Kucoin futures Python API, Kline get data not working

1.2k Views Asked by At

I'm trying to get Klines historical data from a specific time (4th of April of 2022) of the futures Bitcoin market (which has the symbol '.KXBTUSDT'). However when I call the function the API returns an empty array. Furthermore, when I call the get_kline_data function without specifying an end or start time everything works well.

Here is the code :

client = Market(url='https://api-futures.kucoin.com')
kline = client.get_kline_data('.KXBTUSDT', 1, 1648845540000, 1648846800000)
print(kline)

Here is the output :

{'code': '200000', 'data': []}

The fact that the code is equal to 20000 shows that the request was successful, that's why I don't understand how data can be empty.

Would any of you know how to fix this problem?

3

There are 3 best solutions below

0
On BEST ANSWER

Here is a quick way to retrieve the data using CCXT library:

import ccxt

exchange = ccxt.kucoinfutures()
markets = exchange.fetchMarkets()
symbol = 'BTC/USDT:USDT'
kline = exchange.fetchOHLCV(symbol, timeframe = '1m', since = 1648845540000, limit = 1648846800000, params = {})
print(kline)
0
On

I could be wrong, but I think Kucoin Futures limits its data to the last day or two. Your request is correct, but it's not returning any data because it has a lookback longer than what's available. Someone, please correct me if I am wrong.

0
On

The solution above using CCXT is correct, however there are limitations imposed at Kucoin's end for obtaining futures historical Klines. The finer the granularity of data requested, the shorter the obtainable history. For example, requesting daily Klines allows data from Aug 2019 for .KXBTUSDT (at 14 Jan 2024), 4hr Klines from Sept 2022, and 1hr Klines from Sept 2023. Requesting 1m Klines enables one to only obtain data for the prior few days.

While Kucoin only provides a maximum of 200 records per request, creating a loop which obtains required data in chunks of 200 does not overcome the above limitation.

My only workaround for high frequency Klines was to obtain the data from another exchange which does not have this limitation, namely Binance.