diff --git a/bbgo/types/market.go b/bbgo/types/market.go index 3ec8832fa..2a5abce3d 100644 --- a/bbgo/types/market.go +++ b/bbgo/types/market.go @@ -1,10 +1,15 @@ package types import ( + "github.com/leekchan/accounting" "math" "strconv" ) +var USD = accounting.Accounting{Symbol: "$ ", Precision: 2} +var BTC = accounting.Accounting{Symbol: "BTC ", Precision: 2} +var BNB = accounting.Accounting{Symbol: "BNB ", Precision: 4} + type Market struct { Symbol string PricePrecision int @@ -17,6 +22,20 @@ type Market struct { } func (m Market) FormatPrice(val float64) string { + + switch m.QuoteCurrency { + + case "USD", "USDT": + return USD.FormatMoneyFloat64(val) + + case "BTC": + return BTC.FormatMoneyFloat64(val) + + case "BNB": + return BNB.FormatMoneyFloat64(val) + + } + return strconv.FormatFloat(val, 'f', m.PricePrecision, 64) } diff --git a/bbgo/types/trade.go b/bbgo/types/trade.go index e064aea8d..5034aa3a8 100644 --- a/bbgo/types/trade.go +++ b/bbgo/types/trade.go @@ -53,7 +53,7 @@ func (trade Trade) SlackAttachment() slack.Attachment { {Title: "Side", Value: trade.Side, Short: true}, {Title: "Price", Value: market.FormatPrice(trade.Price), Short: true}, {Title: "Volume", Value: market.FormatVolume(trade.Quantity), Short: true}, - {Title: "Amount", Value: market.FormatPrice(trade.QuoteQuantity), Short: true}, + {Title: "Amount", Value: market.FormatPrice(trade.QuoteQuantity)}, {Title: "FeeCurrency", Value: trade.FeeCurrency, Short: true}, {Title: "Fee", Value: util.FormatFloat(trade.Fee, 4), Short: true}, },