R/rate.R

Defines functions instrument_list price instrument_history

Documented in instrument_history instrument_list price

#' Get an instrument list
#'
#' Get a list of tradeable instruments (currency pairs, CFDs, and commodities)
#' that are available for trading with the account specified.
#'
#' See the following link for further information:
#' \url{http://developer.oanda.com/rest-live/rates/}.
#'
#' @param oanda OANDA class object generated by \code{\link{generate_oanda}()}
#' @param fields string vector. list of instrument fields that are to be returned in the response.
#'   The instrument field will be returned regardless of the input to this query parameter.
#' @param instruments string vector. list of instruments that are to be returned in the response.
#' @param account_id string. The account id to fetch the list of tradeable instruments for. This value will be used if it is specified.
#'   If not specified, the value which OANDA object has inside is used as a default (default value is \code{NULL}).
#'
#' @export
instrument_list <- function(oanda, instruments=NULL, fields=NULL, account_id=NULL)
{
  endpoint <- "/v1/instruments"
  query <- list(
    accountId = account_id_inner(oanda, account_id),
    instruments = to_cs_string(instruments),
    fields = to_cs_string(fields)
  )
  request(oanda, endpoint, method=GET, params=list(query=query))
}

#' Get current prices
#'
#' Fetch live prices for specified instruments that are available on the OANDA platform.
#' See the following link for further information:
#' \url{http://developer.oanda.com/rest-live/rates/#getCurrentPrices}
#'
#' @param oanda OANDA class object generated by \code{\link{generate_oanda}()}
#' @param instruments string vector. list of instruments to fetch prices for.
#' @export
price <- function(oanda, instruments)
{
  endpoint <- "/v1/prices"
  query <- list(instruments=paste(instruments, collapse=","))
  request(oanda, endpoint, method=GET, params=list(query=query))
}

#' Retrieve instrument history
#'
#' Get historical information on an instrument
#' See the following link for further information:
#' \url{http://developer.oanda.com/rest-live/rates/#retrieveInstrumentHistory}
#'
#' @param oanda OANDA class object generated by \code{\link{generate_oanda}()}
#' @param instrument string. Name of the instrument to retrieve history for.
#' @param granularity The time range represented by each candlestick.
#'   The value specified will determine the alignment of the first candlestick.
#' @param count: The number of candles to return in the response.
#'  This parameter may be ignored by the server depending on the time range provided.
#'  If not specified, count will default to 500. The maximum acceptable value for count is 5000.
#'  count should not be specified if both the start and end parameters are also specified.
#' @param start The start timestamp for the range of candles requested.
#' @param end The end timestamp for the range of candles requested.
#' @param candle_format Candlesticks representation (about candestick representation).
#'  This can be one of the following:
#'    "midpoint" - Midpoint based candlesticks.
#'    "bidask" - Bid/Ask based candlesticks
#'    The default for candleFormat is "bidask" if the candle_format parameter is not specified.
#' @param include_first A boolean field which may be set to TRUE or FALSE.
#'  If it is set to TRUE, the candlestick covered by the start timestamp will be returned.
#'  If it is set to FASE, this candlestick will not be returned.
#'  This field exists so clients may easily ensure that they can poll for all candles more recent than their last received candle.
#'  The default for include_first is TRUE.
#' @param daily_alignment The hour of day used to align candles with hourly, daily, weekly, or monthly granularity.
#'  The value specified is interpretted as an hour in the timezone set through the alignment_timezone parameter and must be an integer between 0 and 23.
#'  The default for daily_alignment is 17, which corresponds to 17:00 local time in New York.
#' @param alignment_timezone The timezone to be used for the dailyAlignment parameter.
#'  This parameter does NOT affect the returned timestamp, the start or end parameters, these will always be in UTC.
#'  The timezone format used is defined by the IANA Time Zone Database, a full list of the timezones supported by the REST API can be found here.
#'  The default for alignmentTimezone is "America/New_York"
#' @param weekly_alignment The day of the week used to align candles with weekly granularity.
#'  The value specified will be used as the start/end day when calculating the weekly candles.
#'  Valid values are: "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday".
#'  The default for weekly_alignment is "Friday".
#' @export
instrument_history <- function(oanda, instrument, granularity=NULL, count=NULL, start=NULL, end=NULL, candle_format=NULL, include_first=NULL, daily_alignment=NULL, alignment_timezone=NULL, weekly_alignment=NULL)
{
  endpoint <- "/v1/candles"
  query <- list(instrument=instrument, granularity=granularity, count=count, start=start, end=end, candle_format=NULL, includeFirst=include_first, dailyAlignment=daily_alignment, alignmentTimezone=alignment_timezone, weeklyAlignment=weekly_alignment)
  request(oanda, endpoint, method=GET, params=list(query=query))
}
beykuet/ROandaAPI documentation built on May 6, 2019, 2:30 p.m.