feat(data): expose CandleReader (CSV) natively in all 10 languages (#311)

Add the data-layer CSV candle reader to every binding so loading OHLCV
candles from a CSV no longer needs a per-language CSV/dataframe dependency.

- C ABI: wickra_candle_reader_new(bytes, len) / _count / _read / _free over
  an opaque CandleReader handle (parse the whole buffer up front, then drain).
- Native: Node/WASM CandleReader.read() -> Candle[], Python read() -> list[tuple].
- C-ABI languages: Go Read() []Candle, C# Candle[] Read(), Java Candle[] read(),
  R read() S3 generic (n x 6 matrix); C / C++ call the C ABI directly.
- Cross-language golden testdata/golden/data_csv*.csv pins the parsed candles
  bit-for-bit across every binding.

Verified locally across Rust (test+clippy+fmt), Node, WASM, Python, C#, Go,
Java, R, and the C/C++ cmake parity suite.
This commit is contained in:
kingchenc
2026-06-16 00:10:58 +02:00
committed by GitHub
parent cb6da4d737
commit d362ae26a3
31 changed files with 867 additions and 6 deletions
+27
View File
@@ -22000,3 +22000,30 @@ impl ResamplerNode {
.map(candle_to_value))
}
}
// ===== Data layer: CSV candle reader =====
/// Parse OHLCV candles from a CSV string (header `timestamp,open,high,low,close,
/// volume`; a leading UTF-8 BOM is stripped).
#[napi(js_name = "CandleReader")]
pub struct CandleReaderNode {
candles: Vec<wc::Candle>,
}
#[napi]
impl CandleReaderNode {
/// Parse the whole CSV up front; throws on a malformed header or row.
#[napi(constructor)]
pub fn new(csv: String) -> napi::Result<Self> {
let mut reader =
wickra_data::csv::CandleReader::from_reader(csv.as_bytes()).map_err(map_data_err)?;
let candles = reader.read_all().map_err(map_data_err)?;
Ok(Self { candles })
}
/// Return every parsed candle as `{ open, high, low, close, volume, timestamp }`.
#[napi]
pub fn read(&self) -> Vec<CandleValue> {
self.candles.iter().map(|&c| candle_to_value(c)).collect()
}
}