autoborrow: fix repay mech

This commit is contained in:
c9s 2022-07-11 16:20:45 +08:00
parent af488dc87a
commit 98aaa6ce43
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -280,7 +280,8 @@ func (s *Strategy) handleBinanceBalanceUpdateEvent(event *binance.BalanceUpdateE
return
}
if s.ExchangeSession.GetAccount().MarginLevel.Compare(s.MinMarginLevel) > 0 {
account := s.ExchangeSession.GetAccount()
if account.MarginLevel.Compare(s.MinMarginLevel) > 0 {
return
}
@ -291,7 +292,6 @@ func (s *Strategy) handleBinanceBalanceUpdateEvent(event *binance.BalanceUpdateE
return
}
account := s.ExchangeSession.GetAccount()
minMarginLevel := s.MinMarginLevel
curMarginLevel := account.MarginLevel
@ -300,7 +300,7 @@ func (s *Strategy) handleBinanceBalanceUpdateEvent(event *binance.BalanceUpdateE
return
}
toRepay := b.Available
toRepay := b.Borrowed
bbgo.Notify(&MarginAction{
Exchange: s.ExchangeSession.ExchangeName,
Action: "Repay",
@ -309,6 +309,7 @@ func (s *Strategy) handleBinanceBalanceUpdateEvent(event *binance.BalanceUpdateE
MarginLevel: curMarginLevel,
MinMarginLevel: minMarginLevel,
})
if err := s.marginBorrowRepay.RepayMarginAsset(context.Background(), event.Asset, toRepay); err != nil {
log.WithError(err).Errorf("margin repay error")
}