pythonfuturebitcoinkucoin

Kucoin futures Python API, Kline get data not working


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?


Solution

  • 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)