This high-level API-client gives access to cryptocurrency market
data, without having to rely on low-level coding using
httr2
or curl
. All currently listed and
actively traded on most of the major cryptocurrencies are available for
download.
Note: The library uses xts and zoo under the hood and therefore follows the syntax of base R, and related libraries.
In this vignette we will explore a case study to showcase the capabilities of the library; how was the price action of Dogecoin affected in the minutes after Elon Musk tweeted,
Tweet by Elon Musk - the timezone is CET.
Elon Musk tweeted (Well, now he X’ed) about Dogecoin January 14,
06.18 AM (UTC) - and Dogecoin rallied. To determine how fast the markets
reacted to his tweets, we could get the market data for Dogecoin in 1
minute intervals the day he tweeeted using the
getQuotes()
,
## DOGEUSDT the day
## of the tweet on the
## 1m chart
DOGEUSDT <- cryptoQuotes::getQuote(
ticker = 'DOGEUSDT',
interval = '1m',
source = 'binance',
futures = FALSE,
from = '2022-01-14',
to = '2022-01-15'
)
This returns an object of class xts and zoo with 500
rows. To get a closer look on the price action around the tweet hour, we
can subset
the data using the
window()
-function,
## extract the hour
## of the tweet
DOGEUSDT <- window(
x = DOGEUSDT,
start = ('2022-01-14 06:00:00'),
end = ('2022-01-14 07:00:00')
)
This leaves 61 rows, corresponding to a minute by minute price action. We can calculate the price rallying using the 19th row, corresponding to the minute of the tweet. Dogecoin closed at 0.2055, rallying 8.5%.
We can illustrate this with candlestick charts using the
chart()
- and kline()
-function,
## chart the
## price action
## using klines
cryptoQuotes::chart(
chart = cryptoQuotes::kline(
quote = DOGEUSDT
) %>% cryptoQuotes::addVolume(),
slider = FALSE
)
To create a, presumably, better visual overview we can add event
lines using the addEvents()
-function, which takes a
data.frame
of any kind as argument,
## 1) create event data.frame
## by subsetting the data
event_data <- as.data.frame(
zoo::coredata(
DOGEUSDT[19]
)
)
## 1.1) add the index
## to the event_data
event_data$index <- zoo::index(
DOGEUSDT[19]
)
# 1.2) add event label
# to the data
event_data$event <- 'Elon Musk Tweets'
# 1.3) add color to the
# event label
event_data$color <- 'steelblue'
This event data, can be passed into the chart,
## 1) create event data.frame
## by subsetting the data
event_data <- as.data.frame(
zoo::coredata(
DOGEUSDT[19]
)
)
## 1.1) add the index
## to the event_data
event_data$index <- zoo::index(
DOGEUSDT[19]
)
# 1.2) add event label
# to the data
event_data$event <- 'Elon Musk Tweets'
# 1.3) add color to the
# event label
event_data$color <- 'steelblue'
## 1) chart the
## price action
## using klines
cryptoQuotes::chart(
chart = cryptoQuotes::kline(
quote = DOGEUSDT
)%>% addEvents(
event = event_data
) %>% cryptoQuotes::addVolume(),
slider = FALSE
)