library(cryptoQuotes)
This high-level API
-client provides open access to cryptocurrency market data without relying on low-level coding and API
-keys. Currently all actively traded cryptocurrencies on 1 major exchanges are available, see the wiki for more details.
In this vignette we will explore a case study to showcase the capabilities of {cryptoQuotes}; how did the Dogecoin
-market react to Elon Musks following tweet,
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 get_quotes()
-function,
## DOGEUSDT the day
## of the tweet on the
## 1m chart
cryptoQuotes::get_quote(
DOGE <-ticker = 'DOGE-USDT',
interval = '1m',
source = 'kucoin',
futures = FALSE,
from = '2022-01-14 07:00:00',
to = '2022-01-14 08:00:00'
)
This returns an object of class xts and zoo with 61 rows. To calculate the rally within the first minute of the tweet, we can use {xts}-syntax to determine its magnitude,
## extrat the
## tweet moment
DOGE["2022-01-14 07:18:00"]
tweet_moment <-
## calculate
## rally
cat(
"Doge closed:", round((tweet_moment$close/tweet_moment$open - 1),4) * 100, "%"
)
#> Doge closed: 8.71 %
Dogecoin
rallied 8.71% within the minute Elon Musk tweeted.
We can visualize the rally this with candlestick charts using the chart()
- and kline()
-function,
## chart the
## price action
## using klines
::chart(
cryptoQuotesticker = DOGE,
main = cryptoQuotes::kline(),
indicator = list(
::bollinger_bands()
cryptoQuotes
),sub = list(
::volume()
cryptoQuotes
),options = list(
dark = FALSE
) )
To create a, presumably, better visual overview we can add event lines using the event_data
-argument, which takes a data.frame
of any kind as argument,
## 1) create event data.frame
## by subsetting the data
as.data.frame(
event_data <-::coredata(
zoo"2022-01-14 07:18:00"]
DOGE[
)
)
## 1.1) add the index
## to the event_data
$index <- zoo::index(
event_data"2022-01-14 07:18:00"]
DOGE[
)
# 1.2) add event label
# to the data
$event <- 'Elon Musk Tweets'
event_data
# 1.3) add color to the
# event label
$color <- 'steelblue' event_data
This event data, can be passed into the chart as follows,
## 1) chart the
## price action
## using klines
::chart(
cryptoQuotesticker = DOGE,
event_data = event_data,
main = cryptoQuotes::kline(),
indicator = list(
::bollinger_bands()
cryptoQuotes
),sub = list(
::volume()
cryptoQuotes
),options = list(
dark = FALSE
) )