#' @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()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.