# Install if needed:
# install.packages(c("jsonlite", "dplyr"), repos = "https://cloud.r-project.org")

library(jsonlite)
library(dplyr)
url <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=99"
raw <- fromJSON(url)

# Extract the OHLCV frame (time, open, high, low, close, volumefrom, volumeto, conversionType, conversionSymbol)
df <- raw$Data$Data %>%
  mutate(time = as.POSIXct(time, origin = "1970-01-01", tz = "UTC")) %>%
  arrange(time)

head(df)
##         time     high      low     open volumefrom   volumeto    close
## 1 2025-07-10 116848.3 110555.5 111291.7   31905.27 3616719328 116023.3
## 2 2025-07-11 118890.3 115236.7 116023.3   26050.27 3060911543 117573.9
## 3 2025-07-12 118240.0 116954.1 117573.9    7395.67  869899617 117468.2
## 4 2025-07-13 119503.6 117264.6 117468.2    9553.52 1133368268 119127.7
## 5 2025-07-14 123220.3 118951.6 119127.7   31361.70 3784774921 119869.0
## 6 2025-07-15 119958.9 115709.6 119869.0   50123.19 5881848281 117777.9
##   conversionType conversionSymbol
## 1         direct                 
## 2         direct                 
## 3         direct                 
## 4         direct                 
## 5         direct                 
## 6         direct
max_close <- max(df$close, na.rm = TRUE)
max_row <- df %>% filter(close == max_close) %>% slice(1)

cat(sprintf("Maximum daily close for BTC/USD over the last 100 days: %.2f\n", max_close))
## Maximum daily close for BTC/USD over the last 100 days: 124723.00
cat(sprintf("Occurred on: %s (UTC)\n", as.Date(max_row$time)))
## Occurred on: 2025-10-06 (UTC)