Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a binance futures order with ccxt in python?

Tags:

python

ccxt

How can I place a market order in ccxt for binance futures? Trading on binance futures with ccxt is already implemented

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

In this post they suggest to use this line of code:

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

The above line was written in JavaScript. How would the equivalent line in python look like? Like this I get an error:

binance_futures = ccxt.binance({ 'option': { defaultMarket: 'futures' } })
NameError: name 'defaultMarket' is not defined
like image 432
eetiaro Avatar asked Dec 13 '19 16:12

eetiaro


2 Answers

The correct answer is that 'defaultType' (instead of defaultMarket) must be in quotes, but also the value must be '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...
like image 198
Igor Kroitor Avatar answered Oct 05 '22 02:10

Igor Kroitor


Put quotes around defaultMarket:

binance_futures = ccxt.binance({ 'option': { 'defaultMarket': 'futures' } })
like image 36
zok Avatar answered Oct 05 '22 01:10

zok