bbgo_origin/pkg/accounting/pnl/report.go

74 lines
2.4 KiB
Go
Raw Normal View History

2020-10-16 02:21:37 +00:00
package pnl
2020-09-19 01:05:06 +00:00
import (
"strconv"
"time"
2020-10-16 02:21:37 +00:00
log "github.com/sirupsen/logrus"
2020-09-19 01:05:06 +00:00
"github.com/slack-go/slack"
2020-10-11 08:46:15 +00:00
"github.com/c9s/bbgo/pkg/slack/slackstyle"
"github.com/c9s/bbgo/pkg/types"
2020-09-19 01:05:06 +00:00
)
2020-10-16 02:21:37 +00:00
type AverageCostPnlReport struct {
2020-09-19 01:05:06 +00:00
CurrentPrice float64
StartTime time.Time
Symbol string
2020-11-17 07:48:18 +00:00
Market types.Market
2020-09-19 01:05:06 +00:00
NumTrades int
Profit float64
UnrealizedProfit float64
AverageBidCost float64
2020-11-10 06:18:27 +00:00
BuyVolume float64
SellVolume float64
FeeInUSD float64
2020-09-19 01:05:06 +00:00
Stock float64
CurrencyFees map[string]float64
}
2020-10-16 02:21:37 +00:00
func (report AverageCostPnlReport) Print() {
2020-11-10 06:18:27 +00:00
log.Infof("TRADES SINCE: %v", report.StartTime)
log.Infof("NUMBER OF TRADES: %d", report.NumTrades)
log.Infof("AVERAGE COST: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost))
log.Infof("TOTAL BUY VOLUME: %f", report.BuyVolume)
log.Infof("TOTAL SELL VOLUME: %f", report.SellVolume)
log.Infof("STOCK: %f", report.Stock)
log.Infof("FEE (USD): %f", report.FeeInUSD)
log.Infof("CURRENT PRICE: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice))
log.Infof("CURRENCY FEES:")
2020-09-19 01:05:06 +00:00
for currency, fee := range report.CurrencyFees {
2020-10-16 02:21:37 +00:00
log.Infof(" - %s: %f", currency, fee)
2020-09-19 01:05:06 +00:00
}
2020-11-10 06:18:27 +00:00
log.Infof("PROFIT: %s", types.USD.FormatMoneyFloat64(report.Profit))
log.Infof("UNREALIZED PROFIT: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit))
2020-09-19 01:05:06 +00:00
}
2020-10-16 02:21:37 +00:00
func (report AverageCostPnlReport) SlackAttachment() slack.Attachment {
2020-10-09 07:59:33 +00:00
var color = slackstyle.Red
2020-09-19 01:05:06 +00:00
if report.UnrealizedProfit > 0 {
color = slackstyle.Green
}
return slack.Attachment{
Title: report.Symbol + " Profit and Loss report",
Text: "Profit " + types.USD.FormatMoney(report.Profit),
Color: color,
// Pretext: "",
// Text: "",
Fields: []slack.AttachmentField{
{Title: "Profit", Value: types.USD.FormatMoney(report.Profit)},
{Title: "Unrealized Profit", Value: types.USD.FormatMoney(report.UnrealizedProfit)},
2020-11-17 07:48:18 +00:00
{Title: "Current Price", Value: report.Market.FormatPrice(report.CurrentPrice), Short: true},
{Title: "Average Cost", Value: report.Market.FormatPrice(report.AverageBidCost), Short: true},
2020-11-10 06:18:27 +00:00
{Title: "Fee (USD)", Value: types.USD.FormatMoney(report.FeeInUSD), Short: true},
2020-09-19 01:05:06 +00:00
{Title: "Stock", Value: strconv.FormatFloat(report.Stock, 'f', 8, 64), Short: true},
{Title: "Number of Trades", Value: strconv.Itoa(report.NumTrades), Short: true},
},
Footer: report.StartTime.Format(time.RFC822),
FooterIcon: "",
}
}