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)
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()),