Skip to content

Commit

Permalink
fixes #5 (issue with api limits)
Browse files Browse the repository at this point in the history
  • Loading branch information
msperlin committed May 1, 2022
1 parent 0850398 commit ca92e4d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
17 changes: 17 additions & 0 deletions R/yf_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ yf_get <- function(tickers,
# disable dplyr group message
options(dplyr.summarise.inform = FALSE)

# check if using do_parallel = TRUE
# 20220501 Yahoo finance started setting limits to api calls, which
# invalidates the use of any parallel computation
if (do_parallel) {
my_message <- stringr::str_glue(
"Since 2022-04-25, Yahoo Finance started to set limits to api calls, ",
"resulting in 401 errors. When using parallel computations for fetching ",
"data, the limit is reached easily. Said that, the parallel option is now",
" disabled by default. Please set do_parallel = FALSE to use this function.",
"\n\n",
"Returning empty dataframe.")

cli::cli_alert_danger(my_message)
return(data.frame())

}

# first screen msgs

if (!be_quiet) {
Expand Down
3 changes: 1 addition & 2 deletions R/yf_get_single_ticker.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ yf_get_single_ticker <- function(ticker,
be_quiet = FALSE,
thresh_bad_data) {
if (!be_quiet) {
my_msg <- set_cli_msg("({i_ticker}/{length_tickers}) Fetching data for ',
'{ticker}")
my_msg <- set_cli_msg("({i_ticker}/{length_tickers}) Fetching data for {ticker}")
cli::cli_alert_info(my_msg)
}

Expand Down
22 changes: 14 additions & 8 deletions tests/testthat/test-yf_collection.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,30 @@ test_that("Test of yf_get_available_indices()", {

test_that("Test of yf_get_index_comp()", {

if (!covr::in_covr()) {
skip_if_offline()
skip_on_cran() # too heavy for cran
}
if (!covr::in_covr()) {
skip_if_offline()
skip_on_cran() # too heavy for cran
}

available_indices <- yf_get_available_indices()
available_indices <- yf_get_available_indices()

for (i_index in available_indices) {
for (i_index in available_indices) {

expect_true(tibble::is_tibble(yf_get_index_comp(i_index)))
expect_true(tibble::is_tibble(yf_get_index_comp(i_index)))

}
}

})


test_that("Test of yf_collection_get()", {

# 20220501 yf now sets api limits, which invalidates any parallel computation
skip(
paste0("Skipping since parallel is not supported due to YF api limits, ",
"and collections are large datasets for single session download.")
)

# parallel test for collections
n_workers <- floor(parallel::detectCores()/2)
future::plan(future::multisession, workers = n_workers)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-yf_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ test_that(desc = "Test of yf_get()", {

test_that(desc = "Test of yf_get(): do_parallel = TRUE", {

# 20220501 yf now sets api limits, which invalidates any parallel computation
skip("Skipping since parallel is not supported due to YF api limits")

if (!covr::in_covr()) {
skip_if_offline()
skip_on_cran() # too heavy for cran
Expand Down

0 comments on commit ca92e4d

Please sign in to comment.