如何在 ccxt 中为币安期货下市价单?使用 ccxt 进行币安期货交易已经实施
https://github.com/ccxt/ccxt/pull/5907
Run Code Online (Sandbox Code Playgroud)
在这篇文章中,他们建议使用这行代码:
let binance_futures = new ccxt.binance({ options: { defaultMarket: 'futures' } })
Run Code Online (Sandbox Code Playgroud)
上面这行是用 JavaScript 编写的。python 中的等效行会是什么样子?像这样我得到一个错误:
binance_futures = ccxt.binance({ 'option': { defaultMarket: 'futures' } })
NameError: name 'defaultMarket' is not defined
Run Code Online (Sandbox Code Playgroud)
Igo*_*tor 14
正确答案是'defaultType'(而不是defaultMarket) 必须用引号引起来,而且值也必须是'future'(not 'futures')
import ccxt
print('CCXT version:', ccxt.__version__) # requires CCXT version > 1.20.31
exchange = ccxt.binance({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_API_SECRET',
'enableRateLimit': True,
'options': {
'defaultType': 'future', # ?-------------- quotes and 'future'
},
})
exchange.load_markets()
# exchange.verbose = True # uncomment this line if it doesn't work
# your code here...
Run Code Online (Sandbox Code Playgroud)
小智 6
在周围加上引号defaultMarket:
binance_futures = ccxt.binance({ 'option': { 'defaultMarket': 'futures' } })
Run Code Online (Sandbox Code Playgroud)