autoborrow: improve available balance checking

This commit is contained in:
c9s 2023-07-25 00:16:05 +08:00
parent b7c9ef7983
commit 4cb9ff569a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -216,12 +216,14 @@ func (s *Strategy) reBalanceDebt(ctx context.Context) {
log.Infof("checking repayable balance: %+v", b) log.Infof("checking repayable balance: %+v", b)
toRepay := debt toRepay := debt
if !b.Available.IsZero() {
toRepay = fixedpoint.Min(toRepay, b.Available) if b.Available.IsZero() {
} else { log.Errorf("%s available balance is 0, can not repay, balance = %+v", marginAsset.Asset, b)
log.Errorf("available balance is 0: %#v", b) continue
} }
toRepay = fixedpoint.Min(toRepay, b.Available)
if !marginAsset.Low.IsZero() { if !marginAsset.Low.IsZero() {
toRepay = toRepay.Sub(marginAsset.Low) toRepay = toRepay.Sub(marginAsset.Low)
} }
@ -235,6 +237,8 @@ func (s *Strategy) reBalanceDebt(ctx context.Context) {
continue continue
} }
log.Infof("%s repay %f", marginAsset.Asset, toRepay.Float64())
bbgo.Notify(&MarginAction{ bbgo.Notify(&MarginAction{
Exchange: s.ExchangeSession.ExchangeName, Exchange: s.ExchangeSession.ExchangeName,
Action: fmt.Sprintf("Repay for Debt Ratio %f < Minimal Debt Ratio %f", debtRatio.Float64(), marginAsset.DebtRatio.Float64()), Action: fmt.Sprintf("Repay for Debt Ratio %f < Minimal Debt Ratio %f", debtRatio.Float64(), marginAsset.DebtRatio.Float64()),