From b97588f153b430321e193ef01d4a50f2440a0c5b Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 26 Apr 2022 15:32:42 +0800 Subject: [PATCH] autoborrow: fix max total borrow condition --- pkg/strategy/autoborrow/strategy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/autoborrow/strategy.go b/pkg/strategy/autoborrow/strategy.go index 451b7190a..892d9197f 100644 --- a/pkg/strategy/autoborrow/strategy.go +++ b/pkg/strategy/autoborrow/strategy.go @@ -127,14 +127,14 @@ func (s *Strategy) checkAndBorrow(ctx context.Context) { if !marginAsset.MaxTotalBorrow.IsZero() { // check if we over borrow - if toBorrow.Add(b.Borrowed).Compare(marginAsset.MaxTotalBorrow) > 0 { - toBorrow = toBorrow.Sub(toBorrow.Add(b.Borrowed).Sub(marginAsset.MaxTotalBorrow)) + newBorrow := toBorrow.Add(b.Borrowed) + if newBorrow.Compare(marginAsset.MaxTotalBorrow) > 0 { + toBorrow = toBorrow.Sub(newBorrow.Sub(marginAsset.MaxTotalBorrow)) if toBorrow.Sign() < 0 { log.Warnf("margin asset %s is over borrowed, skip", marginAsset.Asset) continue } } - toBorrow = fixedpoint.Min(toBorrow.Add(b.Borrowed), marginAsset.MaxTotalBorrow) } s.Notifiability.Notify(&MarginAction{