# Libraries
library(jsonlite)
library(tidyverse)
# Get today's date and the date 1 year ago
<- as.integer(as.POSIXct(Sys.Date()))
end_date <- as.integer(as.POSIXct(Sys.Date() - 365))
start_date
# Construct the API URL
<- paste0(
url "https://api.coingecko.com/api/v3/coins/",
$crypto,
params"/market_chart/range?vs_currency=usd&from=",
"&to=", end_date
start_date,
)
# Fetch the data using readLines
<- readLines(url, warn = FALSE)
json_data
# Parse the JSON data
<- fromJSON(json_data)$prices %>% as.data.frame()
data colnames(data) <- c("timestamp", "value")
# Format the date (date is provided in millisecond, thus division by 1000)
$timestamp <- date(data$timestamp / 1000) data
Crypto price analysis: bitcoin
This report is gives some information about the bitcoin price for the last 2 weeks.
It is also used to show how parametrized reports in Quarto work.
Getting data
The price can be fetched from the coingecko API. Here is the code to do so:
bitcoin price evolution
Now, let’s make a chart to show the evolution using dygraph:
library(dygraphs)
dygraph(data)
Conclustion
Read more about parametrized reporting in Quarto here.