R/stock_dividends.R

Defines functions stock_dividends

Documented in stock_dividends

#' @title Stock Dividends
#' @description Get history of stock dividends paid
#'  
#' @param symbol Stock ticker
#' @param from Begin date
#' @param to End date
#' 
#' @importFrom purrr set_names
#' @importFrom dplyr mutate
#' @importFrom lubridate today ymd
#' 
#' @return
#' @export
#' 
#' @examples
#' stock_dividends('NVDA')
stock_dividends <- function(symbol, 
                            from = lubridate::today(tz = finnhub_timezone) - 365, 
                            to = lubridate::today(tz = finnhub_timezone), ...){
  
  url <- finnhub_endpoint('stock_dividends')

  df <- retry_get(url,
                  query = list(token = finnhub_key(),
                               symbol = symbol,
                               from = from, 
                               to = to)) 
  df %>% 
    dplyr::mutate(date = lubridate::ymd(date, tz = finnhub_timezone)) %>% 
    purrr::set_names(c('symbol', 'date', 'amount', 'adjusted_amount', 
                       'pay_date', 'record_date', 'declaration_date', 'currency'))
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.