Skip to content

Commit

Permalink
binance: implement TransferFuturesAccountAsset api
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Mar 22, 2023
1 parent 6797069 commit 487fbf8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/exchange/binance/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,33 +367,38 @@ func (e *Exchange) QueryMarginBorrowHistory(ctx context.Context, asset string) e
return nil
}

func (e *Exchange) TransferFuturesAsset(ctx context.Context, asset string, amount fixedpoint.Value, io int) error {
func (e *Exchange) TransferFuturesAccountAsset(ctx context.Context, asset string, amount fixedpoint.Value, io types.TransferDirection) error {
req := e.client2.NewFuturesTransferRequest()
req.Asset(asset)
req.Amount(amount.String())

if io > 0 { // int
if io == types.TransferIn {
req.TransferType(binanceapi.FuturesTransferSpotToUsdtFutures)
} else if io < 0 { // out
} else if io == types.TransferOut {
req.TransferType(binanceapi.FuturesTransferUsdtFuturesToSpot)
} else {
return fmt.Errorf("unexpected transfer direction: %d given", io)
}

resp, err := req.Do(ctx)
log.Debugf("futures transfer %s %s, transaction = %+v", amount.String(), asset, resp)
log.Infof("futures transfer %s %s, transaction = %+v, err = %+v", amount.String(), asset, resp, err)
return err
}

// transferCrossMarginAccountAsset transfer asset to the cross margin account or to the main account
func (e *Exchange) transferCrossMarginAccountAsset(ctx context.Context, asset string, amount fixedpoint.Value, io int) error {
func (e *Exchange) transferCrossMarginAccountAsset(ctx context.Context, asset string, amount fixedpoint.Value, io types.TransferDirection) error {
req := e.client.NewMarginTransferService()
req.Asset(asset)
req.Amount(amount.String())

if io > 0 { // in
if io == types.TransferIn {
req.Type(binance.MarginTransferTypeToMargin)
} else if io < 0 { // out
} else if io == types.TransferOut {
req.Type(binance.MarginTransferTypeToMain)
} else {
return fmt.Errorf("unexpected transfer direction: %d given", io)
}

resp, err := req.Do(ctx)
if err != nil {
return err
Expand Down

0 comments on commit 487fbf8

Please sign in to comment.