binance: implement TransferFuturesAccountAsset api

This commit is contained in:
c9s 2023-03-23 02:42:26 +08:00
parent 6797069a40
commit 487fbf8681
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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