2022-12-04 07:24:13 +00:00
|
|
|
package grid2
|
|
|
|
|
|
|
|
import (
|
2022-12-06 02:06:58 +00:00
|
|
|
"fmt"
|
2022-12-15 07:33:26 +00:00
|
|
|
"strconv"
|
2022-12-04 07:24:13 +00:00
|
|
|
"time"
|
|
|
|
|
2022-12-15 07:33:26 +00:00
|
|
|
"github.com/slack-go/slack"
|
|
|
|
|
2022-12-04 07:24:13 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
2022-12-15 07:33:26 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/style"
|
2022-12-04 07:24:13 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GridProfit struct {
|
2022-12-04 07:24:59 +00:00
|
|
|
Currency string `json:"currency"`
|
|
|
|
Profit fixedpoint.Value `json:"profit"`
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
Order types.Order `json:"order"`
|
2022-12-04 07:24:13 +00:00
|
|
|
}
|
2022-12-06 02:06:58 +00:00
|
|
|
|
|
|
|
func (p *GridProfit) String() string {
|
|
|
|
return fmt.Sprintf("GRID PROFIT: %f %s @ %s orderID %d", p.Profit.Float64(), p.Currency, p.Time.String(), p.Order.OrderID)
|
|
|
|
}
|
2022-12-15 06:58:31 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2022-12-15 07:33:26 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|