mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
types: improve order slack attachment
This commit is contained in:
parent
48cbb7fff6
commit
2c94ec427b
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/slack-go/slack"
|
||||
|
@ -244,27 +245,41 @@ func (o Order) PlainText() string {
|
|||
o.Status)
|
||||
}
|
||||
|
||||
func (o Order) SlackAttachment() slack.Attachment {
|
||||
func (o *Order) SlackAttachment() slack.Attachment {
|
||||
var fields = []slack.AttachmentField{
|
||||
{Title: "Exchange", Value: o.Exchange.String(), Short: true},
|
||||
{Title: "Symbol", Value: o.Symbol, Short: true},
|
||||
{Title: "Side", Value: string(o.Side), Short: true},
|
||||
{Title: "Quantity", Value: o.QuantityString, Short: true},
|
||||
{Title: "Executed Quantity", Value: util.FormatFloat(o.ExecutedQuantity, 4), Short: true},
|
||||
{Title: "Quantity", Value: trimTrailingZeroFloat(o.Quantity), Short: true},
|
||||
{Title: "Executed Quantity", Value: trimTrailingZeroFloat(o.ExecutedQuantity), Short: true},
|
||||
}
|
||||
|
||||
if len(o.PriceString) > 0 {
|
||||
fields = append(fields, slack.AttachmentField{Title: "Price", Value: o.PriceString, Short: true})
|
||||
} else {
|
||||
fields = append(fields, slack.AttachmentField{Title: "Price", Value: trimTrailingZeroFloat(o.Price), Short: true})
|
||||
}
|
||||
|
||||
fields = append(fields, slack.AttachmentField{
|
||||
Title: "Order ID", Value: strconv.FormatUint(o.OrderID, 10), Short: true,
|
||||
Title: "ID",
|
||||
Value: strconv.FormatUint(o.OrderID, 10),
|
||||
Short: true,
|
||||
})
|
||||
|
||||
fields = append(fields, slack.AttachmentField{
|
||||
Title: "Status",
|
||||
Value: string(o.Status),
|
||||
Short: true,
|
||||
})
|
||||
|
||||
footerIcon := exchangeFooterIcon(o.Exchange)
|
||||
|
||||
return slack.Attachment{
|
||||
Color: SideToColorName(o.Side),
|
||||
Title: string(o.Type) + " Order " + string(o.Side),
|
||||
// Text: "",
|
||||
Fields: fields,
|
||||
FooterIcon: footerIcon,
|
||||
Footer: strings.ToLower(o.Exchange.String()) + util.Render(" creation time {{ . }}", o.CreationTime.Time().Format(time.StampMilli)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,18 +146,11 @@ func (trade Trade) PlainText() string {
|
|||
|
||||
var slackTradeTextTemplate = ":handshake: Trade {{ .Symbol }} {{ .Side }} {{ .Quantity }} @ {{ .Price }}"
|
||||
|
||||
func (trade Trade) SlackAttachment() slack.Attachment {
|
||||
var color = "#DC143C"
|
||||
|
||||
if trade.IsBuyer {
|
||||
color = "#228B22"
|
||||
}
|
||||
|
||||
liquidity := trade.Liquidity()
|
||||
text := util.Render(slackTradeTextTemplate, trade)
|
||||
|
||||
func exchangeFooterIcon(exName ExchangeName) string {
|
||||
footerIcon := ""
|
||||
switch trade.Exchange {
|
||||
|
||||
switch exName {
|
||||
case ExchangeBinance:
|
||||
footerIcon = "https://bin.bnbstatic.com/static/images/common/favicon.ico"
|
||||
case ExchangeMax:
|
||||
|
@ -170,6 +163,20 @@ func (trade Trade) SlackAttachment() slack.Attachment {
|
|||
footerIcon = "https://assets.staticimg.com/cms/media/7AV75b9jzr9S8H3eNuOuoqj8PwdUjaDQGKGczGqTS.png"
|
||||
}
|
||||
|
||||
return footerIcon
|
||||
}
|
||||
|
||||
func (trade Trade) SlackAttachment() slack.Attachment {
|
||||
var color = "#DC143C"
|
||||
|
||||
if trade.IsBuyer {
|
||||
color = "#228B22"
|
||||
}
|
||||
|
||||
liquidity := trade.Liquidity()
|
||||
text := util.Render(slackTradeTextTemplate, trade)
|
||||
footerIcon := exchangeFooterIcon(trade.Exchange)
|
||||
|
||||
return slack.Attachment{
|
||||
Text: text,
|
||||
// Title: ...
|
||||
|
|
Loading…
Reference in New Issue
Block a user