bbgo_origin/pkg/strategy/tri/profit.go

61 lines
1.4 KiB
Go
Raw Normal View History

2023-07-05 07:51:16 +00:00
package tri
import (
"github.com/slack-go/slack"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/style"
)
type Profit struct {
Asset string `json:"asset"`
Profit fixedpoint.Value `json:"profit"`
ProfitInUSD fixedpoint.Value `json:"profitInUSD"`
}
func (p *Profit) PlainText() string {
2023-07-22 10:06:53 +00:00
var title = "Arbitrage Profit "
2023-07-05 07:51:16 +00:00
title += style.PnLEmojiSimple(p.Profit) + " "
title += style.PnLSignString(p.Profit) + " " + p.Asset
if !p.ProfitInUSD.IsZero() {
title += " ~= " + style.PnLSignString(p.ProfitInUSD) + " USD"
}
return title
}
func (p *Profit) SlackAttachment() slack.Attachment {
var color = style.PnLColor(p.Profit)
2023-07-22 10:06:53 +00:00
var title = "Triangular PnL "
2023-07-05 07:51:16 +00:00
title += style.PnLEmojiSimple(p.Profit) + " "
title += style.PnLSignString(p.Profit) + " " + p.Asset
if !p.ProfitInUSD.IsZero() {
title += " ~= " + style.PnLSignString(p.ProfitInUSD) + " USD"
}
var fields []slack.AttachmentField
if !p.Profit.IsZero() {
fields = append(fields, slack.AttachmentField{
Title: "Profit",
Value: style.PnLSignString(p.Profit) + " " + p.Asset,
Short: true,
})
}
if !p.ProfitInUSD.IsZero() {
fields = append(fields, slack.AttachmentField{
Title: "Profit (~= USD)",
Value: style.PnLSignString(p.ProfitInUSD) + " USD",
Short: true,
})
}
return slack.Attachment{
Color: color,
Title: title,
Fields: fields,
// Footer: "",
}
}