Skip to content

Usecase

Serkan Korkmaz edited this page Apr 18, 2024 · 25 revisions

Cryptocurrency Market Data in R

The main usecase of the cryptoQuotes-package is the available get_-functions. Below is a basic example of retrieving the daily price of Bitcoin.

## 1) get BTC
## on the daily
BTC <- cryptoQuotes::get_quote(
  ticker  = "BTCUSDT",
  source  = "binance",
  futures = FALSE,
  from    = Sys.Date() - 100
)

All the returned objects are xts-objects, with the following format,

index open high low close volume
2024-04-13 02:00:00 67116.52 67929.00 60660.57 63924.51 71395.220
2024-04-14 02:00:00 63924.52 65840.00 62134.00 65661.84 61599.178
2024-04-15 02:00:00 65661.85 66867.07 62274.40 63419.99 52389.531
2024-04-16 02:00:00 63419.99 64365.00 61600.00 63793.39 53435.293
2024-04-17 02:00:00 63793.40 64499.00 59678.16 61277.37 50610.545
2024-04-18 02:00:00 61277.38 62229.90 60939.92 61167.99 8338.567

Charting

The returned market data can be charted and examined as follows,

cryptoQuotes::chart(
  ticker = BTC,
  main = cryptoQuotes::kline(),
  sub = list(
    cryptoQuotes::volume(),
    cryptoQuotes::macd()
  )
)

Clone this wiki locally