move report struct

This commit is contained in:
c9s 2020-10-16 10:21:37 +08:00
parent 63ea81b648
commit 27b582e948
5 changed files with 22 additions and 25 deletions

View File

@ -1,2 +0,0 @@
package accounting

View File

@ -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,

View File

@ -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 {

View File

@ -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{}

View File

@ -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,