feat(data-layer): TickAggregator (tick-to-candle) in all 10 languages (#309)
* feat(data-layer): TickAggregator in Node, WASM, Python + C ABI hub First data-layer feature (F2): roll trade ticks up into fixed-timeframe OHLCV candles, exposed natively and over the C ABI. - wickra-data wired as a binding dependency (workspace dep; its wickra-core dep is default-features=false so it never forces rayon into the rayon-free WASM build — native bindings re-enable parallel through their own dependency). - Node `TickAggregator(bucket, gapFill?)` -> `push(price, size, ts): Candle[]`; WASM the same (array of objects); Python `push(...) -> list[tuple]`. - C ABI: `WickraCandle` struct + `wickra_tick_aggregator_new/push/free` (push writes candles into a caller buffer and returns the count), generated via the capi generator's new DATA_LAYER section; cbindgen now parses wickra-data so `TickAggregator` is a forward-declared opaque; header vendored to bindings/go. Verified bit-identical across Node/WASM/Python/C/C++ (o=100 h=101 l=100 c=101 v=3 ts=0 for the shared 3-tick probe). WIP: Go/C#/Java/R generated bindings and the cross-language golden are still pending. * feat(data-layer): TickAggregator in Go, C#, Java, R (lossless push/drain) Complete F2 across all 10 languages: the C-ABI tick aggregator now uses a two-step push/drain so gap-fill candles are never lost, and the four generated bindings expose it idiomatically. - C ABI redesigned: opaque TickAggregator handle (inner aggregator + pending buffer); push consumes a tick and returns the closed-candle count, drain copies them into a count-sized caller buffer. - Go: NewTickAggregator + Push(price,size,ts) []Candle; C#: TickAggregator + Candle[] Push(...); Java: TickAggregator + Candle[] push(...); R: TickAggregator constructor + push() S3 generic returning an (n x 6) numeric matrix. - Candle output record generated per language from WickraCandle. Verified bit-identical to the native bindings (o=100 h=101 l=100 c=101 v=3 ts=0) in Go, C#, Java, and R at runtime; R passes R CMD check (pre-existing doc warnings only). WIP: cross-language data-layer golden + CHANGELOG still pending. * test(data-layer): cross-language golden for the tick aggregator + CHANGELOG gen_golden emits a deterministic tick stream (testdata/golden/data_ticks.csv) and the reference candle streams with and without gap filling (data_candles.csv, data_candles_gap.csv). Every binding replays the shared ticks through its TickAggregator and checks the candles bit-for-bit (fp tolerance) against the Rust reference: - Node / WASM / Python / Go / C# / Java / R: a dedicated parity test each. - C / C++: data_layer_test.c (compiled as both, run as ctest). The gap-fill fixture closes several candles from a single push, exercising the lossless push/drain path. Records the feature under CHANGELOG [Unreleased]. * fix(examples): rename the CSV-loader candle to WickraBar The example CSV helper (wickra_csv.h) defined its own struct WickraCandle, which now collides with the public C ABI WickraCandle (the tick aggregator output) in any example that includes both headers (backtest, multi_timeframe, the strategy examples). The public type owns the name; rename the example loader's bar to WickraBar. The generated golden_test.c is untouched (its only match was the unrelated WickraCandleVolumeOutput).
This commit is contained in:
@@ -18965,6 +18965,38 @@ SEXP wk_thrusting_reset(SEXP e) {
|
||||
return R_NilValue;
|
||||
}
|
||||
|
||||
static void tick_aggregator_fin(SEXP e) {
|
||||
struct TickAggregator *h = (struct TickAggregator *)R_ExternalPtrAddr(e);
|
||||
if (h) wickra_tick_aggregator_free(h);
|
||||
R_ClearExternalPtr(e);
|
||||
}
|
||||
SEXP wk_tick_aggregator_new(SEXP a0, SEXP a1) {
|
||||
struct TickAggregator *h = wickra_tick_aggregator_new((int64_t)Rf_asReal(a0), (bool)(Rf_asLogical(a1) == TRUE));
|
||||
if (!h) Rf_error("invalid TickAggregator parameters");
|
||||
SEXP e = PROTECT(R_MakeExternalPtr(h, R_NilValue, R_NilValue));
|
||||
R_RegisterCFinalizerEx(e, tick_aggregator_fin, TRUE);
|
||||
UNPROTECT(1);
|
||||
return e;
|
||||
}
|
||||
SEXP wk_tick_aggregator_push(SEXP e, SEXP price, SEXP size, SEXP ts) {
|
||||
struct TickAggregator *h = (struct TickAggregator *)R_ExternalPtrAddr(e);
|
||||
intptr_t n = wickra_tick_aggregator_push(h, Rf_asReal(price), Rf_asReal(size), (int64_t)Rf_asReal(ts));
|
||||
if (n <= 0) return Rf_allocMatrix(REALSXP, 0, 6);
|
||||
struct WickraCandle *buf = (struct WickraCandle *)R_alloc(n, sizeof(struct WickraCandle));
|
||||
intptr_t w = wickra_tick_aggregator_drain(h, buf, (uintptr_t)n);
|
||||
SEXP r = PROTECT(Rf_allocMatrix(REALSXP, (int)w, 6));
|
||||
for (intptr_t i = 0; i < w; i++) {
|
||||
REAL(r)[i + w * 0] = buf[i].open;
|
||||
REAL(r)[i + w * 1] = buf[i].high;
|
||||
REAL(r)[i + w * 2] = buf[i].low;
|
||||
REAL(r)[i + w * 3] = buf[i].close;
|
||||
REAL(r)[i + w * 4] = buf[i].volume;
|
||||
REAL(r)[i + w * 5] = (double)buf[i].timestamp;
|
||||
}
|
||||
UNPROTECT(1);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void tick_bars_fin(SEXP e) {
|
||||
struct TickBars *h = (struct TickBars *)R_ExternalPtrAddr(e);
|
||||
if (h) wickra_tick_bars_free(h);
|
||||
@@ -25418,6 +25450,8 @@ static const R_CallMethodDef CallEntries[] = {
|
||||
{"wk_thrusting_is_ready", (DL_FUNC)&wk_thrusting_is_ready, 1},
|
||||
{"wk_thrusting_name", (DL_FUNC)&wk_thrusting_name, 1},
|
||||
{"wk_thrusting_reset", (DL_FUNC)&wk_thrusting_reset, 1},
|
||||
{"wk_tick_aggregator_new", (DL_FUNC)&wk_tick_aggregator_new, 2},
|
||||
{"wk_tick_aggregator_push", (DL_FUNC)&wk_tick_aggregator_push, 4},
|
||||
{"wk_tick_bars_new", (DL_FUNC)&wk_tick_bars_new, 1},
|
||||
{"wk_tick_bars_update", (DL_FUNC)&wk_tick_bars_update, 7},
|
||||
{"wk_tick_bars_name", (DL_FUNC)&wk_tick_bars_name, 1},
|
||||
|
||||
Reference in New Issue
Block a user