1

I need to access kucoin Open-high-low-close (OHLC) data from Kucoin API.

Looking in https://docs.kucoin.com/#get-trade-histories, I deduced that to access OHLC data (for instance BTC versus USDT, with hourly timestamp), the address should be something like this :

https://api.kucoin.com/api/v1/market/candles?symbol=BTC-USDT&type=1hour

Doing that, I get empty list for the data {'code': '200000', 'data': []} (according to kucoin API doc, code 200000 correspond to a good request)

What I am doing wrong ?

ps : same method worked very well on kraken api (e.g. https://api.kraken.com/0/public/OHLC?pair=xbtusd )

ps2: this question was originally asked on https://stackoverflow.com/questions/56572249/how-to-access-kucoin-ohlc-data-from-api but with no response for the moment. Perhaps this bitcoin stackexchange is better adapted.

Thank you very much in advance for your help !

1 Answer 1

0

To obtain the information you seek:
I use the a variable called kline and a json formatted request.
It looks like this:

kline = requests.get(url + '/api/v1/market/candles?type=1min&symbol=
                     '+Cry+'&startAt=1566703297&endAt=1566789757')
# Then I convert it to json
kline = kline.json()
# turn that into a dataframe where I pull the data dictionary
kline = pd.DataFrame(kline['data'])
# Then I rename the columbs as so
kline = kline.rename({0:"Time",1:"Open",
                2:"Close",3:"High",4:"Low",5:"Amount",6:"Volume"}, axis='columns')
# Set the index as time
kline.set_index('Time', inplace=True)
# To assist I will call the head and and print for you
kline.head()
print(kline)

As you should know, once you have it as a dataframe you can manipulate it as you please.

1
  • Hi, thanks for your post! In the future, please edit your first post to update instead of posting another. I've deleted the obsolete prior answer, given that this seems to be an improved version of the same. Please let me know if I misunderstood that.
    – Murch
    Dec 21, 2022 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.