From a8b68af7ab8d7eea5aa5b147f5f0db322d11139b Mon Sep 17 00:00:00 2001 From: Matt Dancho Date: Sun, 18 Aug 2024 22:06:33 -0400 Subject: [PATCH] remove res --- DESCRIPTION | 1 - R/tq_stock_list.R | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7e2da54..c8ae109 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,6 @@ Depends: Imports: dplyr (>= 1.0.0), ggplot2 (>= 3.4.0), - jsonlite, httr, httr2, curl, diff --git a/R/tq_stock_list.R b/R/tq_stock_list.R index aa78c48..8ab9510 100644 --- a/R/tq_stock_list.R +++ b/R/tq_stock_list.R @@ -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, @@ -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 }