mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
move report struct
This commit is contained in:
parent
63ea81b648
commit
27b582e948
|
@ -1,2 +0,0 @@
|
|||
package accounting
|
||||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/accounting"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
|
@ -16,7 +15,7 @@ type AverageCostCalculator struct {
|
|||
TradingFeeCurrency string
|
||||
}
|
||||
|
||||
func (c *AverageCostCalculator) Calculate(trades []types.Trade, currentPrice float64) *accounting.ProfitAndLossReport {
|
||||
func (c *AverageCostCalculator) Calculate(trades []types.Trade, currentPrice float64) *AverageCostPnlReport {
|
||||
// copy trades, so that we can truncate it.
|
||||
var bidVolume = 0.0
|
||||
var bidAmount = 0.0
|
||||
|
@ -88,7 +87,7 @@ func (c *AverageCostCalculator) Calculate(trades []types.Trade, currentPrice flo
|
|||
unrealizedProfit += (currentPrice-averageCost)*stock - stockFee
|
||||
}
|
||||
|
||||
return &accounting.ProfitAndLossReport{
|
||||
return &AverageCostPnlReport{
|
||||
Symbol: c.Symbol,
|
||||
StartTime: c.StartTime,
|
||||
CurrentPrice: currentPrice,
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package accounting
|
||||
package pnl
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/slack-go/slack"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/slack/slackstyle"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
type ProfitAndLossReport struct {
|
||||
type AverageCostPnlReport struct {
|
||||
CurrentPrice float64
|
||||
StartTime time.Time
|
||||
Symbol string
|
||||
|
@ -27,23 +27,23 @@ type ProfitAndLossReport struct {
|
|||
CurrencyFees map[string]float64
|
||||
}
|
||||
|
||||
func (report ProfitAndLossReport) Print() {
|
||||
logrus.Infof("trades since: %v", report.StartTime)
|
||||
logrus.Infof("average bid cost: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost))
|
||||
logrus.Infof("total bid volume: %f", report.BidVolume)
|
||||
logrus.Infof("total ask volume: %f", report.AskVolume)
|
||||
logrus.Infof("stock: %f", report.Stock)
|
||||
logrus.Infof("fee (USD): %f", report.FeeUSD)
|
||||
logrus.Infof("current price: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice))
|
||||
logrus.Infof("profit: %s", types.USD.FormatMoneyFloat64(report.Profit))
|
||||
logrus.Infof("unrealized profit: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit))
|
||||
logrus.Infof("currency fees:")
|
||||
func (report AverageCostPnlReport) Print() {
|
||||
log.Infof("trades since: %v", report.StartTime)
|
||||
log.Infof("average bid cost: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost))
|
||||
log.Infof("total bid volume: %f", report.BidVolume)
|
||||
log.Infof("total ask volume: %f", report.AskVolume)
|
||||
log.Infof("stock: %f", report.Stock)
|
||||
log.Infof("fee (USD): %f", report.FeeUSD)
|
||||
log.Infof("current price: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice))
|
||||
log.Infof("profit: %s", types.USD.FormatMoneyFloat64(report.Profit))
|
||||
log.Infof("unrealized profit: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit))
|
||||
log.Infof("currency fees:")
|
||||
for currency, fee := range report.CurrencyFees {
|
||||
logrus.Infof(" - %s: %f", currency, fee)
|
||||
log.Infof(" - %s: %f", currency, fee)
|
||||
}
|
||||
}
|
||||
|
||||
func (report ProfitAndLossReport) SlackAttachment() slack.Attachment {
|
||||
func (report AverageCostPnlReport) SlackAttachment() slack.Attachment {
|
||||
var color = slackstyle.Red
|
||||
|
||||
if report.UnrealizedProfit > 0 {
|
|
@ -1,14 +1,14 @@
|
|||
package bbgo
|
||||
|
||||
import (
|
||||
"github.com/c9s/bbgo/pkg/accounting"
|
||||
"github.com/c9s/bbgo/pkg/accounting/pnl"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
type Notifier interface {
|
||||
Notify(format string, args ...interface{})
|
||||
NotifyTrade(trade *types.Trade)
|
||||
NotifyPnL(report *accounting.ProfitAndLossReport)
|
||||
NotifyPnL(report *pnl.AverageCostPnlReport)
|
||||
}
|
||||
|
||||
type NullNotifier struct{}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
"github.com/slack-go/slack"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/accounting"
|
||||
"github.com/c9s/bbgo/pkg/accounting/pnl"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
)
|
||||
|
@ -106,7 +106,7 @@ func (n *Notifier) NotifyTrade(trade *types.Trade) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *Notifier) NotifyPnL(report *accounting.ProfitAndLossReport) {
|
||||
func (n *Notifier) NotifyPnL(report *pnl.AverageCostPnlReport) {
|
||||
attachment := report.SlackAttachment()
|
||||
|
||||
_, _, err := n.client.PostMessageContext(context.Background(), n.PnlChannel,
|
||||
|
|
Loading…
Reference in New Issue
Block a user