feat(data-layer): Resampler (candle resampling) in all 10 languages (#310)

* feat(data-layer): Resampler (candle resampling) in all 10 languages

Second data-layer feature (F3): resample candles into a higher timeframe.

- Native (Node.js/WASM): new Resampler(timeframe) -> update(o,h,l,c,v,ts):
  Candle|null + flush(): Candle|null. Python the same -> tuple|None.
- C ABI: wickra_resampler_new/update/flush/free (update has the multi-output
  shape so the generators auto-emit it; flush is bespoke). Go Update -> (Candle,
  bool) + Flush; C# Candle? Update/Flush; Java Candle update/flush; R update()
  generic + a flush() S3 method (extends base::flush); C/C++ direct.
- Cross-language golden (testdata/golden/data_resampled.csv): the shared input
  candles resampled into 5-unit buckets, the final partial bucket via flush,
  pinned bit-for-bit across every binding.

Verified locally in all 10 (3 candles for the 5-unit smoke; 16 for the golden).
The WickraCandle output record is shared with the tick aggregator (deduped).

* test(node): exclude data-layer types from the indicator completeness contract

The Resampler exposes update(), so the completeness test flagged it as an
indicator and required batch/reset/isReady/warmupPeriod, which a data-layer type
does not have. Exclude TickAggregator and Resampler like the bar builders.
This commit is contained in:
kingchenc
2026-06-15 22:36:16 +02:00
committed by GitHub
parent 8a103ef920
commit cb6da4d737
30 changed files with 901 additions and 4 deletions
+19
View File
@@ -170,3 +170,22 @@ push.wickra_indicator <- function(object, price, size, timestamp) {
colnames(out) <- c("open", "high", "low", "close", "volume", "timestamp")
out
}
#' Flush a resampler's final candle
#'
#' Emit the final, still-open candle a [Resampler()] is aggregating (the partial
#' higher-timeframe bar that no later input has closed yet). Extends the base
#' generic [base::flush()].
#'
#' @param con A `wickra_indicator` created by [Resampler()].
#' @return A named numeric vector (`open`, `high`, `low`, `close`, `volume`,
#' `timestamp`), or `NULL` if nothing is pending.
#' @examples
#' r <- Resampler(5)
#' for (t in 0:6) update(r, 100 + t, 101 + t, 99 + t, 100 + t, 10, t)
#' flush(r)
#' @exportS3Method base::flush
flush.wickra_indicator <- function(con) {
out <- .Call(paste0("wk_", con$prefix, "_flush"), con$ptr, PACKAGE = "wickra")
out
}