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:
@@ -28287,6 +28287,7 @@ fn _wickra(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<PyCompositeProfile>()?;
|
||||
// Data layer.
|
||||
m.add_class::<PyTickAggregator>()?;
|
||||
m.add_class::<PyResampler>()?;
|
||||
// Candlestick patterns.
|
||||
m.add_class::<PyDoji>()?;
|
||||
m.add_class::<PyHammer>()?;
|
||||
@@ -28616,3 +28617,52 @@ impl PyTickAggregator {
|
||||
format!("TickAggregator(fills_gaps={})", self.inner.fills_gaps())
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Data layer: resampling (candle -> higher-timeframe candle) =====
|
||||
|
||||
/// Resample candles into a higher timeframe (e.g. 1m -> 5m).
|
||||
#[pyclass(name = "Resampler", module = "wickra._wickra", skip_from_py_object)]
|
||||
#[derive(Clone)]
|
||||
struct PyResampler {
|
||||
inner: wickra_data::resample::Resampler,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyResampler {
|
||||
#[new]
|
||||
fn new(timeframe: i64) -> PyResult<Self> {
|
||||
let tf = wickra_data::aggregator::Timeframe::new(timeframe).map_err(map_data_err)?;
|
||||
Ok(Self {
|
||||
inner: wickra_data::resample::Resampler::new(tf),
|
||||
})
|
||||
}
|
||||
|
||||
/// Push one candle; returns the completed higher-timeframe candle as
|
||||
/// `(open, high, low, close, volume, timestamp)` on a bucket boundary, else
|
||||
/// `None`.
|
||||
fn update(
|
||||
&mut self,
|
||||
open: f64,
|
||||
high: f64,
|
||||
low: f64,
|
||||
close: f64,
|
||||
volume: f64,
|
||||
timestamp: i64,
|
||||
) -> PyResult<Option<CandleTuple>> {
|
||||
let candle = wc::Candle::new(open, high, low, close, volume, timestamp).map_err(map_err)?;
|
||||
Ok(self
|
||||
.inner
|
||||
.push(candle)
|
||||
.map_err(map_data_err)?
|
||||
.map(|c| (c.open, c.high, c.low, c.close, c.volume, c.timestamp)))
|
||||
}
|
||||
|
||||
/// Emit the final, still-open candle (or `None` if none is pending).
|
||||
fn flush(&mut self) -> PyResult<Option<CandleTuple>> {
|
||||
Ok(self
|
||||
.inner
|
||||
.flush()
|
||||
.map_err(map_data_err)?
|
||||
.map(|c| (c.open, c.high, c.low, c.close, c.volume, c.timestamp)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user