[英]Transfer USDT between spot and futures in Binance using ccxt python
exchange = ccxt.binance({
--
"apiKey": 'xxx',
"secret": 'xxx',
'options': {
'adjustForTimeDifference': True
},
'enableRateLimit': True
})
exchange_f = ccxt.binance({
"apiKey": 'yyy',
"secret": 'yyy',
'options': {
'defaultType': 'future',
'adjustForTimeDifference': True
},
'enableRateLimit': True
})
exchange.load_markets()
exchange_f.load_markets()
#some calculations here
if np.sum(sell_long_1) > 0:
exchange.create_market_sell_order("ETH/USDT", np.sum(sell_long_1))
elif np.sum(sell_short_1) < 0:
exchange_f.create_market_buy_order("ETH/USDT", -np.sum(sell_short_1))
account_balance_f = exchange_f.fetch_balance()['free']['USDT']
exchange.sapi_post_futures_transfer({
'asset': 'USDT',
'amount': account_balance_f,
'type': 2
})
您好,我正在使用 Python 进行算法交易。让我试着解释一下我的问题:
我的问题是:
非常感谢您提前抽出时间。
这个问题有什么有效的解决办法吗? 你有什么建议?
如果您使用隔离保证金模式,当您的 position 的价值上升/下降时,您的余额不会改变。 在隔离模式下,你的抵押品被放入一个子账户,但在交叉模式下,它全部取自同一个池,这就是为什么你的余额会随着你的头寸大小而增加或减少 go
您可以使用exchange.setMarginMode( symbol, 'isolated');
对于每个市场。
如果代码中有错误,它将停止运行。 我如何更新转账部分的代码,如果由于转账余额不足而出现错误,请再次尝试将未来钱包余额的99%(account_balance_f * 99%)转入现货钱包。
你知道 Python 中的错误处理/异常吗?
我还建议使用统一的传输方法,而不是sapi_post_futures_transfer
, 这是一个例子
# -*- coding: utf-8 -*-
import os
import sys
from pprint import pprint
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')
import ccxt # noqa: E402
def main():
# apiKey must have universal transfer permissions
binance = ccxt.binance({
"apiKey": "...",
"secret": "...",
})
binance.load_markets()
pprint(binance.transfer('USDT', 0.1, 'spot', 'future'))
transfers = binance.fetchTransfers()
pprint('got ' + str(len(transfers)) + ' transfers')
pprint(binance.transfer('USDT', 0.1, 'spot', 'margin'))
# binance requires from and to in the params
pprint(binance.fetchTransfers(None, None, None, {'from': 'spot', 'to': 'margin'}))
# alternatively the same effect as above
pprint(binance.fetchTransfers(None, None, None, {'type': 'MAIN_MARGIN'})) # defaults to MAIN_UMFUTURE
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.