Skip to content

Commit

Permalink
more string optimisation + update instruments list
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 14, 2023
1 parent b9bab35 commit af3afaf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 43 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 @@

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

# ichimoku 1.4.11
Expand Down
8 changes: 4 additions & 4 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"NAS100_USD", "NATGAS_USD", "NL25_EUR", "NZD_CAD", "NZD_CHF",
"NZD_HKD", "NZD_JPY", "NZD_SGD", "NZD_USD", "SG30_SGD", "SGD_CHF",
"SGD_JPY", "SOYBN_USD", "SPX500_USD", "SUGAR_USD", "TRY_JPY",
"TWIX_USD", "UK100_GBP", "UK10YB_GBP", "US2000_USD", "US30_USD",
"UK100_GBP", "UK10YB_GBP", "US2000_USD", "US30_USD",
"USB02Y_USD", "USB05Y_USD", "USB10Y_USD", "USB30Y_USD", "USD_CAD",
"USD_CHF", "USD_CNH", "USD_CZK", "USD_DKK", "USD_HKD", "USD_HUF",
"USD_JPY", "USD_MXN", "USD_NOK", "USD_PLN", "USD_SEK",
Expand All @@ -112,7 +112,7 @@
"Japan 225", "Japan 225 (JPY)", "US Nas 100", "Natural Gas",
"Netherlands 25", "NZD/CAD", "NZD/CHF", "NZD/HKD", "NZD/JPY",
"NZD/SGD", "NZD/USD", "Singapore 30", "SGD/CHF", "SGD/JPY", "Soybeans",
"US SPX 500", "Sugar", "TRY/JPY", "Taiwan Index", "UK 100", "UK 10Y Gilt",
"US SPX 500", "Sugar", "TRY/JPY", "UK 100", "UK 10Y Gilt",
"US Russ 2000", "US Wall St 30", "US 2Y T-Note", "US 5Y T-Note",
"US 10Y T-Note", "US T-Bond", "USD/CAD", "USD/CHF", "USD/CNH",
"USD/CZK", "USD/DKK", "USD/HKD", "USD/HUF", "USD/JPY",
Expand All @@ -134,7 +134,7 @@
"CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CFD",
"CURRENCY", "CFD", "CFD", "CFD", "CFD", "CFD", "CURRENCY",
"CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CFD",
"CURRENCY", "CURRENCY", "CFD", "CFD", "CFD", "CURRENCY", "CFD",
"CURRENCY", "CURRENCY", "CFD", "CFD", "CFD", "CURRENCY",
"CFD", "CFD", "CFD", "CFD", "CFD", "CFD", "CFD", "CFD",
"CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY",
"CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY", "CURRENCY",
Expand All @@ -144,5 +144,5 @@
"METAL", "METAL", "METAL", "METAL", "METAL", "METAL", "METAL",
"CFD", "CFD", "CFD", "CURRENCY")),
class = "data.frame",
row.names = c(NA, -124L)
row.names = c(NA, -123L)
)
63 changes: 30 additions & 33 deletions R/iplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ iplot <- function(x,
#' Shiny plots.
#'
#' @param label a function returning the character string to be shown.
#' @param left the horizontal position of the guide in pixels.
#' @param top the vertical position of the guide in pixels.
#' @param left integer horizontal position of the guide in pixels.
#' @param top integer vertical position of the guide in pixels.
#'
#' @return An object of class 'shiny.tag' comprising the HTML to be rendered.
#'
#' @noRd
#'
drawGuide <- function(label, left, top) {
wellPanel(
style = paste0("position: absolute; z-index: 100; background-color: rgba(245, 245, 245, 0.85); left: ",
left, "px; top: ", top, "px; font-size: 0.8em; padding: 0;"),
style = sprintf("position: absolute; z-index: 100; background-color: rgba(245, 245, 245, 0.85);
left: %dpx; top: %dpx; font-size: 0.8em; padding: 0;", left, top),
HTML(as.character(label))
)
}
Expand All @@ -187,8 +187,8 @@ drawGuide <- function(label, left, top) {
#'
#' @param sidx the selected index value.
#' @param sdata the selected coredata row.
#' @param left the horizontal cursor position in pixels.
#' @param top the vertical cursor position in pixels.
#' @param left integer horizontal cursor position in pixels.
#' @param top integer vertical cursor position in pixels.
#' @param type the type of subplot.
#' @param custom the column name of custom subplot (if applicable).
#'
Expand All @@ -197,33 +197,30 @@ drawGuide <- function(label, left, top) {
#' @noRd
#'
drawInfotip <- function(sidx, sdata, left, top, type, custom = NULL) {
cd <- sdata[["cd"]]
wellPanel(
style = paste0("position: absolute; z-index: 100; background-color: rgba(245, 245, 245, 0.8); left: ",
left + 60, "px; top: ", top + 45, "px; font-size: 0.8em; padding: 1px 5px 5px 5px;"),
HTML(paste0("<div style='margin: 0; padding: 0; font-weight: bold'>",
if (isTRUE(sdata[["cd"]] == 1)) "&#9651;<br />" else if (isTRUE(sdata[["cd"]] == -1)) "&#9660;<br />" else "&#8212;<br />",
format.POSIXct(sidx),
"</div><div style='text-align: center; margin: 2px 0 0 0; padding: 0'>H: ",
signif(sdata[["high"]], digits = 5),
"</div><div style='margin: 0; padding: 0'>O: ",
signif(sdata[["open"]], digits = 5),
"&nbsp;&nbsp;C: ", signif(sdata[["close"]], digits = 5),
"</div><div style='text-align: center; margin: 0; padding: 0'>L: ",
signif(sdata[["low"]], digits = 5),
"</div><div style='margin: 2px 0 0 0; padding: 0'>Tenkan: ",
signif(sdata[["tenkan"]], digits = 5),
"<br />Kijun: ", signif(sdata[["kijun"]], digits = 5),
"<br />Senkou A: ", signif(sdata[["senkouA"]], digits = 5),
"<br />Senkou B: ", signif(sdata[["senkouB"]], digits = 5),
"<br />Chikou: ", signif(sdata[["chikou"]], digits = 5),
switch(
type,
r = sprintf("<br />R-indicator: %.3g", 100 * sdata[["osc_typ_slw"]]),
s = sprintf("<br />S-fast: %.3g<br />S-slow: %.3g", 100 * sdata[["osc_typ_fst"]], 100 * sdata[["osc_typ_slw"]]),
line = ,
bar = sprintf("<br />%s: %.5g", custom, sdata[[custom]]),
NULL
),
"</div>"))
style = sprintf("position: absolute; z-index: 100; background-color: rgba(245, 245, 245, 0.8);
left: %dpx; top: %dpx; font-size: 0.8em; padding: 1px 5px 5px 5px;",
left + 60, top + 45),
HTML(
sprintf(
"<div style='margin: 0; padding: 0; font-weight: bold'>%s<br/>%s</div>
<div style='text-align: center; margin: 2px 0 0 0; padding: 0'>H: %.5g</div>
<div style='margin: 0; padding: 0'>O: %.5g&nbsp;&nbsp;C: %.5g</div>
<div style='text-align: center; margin: 0; padding: 0'>L: %.5g</div>
<div style='margin: 2px 0 0 0; padding: 0'>Tenkan: %.5g<br />Kijun: %.5g<br />Senkou A: %.5g<br />Senkou B: %.5g<br />Chikou: %.5g%s</div>",
if (is.na(cd) || cd == 0) "&#8212;" else if (cd == 1) "&#9651;" else if (cd == -1) "&#9660;",
format.POSIXct(sidx), sdata[["high"]], sdata[["open"]], sdata[["close"]], sdata[["low"]],
sdata[["tenkan"]], sdata[["kijun"]], sdata[["senkouA"]], sdata[["senkouB"]], sdata[["chikou"]],
switch(
type,
r = sprintf("<br />R-indicator: %.3g", 100 * sdata[["osc_typ_slw"]]),
s = sprintf("<br />S-fast: %.3g<br />S-slow: %.3g", 100 * sdata[["osc_typ_fst"]], 100 * sdata[["osc_typ_slw"]]),
line = ,
bar = sprintf("<br />%s: %.5g", custom, sdata[[custom]]),
""
)
)
)
)
}
3 changes: 1 addition & 2 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ summary.ichimoku <- function(object, strat = TRUE, ...) {
} else if (dims[2L] < 12L) {
cat(summary <- "incomplete ichimoku object (partial or subset)", "\n", file = stdout())
} else {
cat(summary <- paste0("ichimoku object with dimensions (", dims[1L], ", ",
dims[2L], ")"), "\n", file = stdout())
cat(summary <- sprintf("ichimoku object with dimensions (%d, %d)", dims[1L], dims[2L]), "\n", file = stdout())
if (dims[1L] != 0L) {
core <- coredata.ichimoku(object)
end <- sum(!is.na(core[, "close"]))
Expand Down
2 changes: 1 addition & 1 deletion R/mltools.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ writeVectors <- function(x, pairs, p2, xlen, type) {
boolean = as.integer(c(rep(NA, offset), (x[, c1] > x[, c2])[1:(xlen - offset)])),
c(rep(NA, offset), (x[, c1] - x[, c2])[1:(xlen - offset)]))
}, c1 = pairs[[1L]], c2 = pairs[[2L]], SIMPLIFY = FALSE, USE.NAMES = FALSE),
do.call(c, mapply(function(c1, c2) paste0(c1, "_", c2),
do.call(c, mapply(function(c1, c2) sprintf("%s_%s", c1, c2),
c1 = pairs[[1L]], c2 = pairs[[2L]], SIMPLIFY = FALSE, USE.NAMES = FALSE)))

}
Expand Down
6 changes: 3 additions & 3 deletions R/switch.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ do_ <- function() {
if (is.null(instruments)) {
server <- if (missing(server)) server_type 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/accounts/", do_$getAccount(server = server, apikey = apikey),
"/instruments")
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))
Expand Down

0 comments on commit af3afaf

Please sign in to comment.