R/get_historical.R

#' 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)
  }
}
JestonBlu/IEXTrader documentation built on May 29, 2019, 1:20 p.m.