From 8e6423514fa969d186ebea78f703a96f84816e96 Mon Sep 17 00:00:00 2001 From: narumi <4680567+narumiruna@users.noreply.github.com> Date: Fri, 8 Mar 2024 17:01:44 +0800 Subject: [PATCH] rebalance: fix cannot lock fund --- pkg/strategy/rebalance/strategy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/rebalance/strategy.go b/pkg/strategy/rebalance/strategy.go index 442e43af2..decbffde1 100644 --- a/pkg/strategy/rebalance/strategy.go +++ b/pkg/strategy/rebalance/strategy.go @@ -253,14 +253,14 @@ func (s *Strategy) generateOrder(ctx context.Context) (*types.SubmitOrder, error return nil, err } - price := s.PriceType.Map(ticker, side) - if side == types.SideTypeBuy { - quantity = fixedpoint.Min(quantity, balances[s.QuoteCurrency].Available.Div(price)) + quantity = fixedpoint.Min(quantity, balances[s.QuoteCurrency].Available.Div(ticker.Sell)) } else if side == types.SideTypeSell { quantity = fixedpoint.Min(quantity, balances[market.BaseCurrency].Available) } + price := s.PriceType.Map(ticker, side) + if s.MaxAmount.Float64() > 0 { quantity = bbgo.AdjustQuantityByMaxAmount(quantity, price, s.MaxAmount) log.Infof("adjusted quantity %s (%s %s @ %s) by max amount %s",