## load dependencies
library(cryptoQuotes)Cryptocurrency market data in R with {cryptoQuotes}
Open access to cryptocurrency market data in R
{cryptoQuotes} provides open access to cryptocurrency market data without the need for API-subscriptions. The market data is provided by the cryptocurrency exchanges and is fetched using curl. The market data is returned as xts-objects.
1 Cryptocurrency market data
There are two types of market data available; open, high, low, close and volume data (OHLC-V), and sentiment data.
For this presentation we will use Bitcoin in hourly intervals, and fetch OHLC-V and Long-Short Ratioes from the last two days.
The intervals can be between 1 second, and 1 month.
1.1 OHLC-V
To get the Bitcoin-price in hourly intervals the get_quote()-function is used,
## get OHLC-V for
## Bitcoin (BTC) on the
## hourly chart
BTC <- get_quote(
ticker = "BTCUSDT",
source = "binance",
futures = FALSE,
interval = "1h",
from = Sys.Date() - 2
) open high low close volume
2024-06-08 08:00:00 69320.00 69414.89 69296.26 69333.45 401.7080
2024-06-08 09:00:00 69333.44 69582.20 69333.44 69582.20 540.1530
2024-06-08 10:00:00 69582.20 69582.20 69381.81 69436.42 364.2401
2024-06-08 11:00:00 69436.43 69495.99 69382.80 69443.24 329.8855
2024-06-08 12:00:00 69443.25 69495.98 69360.01 69453.40 384.7575
2024-06-08 13:00:00 69453.39 69515.00 69420.99 69440.00 312.2917
The BTC-object is class xts/zoo and can be modified using regular xts-syntax.
To get all available tickers use the available_tickers()-function.
The BTC-object can be charted with Japanese candlesticks for quick overview with various indicators such as bollinger bands and simple moving averages,
Source
chart(
ticker = BTC,
main = kline(),
indicator = list(
bollinger_bands(),
sma(n = 7),
sma(n = 14),
sma(n = 27)
),
sub = list(
volume()
),
options = list(
dark = FALSE
)
)1.2 Sentiment Data
There are a variety of sentiment data available in {cryptoQuotes}. This includes, but not limited to, the long-short ratio and the fear and greed index.
1.2.1 Long Short Ratio
The long-short ratio on Bitcoin in hourly intervals can be fetched using the get_lsratio()-function,
## get long-short ratio for
## Bitcoin (BTC) on the
## hourly chart
BTC_LS <- get_lsratio(
ticker = "BTCUSDT",
source = "binance",
interval = "1h",
from = Sys.Date() - 2
) long short ls_ratio
2024-06-08 08:00:00 0.6089 0.3911 1.556891
2024-06-08 09:00:00 0.6091 0.3909 1.558199
2024-06-08 10:00:00 0.6077 0.3923 1.549070
2024-06-08 11:00:00 0.6067 0.3933 1.542588
2024-06-08 12:00:00 0.6057 0.3943 1.536140
2024-06-08 13:00:00 0.6018 0.3982 1.511301
The BTC_LS-object is class xts/zoo and can be modified using regular xts-syntax. This object can be charted alongside the Japanese candlestick chart,
Source
chart(
ticker = BTC,
main = kline(),
indicator = list(
bollinger_bands(),
sma(n = 7),
sma(n = 14),
sma(n = 27)
),
sub = list(
volume(),
lsr(BTC_LS)
),
options = list(
dark = FALSE
)
)2 Documentation and Installation
To get a full overview of the {cryptoQuotes}-package please refer to the documentation on pkgdown. For installing {cryptoQuotes} see below,
2.1 Stable version
## install from CRAN
install.packages(
pkgs = 'cryptoQuotes',
dependencies = TRUE
)2.2 Development version
## install from github
devtools::install_github(
repo = 'https://github.com/serkor1/cryptoQuotes',
ref = 'development'
)