improve floating number formatting

This commit is contained in:
c9s 2021-05-23 01:19:26 +08:00
parent 117b26840e
commit fbe850b364

View File

@ -73,12 +73,12 @@ type Trade struct {
} }
func (trade Trade) String() string { func (trade Trade) String() string {
return fmt.Sprintf("TRADE %s %s %4s %s @ %s orderID %d %s amount %f", return fmt.Sprintf("TRADE %s %s %4s %f @ %f orderID %d %s amount %f",
trade.Exchange.String(), trade.Exchange.String(),
trade.Symbol, trade.Symbol,
trade.Side, trade.Side,
util.FormatFloat(trade.Quantity, 4), trade.Quantity,
util.FormatFloat(trade.Price, 3), trade.Price,
trade.OrderID, trade.OrderID,
trade.Time.Time().Format(time.StampMilli), trade.Time.Time().Format(time.StampMilli),
trade.QuoteQuantity) trade.QuoteQuantity)
@ -86,13 +86,13 @@ func (trade Trade) String() string {
// PlainText is used for telegram-styled messages // PlainText is used for telegram-styled messages
func (trade Trade) PlainText() string { func (trade Trade) PlainText() string {
return fmt.Sprintf("Trade %s %s %s %s @ %s, amount %s", return fmt.Sprintf("Trade %s %s %s %f @ %f, amount %f",
trade.Exchange.String(), trade.Exchange.String(),
trade.Symbol, trade.Symbol,
trade.Side, trade.Side,
util.FormatFloat(trade.Quantity, 4), trade.Quantity,
util.FormatFloat(trade.Price, 3), trade.Price,
util.FormatFloat(trade.QuoteQuantity, 2)) trade.QuoteQuantity)
} }
var slackTradeTextTemplate = ":handshake: {{ .Symbol }} {{ .Side }} Trade Execution @ {{ .Price }}" var slackTradeTextTemplate = ":handshake: {{ .Symbol }} {{ .Side }} Trade Execution @ {{ .Price }}"