From 7f1e876be08e51950c06c0456c152f6de47e31a9 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 18 Mar 2024 12:47:48 +0800 Subject: [PATCH] xalign: check if the quote balance will be used up and below the expected balance line --- pkg/strategy/xalign/strategy.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index 00fa4dbf49..9c5429833d 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -196,6 +196,14 @@ func (s *Strategy) selectSessionForCurrency( continue } + if expectedQuoteBalance, ok := s.ExpectedBalances[quoteCurrency]; ok { + rest := quoteBalance.Total().Sub(requiredQuoteAmount) + if rest.Compare(expectedQuoteBalance) < 0 { + log.Warnf("required quote amount %f will use up the expected balance %f, skip", requiredQuoteAmount.Float64(), expectedQuoteBalance.Float64()) + continue + } + } + maxAmount, ok := s.MaxAmounts[market.QuoteCurrency] if ok { requiredQuoteAmount = bbgo.AdjustQuantityByMaxAmount(requiredQuoteAmount, price, maxAmount)