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

4.8k Views Asked by At

The following code work binance futures using ccxt. What is the correct code/configuration for kucoin futures?

import ccxt
import pandas as pd

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

securities = pd.DataFrame(binance.load_markets()).transpose()
print(securities)
=== OUTPUT ===
               percentage feeSide tierBased   taker   maker  ... inverse         expiry            expiryDatetime active contractSize
BTC/USD              True     get     False  0.0005  0.0001  ...    True           None                      None   True          100
BTCUSD_210924        True     get     False  0.0005  0.0001  ...    True  1632470400000  2021-09-24T08:00:00.000Z   True          100
...
1

There are 1 best solutions below

0
On

kucoinfutures requires you to create an apiKey and secret on futures.kucoin.com that is separate from your apiKey and secret for kucoin that you may have created on kucoin.com. For this reason, kucoinfutures is a separate class from kucoin


The equivalent code for kucoinfutures to the code in your question is

import ccxt
import pandas as pd
import sys
from pprint import pprint
# import logging
# logging.basicConfig(level=logging.DEBUG)

print('python', sys.version)
print('CCXT Version:', ccxt.__version__)

exchange = ccxt.kucoinfutures({
    'adjustForTimeDifference': True,
    "apiKey": '...',
    "secret": '...',
    'password': 'This is you 6-7 digit trading password',
})
# exchange.verbose = True

securities = pd.DataFrame(exchange.load_markets()).transpose()
pprint(securities)

output

python 3.10.1 (main, Dec  6 2021, 22:25:40) [Clang 13.0.0 (clang-1300.0.29.3)]
CCXT Version: 1.67.1
                   percentage  ...                                               info
BTC/USDT:USDT            True  ...  {'symbol': 'XBTUSDTM', 'rootSymbol': 'USDT', '...
BTC/USD:BTC              True  ...  {'symbol': 'XBTUSDM', 'rootSymbol': 'XBT', 'ty...
ETH/USDT:USDT            True  ...  {'symbol': 'ETHUSDTM', 'rootSymbol': 'USDT', '...
BCH/USDT:USDT            True  ...  {'symbol': 'BCHUSDTM', 'rootSymbol': 'USDT', '...
BSV/USDT:USDT            True  ...  {'symbol': 'BSVUSDTM', 'rootSymbol': 'USDT', '...
...                       ...  ...                                                ...
OMG/USDT:USDT            True  ...  {'symbol': 'OMGUSDTM', 'rootSymbol': 'USDT', '...
LINA/USDT:USDT           True  ...  {'symbol': 'LINAUSDTM', 'rootSymbol': 'USDT', ...
IMX/USDT:USDT            True  ...  {'symbol': 'IMXUSDTM', 'rootSymbol': 'USDT', '...
NFT/USDT:USDT            True  ...  {'symbol': 'NFTUSDTM', 'rootSymbol': 'USDT', '...
BTC/USD:BTC-220325       True  ...  {'symbol': 'XBTMH22', 'rootSymbol': 'XBT', 'ty...

[90 rows x 29 columns]

if you want to create an order on kucoinfutures you can do

order_response = exchange.createOrder('ADA/USDT:USDT', 'limit', 'buy', 1, 1, {'leverage': 10})
pprint(order_response)

output

{'amount': None,
 'average': None,
 'clientOrderId': None,
 'cost': None,
 'datetime': None,
 'fee': None,
 'filled': None,
 'id': '39292jdf8392039kldlsjas393020',
 'info': {'code': '200000', 'data': {'orderId': '39292jdf8392039kldlsjas393020'}},
 'lastTradeTimestamp': None,
 'postOnly': None,
 'price': None,
 'remaining': None,
 'side': None,
 'status': None,
 'stopPrice': None,
 'symbol': None,
 'timeInForce': None,
 'timestamp': None,
 'trades': None,
 'type': None}