From 898204f5fa8f7b1f57761036c8bb1ed703f6e3d8 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 16 Jan 2022 01:15:34 +0800 Subject: [PATCH] bollmaker: adjust quantity to met the min notional condition before we submit --- pkg/strategy/bollmaker/strategy.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/strategy/bollmaker/strategy.go b/pkg/strategy/bollmaker/strategy.go index 2fec2d503..996d90039 100644 --- a/pkg/strategy/bollmaker/strategy.go +++ b/pkg/strategy/bollmaker/strategy.go @@ -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 { // submitOrders = append(submitOrders, buyOrder) } + + buyOrder = s.adjustOrderQuantity(buyOrder) + sellOrder = s.adjustOrderQuantity(sellOrder) + if canBuy { submitOrders = append(submitOrders, buyOrder) } @@ -369,6 +373,18 @@ func (s *Strategy) placeOrders(ctx context.Context, orderExecutor bbgo.OrderExec 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 { if s.MinProfitSpread == 0 { s.MinProfitSpread = fixedpoint.NewFromFloat(0.001)