mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
improve price formatter
This commit is contained in:
parent
bfe38b8815
commit
cb2ee2d502
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user