#' @title Forex Candles
#' @description Get forexcandles
#'
#' @param symbol Forex symbol
#' @param resolution 1-minute, 5-minute, 15-minute, 30-minute, 60-minute,
#' daily, weekly and monthly
#' @param from Begin date - default 30-days from today
#' @param to End date - current date
#' @param format json
#' @param adjusted Adjusted prices ('true') or not ('false')
#'
#' @importFrom tibble as_tibble
#' @importFrom purrr set_names
#' @importFrom dplyr mutate select everything
#' @importFrom lubridate as_datetime today
#'
#' @return
#' @export
#'
#' @examples
#' forex_candles('OANDA:EUR_USD')
#' forex_candles('OANDA:EUR_USD', resolution = '1') # Not working?
#' forex_candles('OANDA:EUR_USD', resolution = '5')
#' forex_candles('OANDA:EUR_USD', resolution = '15')
#' forex_candles('OANDA:EUR_USD', resolution = '30')
#' forex_candles('OANDA:EUR_USD', resolution = '60')
#' forex_candles('OANDA:EUR_USD', resolution = 'D', from = today() - 365, to = today())
#' forex_candles('OANDA:EUR_USD', from = today() - 365, resolution = 'W')
#' forex_candles('OANDA:EUR_USD', from = today() - 365, resolution = 'M')
forex_candles <- function(symbol,
resolution = 'D',
from = lubridate::today() - 30,
to = lubridate::today(),
format='json',
adjusted='true',
...){
from <- date_to_unix(from)
to <- date_to_unix(to)
url <- finnhub_endpoint('forex_candles')
df <- retry_get(url,
query = list(token = finnhub_key(),
symbol = symbol,
resolution = resolution,
from = from,
to = to,
format = format,
adjusted = adjusted))
df %>%
tibble::as_tibble() %>%
purrr::set_names(c('close', 'high', 'low', 'open' ,'flag', 'unixtime', 'volume')) %>%
dplyr::mutate(date = lubridate::as_datetime(unixtime, tz = finnhub_timezone),
symbol = symbol) %>%
dplyr::select(symbol, date, dplyr::everything())
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.