xfunding: add SlackAttachment method support on profit stats

This commit is contained in:
c9s 2023-03-26 16:12:22 +08:00
parent 4d59edc3d1
commit 6f961556d7
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -4,7 +4,10 @@ import (
"fmt"
"time"
"github.com/slack-go/slack"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/style"
"github.com/c9s/bbgo/pkg/types"
)
@ -18,6 +21,20 @@ type ProfitStats struct {
LastFundingFeeTime time.Time `json:"lastFundingFeeTime"`
}
func (s *ProfitStats) SlackAttachment() slack.Attachment {
var fields []slack.AttachmentField
var totalProfit = fmt.Sprintf("Total Funding Fee Profit: %s %s", style.PnLSignString(s.TotalFundingFee), s.FundingFeeCurrency)
return slack.Attachment{
Title: totalProfit,
Color: style.PnLColor(s.TotalFundingFee),
// Pretext: "",
// Text: text,
Fields: fields,
Footer: fmt.Sprintf("Last Funding Fee Transation ID: %d Last Funding Fee Time %s", s.LastFundingFeeTxn, s.LastFundingFeeTime.Format(time.RFC822)),
}
}
func (s *ProfitStats) AddFundingFee(fee FundingFee) error {
if s.FundingFeeCurrency == "" {
s.FundingFeeCurrency = fee.Asset