There seems to be a rate limit for the number of tickers you can request via the CSV endpoint. The yfinance python library uses the JSON endpoint and doesn't seem to have this rate limit (cf #358 (comment)).
Try to use the other endpoint when there's an error from the current endpoint.
Here's an example that uses the JSON endpoint:
ticker <- "AAPL"
.dateToUNIX <- function(Date) {
posixct <- as.POSIXct(as.Date(Date, origin = "1970-01-01"))
trunc(as.numeric(posixct))
}
url <- paste0("https://query2.finance.yahoo.com/v8/finance/chart/",
ticker,
"?period1=", .dateToUNIX("2022-01-01"),
"&period2=", .dateToUNIX("2022-02-01"),
"&interval=1d")
raw_result <- curl::curl_fetch_memory(url)
result <- jsonlite::fromJSON(rawToChar(raw_result$content))$chart$result
series <- unlist(result$indicators$quote[[1]], recursive = FALSE)
ohlcv <- xts(do.call(cbind, series), .POSIXct(result$timestamp[[1]]))
There seems to be a rate limit for the number of tickers you can request via the CSV endpoint. The yfinance python library uses the JSON endpoint and doesn't seem to have this rate limit (cf #358 (comment)).
Try to use the other endpoint when there's an error from the current endpoint.
Here's an example that uses the JSON endpoint: