From 4cb9ff569af74fa0415e114b9b1a062ac3523c6d Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 25 Jul 2023 00:16:05 +0800 Subject: [PATCH] autoborrow: improve available balance checking --- pkg/strategy/autoborrow/strategy.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/strategy/autoborrow/strategy.go b/pkg/strategy/autoborrow/strategy.go index a5d98ad2b..5c391748a 100644 --- a/pkg/strategy/autoborrow/strategy.go +++ b/pkg/strategy/autoborrow/strategy.go @@ -216,12 +216,14 @@ func (s *Strategy) reBalanceDebt(ctx context.Context) { log.Infof("checking repayable balance: %+v", b) toRepay := debt - if !b.Available.IsZero() { - toRepay = fixedpoint.Min(toRepay, b.Available) - } else { - log.Errorf("available balance is 0: %#v", b) + + if b.Available.IsZero() { + log.Errorf("%s available balance is 0, can not repay, balance = %+v", marginAsset.Asset, b) + continue } + toRepay = fixedpoint.Min(toRepay, b.Available) + if !marginAsset.Low.IsZero() { toRepay = toRepay.Sub(marginAsset.Low) } @@ -235,6 +237,8 @@ func (s *Strategy) reBalanceDebt(ctx context.Context) { continue } + log.Infof("%s repay %f", marginAsset.Asset, toRepay.Float64()) + bbgo.Notify(&MarginAction{ Exchange: s.ExchangeSession.ExchangeName, Action: fmt.Sprintf("Repay for Debt Ratio %f < Minimal Debt Ratio %f", debtRatio.Float64(), marginAsset.DebtRatio.Float64()),