xfunding: always transfer balance out when reducing the futures position

This commit is contained in:
c9s 2023-06-16 17:13:42 +08:00
parent c818f79932
commit 5d0bdd19e3
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -635,6 +635,17 @@ func (s *Strategy) reduceFuturesPosition(ctx context.Context) {
return
}
spotBase := s.SpotPosition.GetBase()
if !s.spotMarket.IsDustQuantity(spotBase, s.SpotPosition.AverageCost) {
if balance, ok := s.futuresSession.Account.Balance(s.futuresMarket.BaseCurrency); ok && balance.Available.Sign() > 0 {
if err := backoff.RetryGeneral(ctx, func() error {
return s.transferOut(ctx, s.binanceSpot, s.spotMarket.BaseCurrency, balance.Available)
}); err != nil {
log.WithError(err).Errorf("spot-to-futures transfer in retry failed")
}
}
}
if futuresBase.Compare(fixedpoint.Zero) < 0 {
orderPrice := ticker.Buy
orderQuantity := futuresBase.Abs()