R/company_news.R

Defines functions company_news

Documented in company_news

#' @title Company News
#' @description Get company news
#'  
#' @param symbol Ticker symbol
#' @param from Begin date
#' @param to End date
#' 
#' @importFrom purrr set_names
#' @importFrom lubridate today as_datetime
#' @importFrom dplyr mutate
#' 
#' @return
#' @export
#' 
#' @examples
#' company_news('NVDA', from = '2020-05-01', to = today())
company_news <- function(symbol, 
                         from = lubridate::today(tz = finnhub_timezone) - 7, 
                         to = lubridate::today(tz = finnhub_timezone), 
                         ...){
  
  url <- finnhub_endpoint('company_news')
  
  retry_get(url, 
            query = list(token = finnhub_key(),
                         symbol = symbol,
                         from = from,
                         to = to)) %>%
    purrr::set_names(c('news_category', 'unixtime', 'headline', 'id',
                       'image', 'related', 'source', 'summary', 'url')) %>%
    dplyr::mutate(date = as_datetime(unixtime, tz = finnhub_timezone))
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.