Merge pull request #1588 from c9s/c9s/xalign-add-check-expected-balance

FIX: [xalign] check if the quote balance will be used up and below the expected balance
This commit is contained in:
c9s 2024-03-18 14:44:36 +08:00 committed by GitHub
commit ee21e9ea62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -196,6 +196,14 @@ func (s *Strategy) selectSessionForCurrency(
continue 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] maxAmount, ok := s.MaxAmounts[market.QuoteCurrency]
if ok { if ok {
requiredQuoteAmount = bbgo.AdjustQuantityByMaxAmount(requiredQuoteAmount, price, maxAmount) requiredQuoteAmount = bbgo.AdjustQuantityByMaxAmount(requiredQuoteAmount, price, maxAmount)