R/forex_rates.R

Defines functions forex_rates

Documented in forex_rates

#' @title Forex Rates
#' @description Get currency exchange rates
#'   
#' @param base_currency Select base currency - USD, EUR, etc
#' 
#' @importFrom purrr set_names
#' @importFrom dplyr bind_cols mutate select everything
#' @importFrom lubridate now
#' 
#' @return
#' @export
#' 
#' @examples
#' forex_rates('USD')
#' forex_rates('EUR')
forex_rates <- function(base_currency = 'USD', ...){
  
  url <- finnhub_endpoint('forex_rates')
  
  df <- retry_get(url, 
                  query = list(token = finnhub_key(),
                               base = base_currency)
  )
  df %>% 
    dplyr::bind_cols() %>% 
    purrr::set_names(tolower) %>% 
    dplyr::mutate(query_date = lubridate::now(tz = finnhub_timezone)) %>% 
    dplyr::select(base, query_date, dplyr::everything())
}  
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.