Skip to content

Commit

Permalink
remove res
Browse files Browse the repository at this point in the history
  • Loading branch information
mdancho84 committed Aug 19, 2024
1 parent 4f2712b commit a8b68af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Depends:
Imports:
dplyr (>= 1.0.0),
ggplot2 (>= 3.4.0),
jsonlite,
httr,
httr2,
curl,
Expand Down
13 changes: 7 additions & 6 deletions R/tq_stock_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,23 @@ tq_exchange <- function(x) {
base_path_1 <- "https://api.nasdaq.com/api/screener/stocks?tableonly=true&exchange="
base_path_2 <- "&download=true"
url <- paste0(base_path_1, x, base_path_2)
# res <- jsonlite::fromJSON(url)

# Use HTTR2 to make the HTTP request:
response <- httr2::request(url) %>%
httr2::req_user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36") %>%
httr2::req_perform()

content <- httr2::resp_body_json(response)

# Evaluate Response / Clean & Return
if (is.null(res$err)) {
if (response$status_code == 200) {

# Collect JSON
content <- httr2::resp_body_json(response)

# Post-process response
suppressWarnings({

exchange_tbl <- do.call(rbind, lapply(content$data$rows, as_tibble))
exchange_tbl <- do.call(rbind, lapply(content$data$rows, tibble::as_tibble))

exchange <- exchange_tbl %>%
dplyr::rename(
symbol = symbol,
Expand Down Expand Up @@ -162,7 +163,7 @@ tq_exchange <- function(x) {
return(exchange)

} else {
warn <- paste0("Error at ", x, " during call to tq_exchange.\n\n", res$err)
warn <- paste0("Error at ", x, " during call to tq_exchange.\n\n", response)
warning(warn)
return(NA) # Return NA on error
}
Expand Down

0 comments on commit a8b68af

Please sign in to comment.