grid2: add SlackAttachment on grid profit

This commit is contained in:
c9s 2022-12-15 15:33:26 +08:00
parent a6a4be9878
commit 7a35a652c3
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -2,9 +2,13 @@ package grid2
import (
"fmt"
"strconv"
"time"
"github.com/slack-go/slack"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/style"
"github.com/c9s/bbgo/pkg/types"
)
@ -22,3 +26,23 @@ func (p *GridProfit) String() string {
func (p *GridProfit) PlainText() string {
return fmt.Sprintf("Grid profit: %f %s @ %s orderID %d", p.Profit.Float64(), p.Currency, p.Time.String(), p.Order.OrderID)
}
func (p *GridProfit) SlackAttachment() slack.Attachment {
title := fmt.Sprintf("Grid Profit %s %s", style.PnLSignString(p.Profit), p.Currency)
return slack.Attachment{
Title: title,
Color: "warning",
Fields: []slack.AttachmentField{
{
Title: "OrderID",
Value: strconv.FormatUint(p.Order.OrderID, 10),
Short: true,
},
{
Title: "Time",
Value: p.Time.String(),
Short: true,
},
},
}
}