#' Get Historical Stock Prices from IEXTrader
#'
#' @param ticker (string) single stock ticker
#' @param type (string) length of time to pull (default: 5 years)
#' @import magrittr curl jsonlite
#' @export
get_historical <- function(ticker, type = "5y") {
url <- iextrader_endpoints("historical")
url <- gsub("'stock'", ticker, url)
url <- gsub("5y", type, url)
dta <- iextrader_api(url)
if (dta == "Not Found" | length(fromJSON(dta)) <= 1) {
dta <- "Not Found"
return(dta)
} else {
dta <- fromJSON(dta)
dta$date <- as.Date(dta$date)
dta <- dta[, c(1:6)]
return(dta)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.