autoborrow: check available

This commit is contained in:
c9s 2023-07-24 18:23:09 +08:00
parent f014213c85
commit a5a9512ef1
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -213,8 +213,16 @@ func (s *Strategy) reBalanceDebt(ctx context.Context) {
log.Infof("checking repayable balance: %+v", b) log.Infof("checking repayable balance: %+v", b)
toRepay := fixedpoint.Min(b.Borrowed, b.Available) toRepay := b.Borrowed
toRepay = toRepay.Sub(marginAsset.Low) if !b.Available.IsZero() {
toRepay = fixedpoint.Min(b.Borrowed, b.Available)
} else {
log.Errorf("available balance is 0: %#v", b)
}
if !marginAsset.Low.IsZero() {
toRepay = toRepay.Sub(marginAsset.Low)
}
if toRepay.Sign() <= 0 { if toRepay.Sign() <= 0 {
log.Warnf("%s repay = %f, available = %f, borrowed = %f, can not repay", log.Warnf("%s repay = %f, available = %f, borrowed = %f, can not repay",