fix submit order quantity formatting

This commit is contained in:
c9s 2020-10-28 17:17:57 +08:00
parent 2680ad5072
commit 468864302e
2 changed files with 12 additions and 4 deletions

View File

@ -140,9 +140,11 @@ func (e *BasicRiskControlOrderExecutor) SubmitOrders(ctx context.Context, orders
} }
formattedOrders = append(formattedOrders, o) formattedOrders = append(formattedOrders, o)
e.Notify(":memo: Submitting %s %s %s order with quantity %s @ %s", o.Symbol, o.Side, o.Type, o.QuantityString, o.PriceString, o)
} }
// e.Notify(":memo: Submitting %s %s %s order with quantity: %s", order.Symbol, order.Type, order.Side, order.QuantityString, order)
return e.session.Exchange.SubmitOrders(ctx, formattedOrders...) return e.session.Exchange.SubmitOrders(ctx, formattedOrders...)
} }
@ -164,7 +166,7 @@ func formatOrder(order types.SubmitOrder, session *ExchangeSession) (types.Submi
} }
order.QuantityString = market.FormatVolume(order.Quantity) order.QuantityString = market.FormatQuantity(order.Quantity)
return order, nil return order, nil
} }

View File

@ -44,14 +44,20 @@ func (m Market) FormatPriceCurrency(val float64) string {
} }
func (m Market) FormatPrice(val float64) string { func (m Market) FormatPrice(val float64) string {
p := math.Pow10(m.PricePrecision) p := math.Pow10(m.PricePrecision)
val = math.Trunc(val*p) / p val = math.Trunc(val*p) / p
return strconv.FormatFloat(val, 'f', m.PricePrecision, 64) return strconv.FormatFloat(val, 'f', m.PricePrecision, 64)
} }
func (m Market) FormatQuantity(val float64) string {
prec := int(math.Abs(math.Log10(m.MinLot)))
p := math.Pow10(prec)
val = math.Trunc(val*p) / p
return strconv.FormatFloat(val, 'f', prec, 64)
}
func (m Market) FormatVolume(val float64) string { func (m Market) FormatVolume(val float64) string {
p := math.Pow10(m.PricePrecision) p := math.Pow10(m.VolumePrecision)
val = math.Trunc(val*p) / p val = math.Trunc(val*p) / p
return strconv.FormatFloat(val, 'f', m.VolumePrecision, 64) return strconv.FormatFloat(val, 'f', m.VolumePrecision, 64)
} }