bollmaker: adjust quantity to met the min notional condition before we submit

This commit is contained in:
c9s 2022-01-16 01:15:34 +08:00
parent fd4a3bb000
commit 898204f5fa

View File

@ -353,6 +353,10 @@ func (s *Strategy) placeOrders(ctx context.Context, orderExecutor bbgo.OrderExec
if midPrice < s.state.Position.AverageCost.MulFloat64(1.0-s.MinProfitSpread.Float64()) && canBuy { if midPrice < s.state.Position.AverageCost.MulFloat64(1.0-s.MinProfitSpread.Float64()) && canBuy {
// submitOrders = append(submitOrders, buyOrder) // submitOrders = append(submitOrders, buyOrder)
} }
buyOrder = s.adjustOrderQuantity(buyOrder)
sellOrder = s.adjustOrderQuantity(sellOrder)
if canBuy { if canBuy {
submitOrders = append(submitOrders, buyOrder) submitOrders = append(submitOrders, buyOrder)
} }
@ -369,6 +373,18 @@ func (s *Strategy) placeOrders(ctx context.Context, orderExecutor bbgo.OrderExec
s.activeMakerOrders.Add(createdOrders...) s.activeMakerOrders.Add(createdOrders...)
} }
func (s *Strategy) adjustOrderQuantity(submitOrder types.SubmitOrder) types.SubmitOrder {
if submitOrder.Quantity*submitOrder.Price < s.market.MinNotional {
submitOrder.Quantity = bbgo.AdjustFloatQuantityByMinAmount(submitOrder.Quantity, submitOrder.Price, s.market.MinNotional)
}
if submitOrder.Quantity < s.market.MinQuantity {
submitOrder.Quantity = math.Max(submitOrder.Quantity, s.market.MinQuantity)
}
return submitOrder
}
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
if s.MinProfitSpread == 0 { if s.MinProfitSpread == 0 {
s.MinProfitSpread = fixedpoint.NewFromFloat(0.001) s.MinProfitSpread = fixedpoint.NewFromFloat(0.001)