R/etf_holdings.R

Defines functions etf_holdings

Documented in etf_holdings

#' @title ETF Holdings
#' @description Get exchange traded fund holdings
#'   
#' @param index ETF ticker - SPY, XLK, IYW
#' 
#' @importFrom tibble as_tibble
#' @importFrom dplyr mutate select
#' @importFrom lubridate now
#' 
#' @return
#' @export
#' 
#' @examples
#' etf_holdings('SPY')
#' etf_holdings('XLK')
#' etf_holdings('IYW')
etf_holdings <- function(etf, ...){
  
  url <- finnhub_endpoint('etfs_holdings')
  
  df <- retry_get(url, 
                  query = list(token = finnhub_key(),
                               symbol = etf))
  df %>% 
    .[['holdings']] %>% 
    dplyr::mutate(etf = etf,
                  query_date = lubridate::now()) %>% 
    dplyr::select(etf, constituents = symbol, shares = share, percent, query_date) %>% 
    tibble::as_tibble()
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.