Skip to content

Commit

Permalink
Oanda only provides past 180 days
Browse files Browse the repository at this point in the history
The previous commit assumed Oanda only provided 180 days per request,
but they actually only provide data for the past 180 days. No data will
be returned for dates prior to 180 days ago. Update the documentation
and warning accordingly.

Also remove old code used to request the minimum amount of data from
the Oanda servers, while still fulfilling the user's request.

See #144.
  • Loading branch information
joshuaulrich committed Apr 10, 2017
1 parent f17b925 commit 51a3735
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 3 additions & 11 deletions R/getSymbols.R
Expand Up @@ -1055,10 +1055,6 @@ function(Symbols,env,return.class='xts',
if(!hasArg(verbose)) verbose <- FALSE
if(!hasArg(auto.assign)) auto.assign <- TRUE

# Request minimum data from server to fulfill user's request
daySpans <- c(7, 30, 60, 90, 180)
dateStr <- c("d7", "d30", "d60", "d90", "d180")

tmp <- tempfile()
on.exit(unlink(tmp))
for(i in 1:length(Symbols)) {
Expand All @@ -1081,15 +1077,11 @@ function(Symbols,env,return.class='xts',
}

if(verbose) cat("downloading ",Symbols.name,".....")
# Request minimum data from server to fulfill user's request
dateDiff <- difftime(to, from, units="days")
dateLoc <- which(daySpans >= dateDiff)
# throw warning, but return as much data as possible
if(!length(dateLoc)) {
warning("Oanda limits data to 180 days. Symbol: ", Symbols[[i]])
dateLoc <- length(dateStr)
if(from < Sys.Date() - 180) {
warning("Oanda only provides historical data for the past 180 days",
" Symbol: ", Symbols[[i]])
}
data_range <- dateStr[dateLoc[1]]
oanda.URL <- paste0("https://www.oanda.com/fx-for-business/",
"historical-rates/api/update/?&widget=1",
"&source=OANDA&display=absolute&adjustment=0",
Expand Down
5 changes: 3 additions & 2 deletions man/getSymbols.oanda.Rd
Expand Up @@ -40,8 +40,9 @@ available by calling \code{oanda.currencies} }
Meant to be called internally by getSymbols only.

Oanda data is 7 day daily average price data, that is Monday through Sunday.
There is a limit of 180 days per request, and getSymbols will return as much
data as possible and warn that the limit has been exceeded.
Oanda only provides historical data for the past 180 days. getSymbols will
return as much data as possible, and warn when the \code{from} date is more
than 180 days ago.
}
\value{
A call to getSymbols(Symbols,src="oanda") will load into the specified
Expand Down

0 comments on commit 51a3735

Please sign in to comment.