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:
@@ -28057,6 +28057,56 @@ func (ind *RenkoTrailingStop) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
// Resampler wraps the Resampler indicator over the Wickra C ABI.
|
||||
type Resampler struct {
|
||||
handle *C.struct_Resampler
|
||||
}
|
||||
|
||||
// NewResampler constructs a Resampler. It returns ErrInvalidParams when the
|
||||
// native constructor rejects the arguments.
|
||||
func NewResampler(timeframe int64) (*Resampler, error) {
|
||||
ptr := C.wickra_resampler_new(C.int64_t(timeframe))
|
||||
if ptr == nil {
|
||||
return nil, ErrInvalidParams
|
||||
}
|
||||
obj := &Resampler{handle: ptr}
|
||||
runtime.SetFinalizer(obj, (*Resampler).Close)
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
// Update feeds one observation. The bool reports whether a value is
|
||||
// available yet (false during warmup).
|
||||
func (ind *Resampler) Update(open float64, high float64, low float64, close float64, volume float64, timestamp int64) (Candle, bool) {
|
||||
var out C.struct_WickraCandle
|
||||
ok := bool(C.wickra_resampler_update(ind.handle, C.double(open), C.double(high), C.double(low), C.double(close), C.double(volume), C.int64_t(timestamp), &out))
|
||||
runtime.KeepAlive(ind)
|
||||
if !ok {
|
||||
return Candle{}, false
|
||||
}
|
||||
return Candle{float64(out.open), float64(out.high), float64(out.low), float64(out.close), float64(out.volume), int64(out.timestamp)}, true
|
||||
}
|
||||
|
||||
// Flush emits the final, still-open candle (ok is false if none is pending).
|
||||
func (ind *Resampler) Flush() (Candle, bool) {
|
||||
var out C.struct_WickraCandle
|
||||
ok := bool(C.wickra_resampler_flush(ind.handle, &out))
|
||||
runtime.KeepAlive(ind)
|
||||
if !ok {
|
||||
return Candle{}, false
|
||||
}
|
||||
return Candle{float64(out.open), float64(out.high), float64(out.low), float64(out.close), float64(out.volume), int64(out.timestamp)}, true
|
||||
}
|
||||
|
||||
// Close frees the native handle. It is idempotent and safe to call
|
||||
// alongside the finalizer.
|
||||
func (ind *Resampler) Close() {
|
||||
if ind.handle != nil {
|
||||
C.wickra_resampler_free(ind.handle)
|
||||
ind.handle = nil
|
||||
runtime.SetFinalizer(ind, nil)
|
||||
}
|
||||
}
|
||||
|
||||
// RickshawMan wraps the RickshawMan indicator over the Wickra C ABI.
|
||||
type RickshawMan struct {
|
||||
handle *C.struct_RickshawMan
|
||||
|
||||
Reference in New Issue
Block a user