Skip to content

Commit

Permalink
Use new handle and wait after connection attempt
Browse files Browse the repository at this point in the history
Some users are still experiencing intermittent issues importing data
from Yahoo Finance. Add 100ms between each connection attempt, and
also use a new handle.

See #166.
  • Loading branch information
joshuaulrich committed Jun 19, 2017
1 parent b523b15 commit a7c57e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/getSymbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,16 @@ formals(loadSymbols) <- loadSymbols.formals
}

# establish session
new.session <- function(h) {
new.session <- function() {
tmp <- tempfile()
on.exit(unlink(tmp))

for (i in 1:5) {
h <- curl::new_handle()
curl::curl_download("https://finance.yahoo.com", tmp, handle = h)
if (NROW(curl::handle_cookies(h)) > 0)
break;
Sys.sleep(0.1)
}

if (NROW(curl::handle_cookies(h)) == 0)
Expand All @@ -237,7 +239,7 @@ formals(loadSymbols) <- loadSymbols.formals
return(h)
}

h$ch <- new.session(curl::new_handle())
h$ch <- new.session()

n <- if (unclass(Sys.time()) %% 1L >= 0.5) 1L else 2L
query.srv <- paste0("https://query", n, ".finance.yahoo.com/",
Expand Down

0 comments on commit a7c57e2

Please sign in to comment.