diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index 9faa96a8b1..bb89efa1b9 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -185,6 +185,12 @@ func (s *Strategy) selectSessionForCurrency( log.Infof("%s changeQuantity: %f ticker: %+v market: %+v", symbol, changeQuantity.Float64(), ticker, market) + maxAmount, ok := s.MaxAmounts[market.QuoteCurrency] + if ok { + q = bbgo.AdjustQuantityByMaxAmount(q, ticker.Sell, maxAmount) + log.Infof("adjusted quantity %f %s by max amount %f %s", q.Float64(), market.BaseCurrency, maxAmount.Float64(), market.QuoteCurrency) + } + switch side { case types.SideTypeBuy: @@ -230,12 +236,6 @@ func (s *Strategy) selectSessionForCurrency( } } - maxAmount, ok := s.MaxAmounts[market.QuoteCurrency] - if ok { - requiredQuoteAmount = bbgo.AdjustQuantityByMaxAmount(requiredQuoteAmount, price, maxAmount) - log.Infof("adjusted quantity %f %s by max amount %f %s", requiredQuoteAmount.Float64(), market.BaseCurrency, maxAmount.Float64(), market.QuoteCurrency) - } - if quantity, ok := market.GreaterThanMinimalOrderQuantity(side, price, requiredQuoteAmount); ok { return session, &types.SubmitOrder{ Symbol: symbol, @@ -274,12 +274,6 @@ func (s *Strategy) selectSessionForCurrency( continue } - maxAmount, ok := s.MaxAmounts[market.QuoteCurrency] - if ok { - q = bbgo.AdjustQuantityByMaxAmount(q, price, maxAmount) - log.Infof("adjusted quantity %f %s by max amount %f %s", q.Float64(), market.BaseCurrency, maxAmount.Float64(), market.QuoteCurrency) - } - if quantity, ok := market.GreaterThanMinimalOrderQuantity(side, price, q); ok { return session, &types.SubmitOrder{ Symbol: symbol,