Skip to content

Commit

Permalink
nanonext compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Aug 24, 2023
1 parent 60aed2b commit bfbb470
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Updates:

* Ensures compatibility with upcoming {nanonext} releases.
* Internal performance enhancements.

# ichimoku 1.4.7
Expand Down
16 changes: 8 additions & 8 deletions R/oanda.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ getPrices <- function(instrument, granularity, count = NULL, from = NULL,
if (!is.null(from)) paste0("&from=", from),
if (!is.null(to)) paste0("&to=", to))
resp <- ncurl(url,
convert = FALSE,
convert = TRUE,
follow = TRUE,
headers = c(Authorization = paste0("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX",
`User-Agent` = .user_agent),
response = "date")
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ",
deserialize_json(resp[["raw"]]), call. = FALSE)
deserialize_json(resp[["data"]]), call. = FALSE)
timestamp <- as.POSIXct.POSIXlt(strptime(resp[["headers"]][["date"]],
format = "%a, %d %b %Y %H:%M:%S", tz = "UTC"))
candles <- deserialize_json(resp[["raw"]], query = "/candles")
Expand Down Expand Up @@ -1008,13 +1008,13 @@ oanda_positions <- function(instrument, time, server, apikey) {
url <- paste0("https://api-fx", switch(server, practice = "practice", live = "trade"),
".oanda.com/v3/instruments/", instrument, "/positionBook",
if (!missing(time)) paste0("?time=", unclass(as.POSIXct(time))))
resp <- ncurl(url, convert = FALSE, follow = TRUE,
resp <- ncurl(url, convert = TRUE, follow = TRUE,
headers = c(Authorization = paste0("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX", `User-Agent` = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ",
deserialize_json(resp[["raw"]]), call. = FALSE)
data <- deserialize_json(resp[["raw"]], query = "/positionBook")
deserialize_json(resp[["data"]]), call. = FALSE)
data <- deserialize_json(resp[["data"]], query = "/positionBook")
currentprice <- as.numeric(data[["price"]])
timestamp <- .Call(ichimoku_psxct, data[["unixTime"]])
bucketwidth <- as.numeric(data[["bucketWidth"]])
Expand Down Expand Up @@ -1100,13 +1100,13 @@ oanda_orders <- function(instrument, time, server, apikey) {
url <- paste0("https://api-fx", switch(server, practice = "practice", live = "trade"),
".oanda.com/v3/instruments/", instrument, "/orderBook",
if (!missing(time)) paste0("?time=", unclass(as.POSIXct(time))))
resp <- ncurl(url, convert = FALSE, follow = TRUE,
resp <- ncurl(url, convert = TRUE, follow = TRUE,
headers = c(Authorization = paste0("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX", `User-Agent` = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ",
deserialize_json(resp[["raw"]]), call. = FALSE)
data <- deserialize_json(resp[["raw"]], query = "/orderBook")
deserialize_json(resp[["data"]]), call. = FALSE)
data <- deserialize_json(resp[["data"]], query = "/orderBook")
currentprice <- as.numeric(data[["price"]])
timestamp <- .Call(ichimoku_psxct, data[["unixTime"]])
bucketwidth <- as.numeric(data[["bucketWidth"]])
Expand Down
10 changes: 5 additions & 5 deletions R/switch.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ do_ <- function() {
url <- switch(server,
practice = "https://api-fxpractice.oanda.com/v3/accounts",
live = "https://api-fxtrade.oanda.com/v3/accounts")
resp <- ncurl(url, convert = FALSE, follow = TRUE,
resp <- ncurl(url, convert = TRUE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
"User-Agent" = .user_agent))
parsed <- deserialize_json(resp[["raw"]])
parsed <- deserialize_json(resp[["data"]])
length(parsed[["accounts"]]) || stop(parsed, call. = FALSE)
account <<- parsed[["accounts"]][[1L]][["id"]]
}
Expand All @@ -134,15 +134,15 @@ do_ <- function() {
url <- paste0("https://api-fx", switch(server, practice = "practice", live = "trade"),
".oanda.com/v3/accounts/", do_$getAccount(server = server, apikey = apikey),
"/instruments")
resp <- ncurl(url, convert = FALSE, follow = TRUE,
resp <- ncurl(url, convert = TRUE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
"User-Agent" = .user_agent))
if (resp[["status"]] != 200L) {
resp <- ncurl(url, convert = FALSE, follow = TRUE,
resp <- ncurl(url, convert = TRUE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
"User-Agent" = .user_agent))
}
parsed <- deserialize_json(resp[["raw"]])
parsed <- deserialize_json(resp[["data"]])
length(parsed[["instruments"]]) || {
warning(parsed,
"\nInstruments list could not be retrieved - falling back to internal data",
Expand Down

0 comments on commit bfbb470

Please sign in to comment.