Skip to content

Commit

Permalink
retry instruments api once
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jan 15, 2024
1 parent dd0c5fd commit d8f55c6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions R/switch.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ do_ <- function() {
url <- sprintf("https://api-fx%s.oanda.com/v3/accounts/%s/instruments",
switch(server, practice = "practice", live = "trade"),
do_$getAccount(server = server, apikey = apikey))
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c("Authorization" = strcat("Bearer ", apikey),
"User-Agent" = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ", deserialize_json(resp[["data"]]), call. = FALSE)
for (i in seq_len(2L)) {
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c("Authorization" = strcat("Bearer ", apikey),
"User-Agent" = .user_agent))
resp[["status"]] == 200L && break
i == 2L && stop("status code ", resp[["status"]], " - ", deserialize_json(resp[["data"]]), call. = FALSE)
}
parsed <- deserialize_json(resp[["data"]])
length(parsed[["instruments"]]) || {
warning(parsed,
Expand Down

0 comments on commit d8f55c6

Please sign in to comment.