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
@@ -26580,6 +26580,50 @@ public sealed class RenkoTrailingStop : IDisposable
public void Dispose() => _handle.Dispose();
}
public sealed class Resampler : IDisposable
{
private readonly WickraHandle _handle;
public Resampler(long timeframe)
{
var ptr = NativeMethods.wickra_resampler_new(timeframe);
if (ptr == nint.Zero)
{
throw new ArgumentException("invalid Resampler parameters");
}
_handle = new WickraHandle(ptr, NativeMethods.wickra_resampler_free);
}
public Candle? Update(double open, double high, double low, double close, double volume, long timestamp)
{
WickraCandle native;
bool ok;
unsafe
{
ok = NativeMethods.wickra_resampler_update(_handle.DangerousGetHandle(), open, high, low, close, volume, timestamp, &native);
}
GC.KeepAlive(_handle);
return ok ? new Candle(native.open, native.high, native.low, native.close, native.volume, native.timestamp) : null;
}
/// <summary>Emit the final, still-open candle (null if none is pending).</summary>
public Candle? Flush()
{
WickraCandle native;
bool ok;
unsafe
{
ok = NativeMethods.wickra_resampler_flush(_handle.DangerousGetHandle(), &native);
}
GC.KeepAlive(_handle);
return ok ? new Candle(native.open, native.high, native.low, native.close, native.volume, native.timestamp) : null;
}
public void Dispose() => _handle.Dispose();
}
public sealed class RickshawMan : IDisposable
{
private readonly WickraHandle _handle;
@@ -12416,6 +12416,20 @@ internal static partial class NativeMethods
[LibraryImport(WickraNative.LibraryName)]
internal static partial void wickra_tick_aggregator_free(nint handle);
[LibraryImport(WickraNative.LibraryName)]
internal static partial nint wickra_resampler_new(long timeframe);
[LibraryImport(WickraNative.LibraryName)]
[return: MarshalAs(UnmanagedType.U1)]
internal static unsafe partial bool wickra_resampler_update(nint handle, double open, double high, double low, double close, double volume, long timestamp, WickraCandle* @out);
[LibraryImport(WickraNative.LibraryName)]
[return: MarshalAs(UnmanagedType.U1)]
internal static unsafe partial bool wickra_resampler_flush(nint handle, WickraCandle* @out);
[LibraryImport(WickraNative.LibraryName)]
internal static partial void wickra_resampler_free(nint handle);
}
[StructLayout(LayoutKind.Sequential)]