如何在python中使用ccxt生成binance期货订单?

2024-10-02 20:33:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我怎样才能在ccxt下一个binance期货的市场订单? 与ccxt的binance期货交易已经实现

https://github.com/ccxt/ccxt/pull/5907

在这篇文章中,他们建议使用以下代码行:

^{pr2}$

上面这一行是用JavaScript编写的。python中的等价行是什么样子的? 像这样我得到一个错误:

binance_futures = ccxt.binance({ 'option': { defaultMarket: 'futures' } })
NameError: name 'defaultMarket' is not defined

Tags: 代码https订单githubcom市场binancepull
2条回答

在^{周围加上引号

binance_futures = ccxt.binance({ 'option': { 'defaultMarket': 'futures' } })

正确答案是'defaultType'(而不是defaultMarket)必须用引号括起来,但值必须是'future'(不是'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...

相关问题 更多 >