Skip to content

Commit

Permalink
even more string optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 14, 2023
1 parent af3afaf commit e3cd031
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
13 changes: 12 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
# ichimoku 1.4.11.9000 (development)

#### Updates:

* Uses 'mirai' to run `oanda_studio(new.process = TRUE)`
* Fixes `oanda_switch()`, regression since v1.4.11.
* Fixes `oanda_switch()` after a regression in 1.4.11.
* Updates internal OANDA instruments list.
* Internal performance enhancements.

# ichimoku 1.4.11

#### New features:

* Allows using the environment variable 'OANDA_API_KEY' as an alternative to the 'keyring' package.

#### Updates:

* Arguments 'keep.data' and 'keep.attrs' across the package now have an explicit default value of FALSE (no resultant change in behaviour).
* Internal performance enhancements.
* Requires nanonext >= 0.11.0.

# ichimoku 1.4.10

#### Updates:

* Improves handling of OANDA API errors.

# ichimoku 1.4.9

#### Updates:

* Internal performance enhancements.
* Requires nanonext >= 0.10.0 and R >= 3.5.

Expand Down
2 changes: 1 addition & 1 deletion R/iplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ iplot <- function(x,

server <- function(input, output, session) {

window <- reactive(paste0(input$dates[1L], "/", input$dates[2L]))
window <- reactive(sprintf("%s/%s", input$dates[1L], input$dates[2L]))
left_px <- reactive(input$plot_hover$coords_css$x)
top_px <- reactive(input$plot_hover$coords_css$y)
posi_x <- reactive(round(input$plot_hover$x, digits = 0))
Expand Down
27 changes: 14 additions & 13 deletions R/oanda.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ oanda <- function(instrument,
getPrices <- function(instrument, granularity, count = NULL, from = NULL,
to = NULL, price, server, apikey, .validate) {

url <- paste0("https://api-fx", switch(server, practice = "practice", live = "trade"),
".oanda.com/v3/instruments/", instrument, "/candles?granularity=",
granularity, "&price=", price,
if (length(count)) strcat("&count=", as.character(count)),
if (length(from)) strcat("&from=", as.character(from)),
if (length(to)) strcat("&to=", as.character(to)))
url <- sprintf(
"https://api-fx%s.oanda.com/v3/instruments/%s/candles?granularity=%s&price=%s%s%s%s",
switch(server, practice = "practice", live = "trade"), instrument, granularity, price,
if (length(count)) strcat("&count=", as.character(count)) else "",
if (length(from)) strcat("&from=", as.character(from)) else "",
if (length(to)) strcat("&to=", as.character(to)) else ""
)
resp <- ncurl(url,
convert = FALSE,
follow = TRUE,
Expand Down Expand Up @@ -759,7 +760,7 @@ oanda_studio <- function(instrument = "USD_JPY",
type = input$type)
})

output$savedata <- downloadHandler(filename = function() paste0(input$instrument, "_", input$granularity, "_", input$price, ".rda"),
output$savedata <- downloadHandler(filename = function() sprintf("%s_%s_%s.rda", input$instrument, input$granularity, input$price),
content = function(file) archive(pdata(), file))

session$onSessionEnded(stopApp)
Expand Down Expand Up @@ -1007,9 +1008,9 @@ oanda_positions <- function(instrument, time, server, apikey) {
server <- if (missing(server)) do_[["getServer"]]() else match.arg(server, c("practice", "live"))
if (missing(apikey)) apikey <- do_[["getKey"]](server = server)

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))))
url <- sprintf("https://api-fx%s.oanda.com/v3/instruments/%s/positionBook%s",
switch(server, practice = "practice", live = "trade"), instrument,
if (missing(time)) "" else sprintf("?time=%.f", unclass(as.POSIXct(time))))
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c(Authorization = strcat("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX", `User-Agent` = .user_agent))
Expand Down Expand Up @@ -1099,9 +1100,9 @@ oanda_orders <- function(instrument, time, server, apikey) {
server <- if (missing(server)) do_[["getServer"]]() else match.arg(server, c("practice", "live"))
if (missing(apikey)) apikey <- do_[["getKey"]](server = server)

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))))
url <- sprintf("https://api-fx%s.oanda.com/v3/instruments/%s/orderBook%s",
switch(server, practice = "practice", live = "trade"), instrument,
if (missing(time)) "" else sprintf("?time=%.f", unclass(as.POSIXct(time))))
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c(Authorization = strcat("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX", `User-Agent` = .user_agent))
Expand Down

0 comments on commit e3cd031

Please sign in to comment.