如何在python中使用ccxt制作币安期货订单?

时间:2019-12-13 16:27:33

标签: python ccxt

我如何在ccxt中为币安期货下订单? 使用ccxt进行币安期货交易已经实现

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

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

let binance_futures = new ccxt.binance({ options: { defaultMarket: 'futures' } })

上面的行是用JavaScript编写的。 python中的等效行看起来如何? 像这样我得到一个错误:

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

4 个答案:

答案 0 :(得分:2)

defaultMarket周围加上引号

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

答案 1 :(得分:1)

实例化币安交换并将其options属性调整为{'defaultType': 'future'}

import ccxt

exchange_id = 'binance'
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
    'apiKey': 'your-public-api-key',
    'secret': 'your-api-secret',
    'timeout': 30000,
    'enableRateLimit': True,
})

exchange.options = {'defaultType': 'future'}
markets = exchange.load_markets()  # Load the futures markets

for market in markets: 
    print(market)                # check for the symbol you want to trade here

# The rest of your code goes here

答案 2 :(得分:1)

如果您正在寻找币安的 COIN-M 期货(例如用于现金期货基础交易),您需要use the delivery option instead

import ccxt
import pandas as pd

binance = ccxt.binance()
binance.options = {'defaultType': 'delivery', 'adjustForTimeDifference': True}

securities = pd.DataFrame(binance.load_markets()).transpose()
securities

预期期货:

Dated Futures


请注意,上述代码段按预期返回了日期期货。但是,下面显示的替代单线解决方案(似乎默认为现货市场):

import ccxt
import pandas as pd

binance = ccxt.binance({'option': {'defaultType': 'delivery', 'adjustForTimeDifference': True}})

securities = pd.DataFrame(binance.load_markets()).transpose()
securities

返回现货市场:

Spot Markets

答案 3 :(得分:0)

正确的答案是'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...