Usecase
What happens when Elon Musk Tweets about Dogecoin?
Source:vignettes/usecase.Rmd
usecase.Rmd
Introduction
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,
Cryptocurrency Market Analysis in R
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
DOGE <- cryptoQuotes::get_quote(
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
tweet_moment <- DOGE["2022-01-14 07:18:00"]
## 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.
Charting price action with candlesticks
We can visualize the rally this with candlestick charts using the
chart()
- and kline()
-function,
Charting price action with event lines
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
event_data <- as.data.frame(
zoo::coredata(
DOGE["2022-01-14 07:18:00"]
)
)
## 1.1) add the index
## to the event_data
event_data$index <- zoo::index(
DOGE["2022-01-14 07:18:00"]
)
# 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 as follows,