From d8f55c6f872698de7943731f9193151a27dccad3 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:34:04 +0000 Subject: [PATCH] retry instruments api once --- R/switch.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/switch.R b/R/switch.R index 6034fc31..2a183dcc 100644 --- a/R/switch.R +++ b/R/switch.R @@ -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,