pythonrcryptocurrencycryptoapi

How to get Bybit or Kucoin exchanges crypto history prices with R


I'am successfuly using the package binancer to get the crypto historical prices from the Binance exchange. https://github.com/daroczig/binancer

Here is R code to get crypto prices from Binance (Binancer Package)

library(binancer)

klines <- binance_klines(crypto_pair_of_interest, interval = freq_table, start_time = start_data+days(0), end_time = end_data+days(1), limit = 2)

I'd like to compare prices from other markets such as Kucoin or Bybit to perform statistical analyses.

However, I find no R package for those exchanges. I only find python packages or tutorials https://dev.to/kylefoo/bybits-pybit-how-to-subscribe-to-kline-websocket-stream-5c2f ; https://github.com/gudlc/kucoin-klines

Here is Python code to get crypto prices from Kucoin

kline = requests.get(url + '/api/v1/market/candles?type=1min&symbol=BTC-USDT&startAt=1566703297&endAt=1566789757')
kline = kline.json()
kline = pd.DataFrame(kline['data'])
kline = kline.rename({0:"Time",1:"Open",
                2:"Close",3:"High",4:"Low",5:"Amount",6:"Volume"}, axis='columns')
kline.set_index('Time', inplace=True)
kline.head()

I also tried to search within the Binancer R package documentation a way to transfer the commands from Binance to Kucoin but I keep failing.

If anyone as a clue to do it, please let me know (link, part of code, ideas...)

Thank you


Solution

  • You can get the latest prices from kucoin using the cryptoQuotes-library. Here is an example on ATOM with a 15m interval,

    ## ATOM
    cryptoQuotes::getQuote(
        ticker  = 'ATOM-USDT',
        source = 'kucoin',
        interval = '15m',
        futures = FALSE
      )
    

    This gives you an xts-object with OHLC-prices,

                           Open   Close    High     Low    Volume
    2023-12-11 11:45:00 10.0103 10.0468 10.0472  9.9800  6129.022
    2023-12-11 12:00:00 10.0471 10.0723 10.0896 10.0408 11354.375
    2023-12-11 12:15:00 10.0788 10.0566 10.1116 10.0472  5876.863
    2023-12-11 12:30:00 10.0533  9.9995 10.0750  9.9928  8153.006
    2023-12-11 12:45:00  9.9959  9.9595 10.0027  9.9500  2524.759
    

    You can read more about the library from here: https://serkor1.github.io/cryptoQuotes/

    The source code can be found here: https://github.com/serkor1/cryptoQuotes

    Note: I am the maintainer of the repository.