mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
autoborrow: improve available balance checking
This commit is contained in:
parent
b7c9ef7983
commit
4cb9ff569a
|
@ -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()),
|
||||
|
|
Loading…
Reference in New Issue
Block a user