mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
fix submit order quantity formatting
This commit is contained in:
parent
2680ad5072
commit
468864302e
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user