improve SubmitOrder formating

This commit is contained in:
c9s 2021-11-04 23:21:01 +08:00
parent 6002a958d2
commit 13577fc2b4
2 changed files with 34 additions and 0 deletions

View File

@ -8,3 +8,12 @@ var BNB = accounting.Accounting{Symbol: "BNB ", Precision: 4}
var FiatCurrencies = []string{"USDC", "USDT", "USD", "TWD", "EUR", "GBP", "BUSD"}
func IsFiatCurrency(currency string) bool {
for _, c := range FiatCurrencies {
if c == currency {
return true
}
}
return false
}

View File

@ -131,10 +131,35 @@ func (o *SubmitOrder) SlackAttachment() slack.Attachment {
{Title: "Quantity", Value: o.QuantityString, Short: true},
}
if len(o.PriceString) > 0 {
fields = append(fields, slack.AttachmentField{Title: "Price", Value: o.PriceString, Short: true})
}
if o.Price > 0 && o.Quantity > 0 && len(o.Market.QuoteCurrency) > 0 {
if IsFiatCurrency(o.Market.QuoteCurrency) {
fields = append(fields, slack.AttachmentField{
Title: "Amount",
Value: USD.FormatMoneyFloat64(o.Price * o.Quantity),
Short: true,
})
} else {
fields = append(fields, slack.AttachmentField{
Title: "Amount",
Value: fmt.Sprintf("%f %s", o.Price * o.Quantity, o.Market.QuoteCurrency),
Short: true,
})
}
}
if len(o.ClientOrderID) > 0 {
fields = append(fields, slack.AttachmentField{Title: "ClientOrderID", Value: o.ClientOrderID, Short: true})
}
if len(o.MarginSideEffect) > 0 {
fields = append(fields, slack.AttachmentField{Title: "MarginSideEffect", Value: string(o.MarginSideEffect), Short: true})
}
return slack.Attachment{
Color: SideToColorName(o.Side),
Title: string(o.Type) + " Order " + string(o.Side),