Skip to content

cryptoQuotes is an R package for retrieving historical and real-time cryptocurrency market data from multiple exchanges. It offers an easy-to-use interface for accessing price quotes, trading volumes, and market data, making it valuable for analysts, developers, and crypto enthusiasts.

License

Notifications You must be signed in to change notification settings

serkor1/cryptoQuotes

Repository files navigation

{cryptoQuotes}: Open access to cryptocurrency market data cryptocurrency in R

CRAN status CRAN RStudio mirror downloads R-CMD-check codecov Lifecycle: stable GitHub last commit (branch)

ℹ️ About

{cryptoQuotes} is a high-level API client for accessing public market data endpoints on major cryptocurrency exchanges. It supports open, high, low, close and volume (OHLC-V) data and a variety of sentiment indicators; the market data is high quality and can be retrieved in intervals ranging from seconds to months. All the market data is accessed and processed without relying on crawlers, or API keys, ensuring an open, and reliable, access for researchers, traders and students alike. There are currently 8 supported cryptocurrency exchanges,

All supported exchanges.
Binance BitMart Bybit Crypto.com
Huobi (HTX) Kraken KuCoin MEXC

All data is returned as {xts}-objects which enables seamless interaction with with {quantmod} and {TTR}, for developing and evaluating trading strategies or general purpose cryptocurrency market analysis with a historical or temporal perspective.

ℹ️ Overview

{cryptoQuotes} has two main features; retrieving cryptocurrency market data, and charting. The market data consists of OHLC-V data and sentiment indicators; including, but not limited to, cryptocurrency fear and greed index, long-short ratio and open interest. All market data is retrieved using the family of get_*-functions. To get a full overview of the package and functionality please see the documentation via {pkgdown}.

Warning

Given the nature of crypotcurrency data and general legislative restrictions, some exchanges may not work in your geolocation.

Below is a quick overview of the package and basic usage examples on retrieving and charting Bitcoin (BTC) OHLC-V and long-short ratio in 30 minute intervals.

ℹ️ Cryptocurrency market data

OHLC-V

All supported exchanges and markets are listed in the table below, alongside the available range of intervals available from the respective exchanges,

Supported exchanges by spot and futures markets with available intervals.
Exchange Spot Futures Available Intervals Smallest Interval Biggest Interval
Binance 16 1 second(s) 1 month(s)
BitMart 13 1 minute(s) 1 week(s)
Bybit 13 1 minute(s) 1 month(s)
Crypto.com 12 1 minute(s) 1 month(s)
Huobi (HTX) 9 1 minute(s) 1 month(s)
Kraken 10 1 minute(s) 2 week(s)
KuCoin 13 1 minute(s) 1 week(s)
MEXC 10 1 minute(s) 1 month(s)
Example: Bitcoin OHLC-V

Get USDT denominated Bitcoin (BTC) on the spot market from Binance in 30m-intervals using the get_quote()-function,

## BTC OHLC prices
## from Binance spot market
## in 30 minute intervals
BTC <- cryptoQuotes::get_quote(
  ticker   = 'BTCUSDT',
  source   = 'binance',
  futures  = FALSE,
  interval = '30m',
  from     = Sys.Date() - 2
)
Bitcoin (BTC) OHLC-V data
index open high low close volume
2024-11-02 13:00:00 69608 69680 69520 69529.32 111.56801
2024-11-02 13:30:00 69529.32 69626 69390.09 69459.05 373.18153
2024-11-02 14:00:00 69459.05 69711.59 69393.22 69679.99 524.68007
2024-11-02 14:30:00 69679.99 69680 69358.87 69365.99 391.34893
2024-11-02 15:00:00 69366 69437.85 69099.96 69151.19 731.13778
2024-11-02 15:30:00 69151.2 69253.16 69112 69112.01 260.8502

Sentiment indicators

The sentiment indicators available in {cryptoQuotes} can be divided in two; derived indicators and market indicators. The former is calculated based on, for example, the price actions such as the Moving Average Convergence Divergence (MACD) indicator. The latter are public indicators such as the long-short ratio or fear and greed index; these are retrieved using the family of get_*-functions, while the derived indicators can be created using, for example, {TTR}.

In this overview we are focusing on market indicators made public by the cryptocurrency exchanges. For a full overview of sentiment indicators please refer to the documentation via {pkgdown}. All supported market indicators by exchange are listed in the table below,

Available sentiment indicators by exchange
Endpoint Binance BitMart Bybit Crypto.com Huobi (HTX) Kraken KuCoin MEXC
Long-Short Ratio
Open Interest
Fundingrate
Example: Bitcoin Long-Short Ratio

Get the long-short ratio on Bitcoin (BTC) using the get_lsratio()-function,

## BTC OHLC prices
## from Binance spot market
## in 30 minute intervals
BTC_LS <- cryptoQuotes::get_lsratio(
  ticker   = 'BTCUSDT',
  source   = 'binance',
  interval = '30m',
  from     = Sys.Date() - 2
)
Long-Short Ratio on Bitcoin (BTC)
index long short ls_ratio
2024-11-02 13:00:00 0.523 0.477 1.098
2024-11-02 13:30:00 0.52 0.48 1.085
2024-11-02 14:00:00 0.517 0.483 1.07
2024-11-02 14:30:00 0.519 0.481 1.077
2024-11-02 15:00:00 0.519 0.481 1.08
2024-11-02 15:30:00 0.52 0.48 1.085

ℹ️ Charting

Charting in {cryptoQuotes} is built on {plotly} for interactivity. It supports light and dark themes, and accounts for color-deficiency via the options-argument in the chart()-function.

Charting with indicators

The OHLC-V data and the sentiment indicator can be charted using the chart()-function,

cryptocurrency charts in R

Source
## Chart BTC
## using klines, SMA
## Bollinger Bands and
## long-short ratio
cryptoQuotes::chart(
  ticker = BTC,
  main   = cryptoQuotes::kline(),
  sub    = list(
    cryptoQuotes::lsr(ratio = BTC_LS),
    cryptoQuotes::volume()
  ),
  indicator = list(
    cryptoQuotes::sma(n = 7),
    cryptoQuotes::sma(n = 14),
    cryptoQuotes::sma(n = 21),
    cryptoQuotes::bollinger_bands()
  ),
  options = list(
    static     = TRUE
  )
)

ℹ️ Installation

🛡️ Stable version

## install from CRAN
install.packages(
  pkgs = 'cryptoQuotes',
  dependencies = TRUE
)

🛠️ Development version

## install from github
devtools::install_github(
  repo = 'https://github.com/serkor1/cryptoQuotes/',
  ref  = 'development'
)

ℹ️ Code of Conduct

Please note that the {cryptoQuotes} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

About

cryptoQuotes is an R package for retrieving historical and real-time cryptocurrency market data from multiple exchanges. It offers an easy-to-use interface for accessing price quotes, trading volumes, and market data, making it valuable for analysts, developers, and crypto enthusiasts.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages