mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
xfunding: fix transferOut, and de-leverage the trade amount from the caller
This commit is contained in:
parent
e82341b2bd
commit
2813ede7ed
|
@ -405,8 +405,11 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
|||
|
||||
switch s.getPositionState() {
|
||||
case PositionClosing:
|
||||
// de-leverage and get the collateral base quantity for transfer
|
||||
quantity := trade.Quantity.Div(s.Leverage)
|
||||
|
||||
if err := backoff.RetryGeneral(ctx, func() error {
|
||||
return s.transferOut(ctx, s.binanceSpot, s.spotMarket.BaseCurrency, trade.Quantity)
|
||||
return s.transferOut(ctx, s.binanceSpot, s.spotMarket.BaseCurrency, quantity)
|
||||
}); err != nil {
|
||||
log.WithError(err).Errorf("spot-to-futures transfer in retry failed")
|
||||
return
|
||||
|
|
|
@ -41,15 +41,12 @@ func (s *Strategy) resetTransfer(ctx context.Context, ex FuturesTransfer, asset
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) transferOut(ctx context.Context, ex FuturesTransfer, asset string, tradeQuantity fixedpoint.Value) error {
|
||||
func (s *Strategy) transferOut(ctx context.Context, ex FuturesTransfer, asset string, quantity fixedpoint.Value) error {
|
||||
// if transfer done
|
||||
if s.State.TotalBaseTransfer.IsZero() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// de-leverage and get the collateral base quantity for transfer
|
||||
quantity := tradeQuantity.Div(s.Leverage)
|
||||
|
||||
balances, err := s.futuresSession.Exchange.QueryAccountBalances(ctx)
|
||||
if err != nil {
|
||||
log.Infof("balance query error, adding to pending base transfer: %s %s + %s", quantity.String(), asset, s.State.PendingBaseTransfer.String())
|
||||
|
@ -64,6 +61,8 @@ func (s *Strategy) transferOut(ctx context.Context, ex FuturesTransfer, asset st
|
|||
return fmt.Errorf("%s balance not found", asset)
|
||||
}
|
||||
|
||||
log.Infof("found futures balance: %+v", b)
|
||||
|
||||
// add the previous pending base transfer and the current trade quantity
|
||||
amount := s.State.PendingBaseTransfer.Add(quantity)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user