R/historical_constituents.R

Defines functions historical_constituents

Documented in historical_constituents

#' @title Historical Constituents
#' @description Get history of index constituents
#'  
#' @param index Index ticker - ^GSPC, ^DJI
#' 
#' @importFrom tibble tibble
#' @importFrom dplyr mutate select
#' @importFrom lubridate ymd now
#' 
#' @return
#' @export
#' 
#' @examples
#' historical_constituents('^GSPC')
#' historical_constituents('^DJI')
historical_constituents <- function(index, ...){
  
  url <- finnhub_endpoint('historical_constituents')
  
  df <- retry_get(url, 
                  query = list(token = finnhub_key(),
                               symbol = index))
  df %>%
    .[['historicalConstituents']] %>% 
    dplyr::mutate(index = index,
                  date = lubridate::ymd(date, tz = finnhub_timezone),
                  query_date = lubridate::now()) %>%
    dplyr::select(index, constituents = symbol, date, action, query_date)
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.