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做algotrading。让我解释一下我的问题:
我的问题是:
非常感谢您提前给我时间。
发布于 2022-04-26 11:16:32
这个问题有什么有效的解决办法吗?你有什么建议?
如果您使用孤立的marginMode,则当您的位置的值上升/下降时,您的余额不会改变。在隔离模式下,抵押品被放入一个子账户,但在交叉模式下,所有这些都来自同一个池,这就是为什么你的余额会随着头寸的大小而上升或下降。
您可以使用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()https://stackoverflow.com/questions/71949435
复制相似问题