Skip to main content

Crate wickra_backtest_data

Crate wickra_backtest_data 

Source
Expand description

§wickra-backtest-data

Loaders that turn market-history files into the Candle stream the wickra_backtest_core engine consumes. CSV (time,open,high,low,close[,volume]), JSON Lines (one Candle object per line) and a JSON array are supported, dispatched by file extension; Apache Parquet is supported behind the parquet feature. Candles can also be resampled to a coarser timeframe by a fixed bar count or a timestamp interval.

Functions§

fetch_klinesbinance
Fetch historical candles from the Binance REST API (GET /api/v3/klines). interval is a Binance interval such as 1m, 1h or 1d; limit is the number of bars (Binance caps this at 1000). Requires the binance feature.
load_candles
Load candles from a file, choosing the parser by extension (.jsonl/.ndjson → JSON Lines, .json → JSON array, .parquet → Parquet when the parquet feature is on, anything else → CSV).
load_parquetparquet
Load candles from an Apache Parquet file with columns time, open, high, low, close[, volume] (matched case-insensitively). Integer or floating-point columns are both accepted.
parse_binance_klines
Parse a Binance GET /api/v3/klines response (a JSON array of kline arrays) into candles. Each kline is [openTime_ms, "open", "high", "low", "close", "volume", …] where the OHLCV fields are JSON strings; the open time is milliseconds since epoch and is converted to seconds. This is always available (no HTTP dependency) so the parser can be tested offline.
parse_csv
Parse CSV with columns time,open,high,low,close[,volume]. A non-numeric first row is treated as a header and skipped.
parse_json_array
Parse a JSON array of Candle objects.
parse_jsonl
Parse JSON Lines: one Candle object per non-empty line.
resample_by_count
Resample candles into fixed groups of count (e.g. five 1-minute bars into one 5-minute bar). A trailing partial group is aggregated as-is. count must be non-zero.
resample_by_interval
Resample candles by a timestamp interval: candles whose time falls in the same floor(time / interval) bucket are aggregated, and the bucket adopts the floored start time. Input must be time-ordered; interval must be non-zero.
to_kagi
Transform candles into Kagi segments (wickra-core’s KagiBars, fixed reversal amount on closes), each emitted as a synthetic candle (open = segment start, close = segment end). reversal must be positive.
to_pnf
Transform candles into Point-and-Figure columns (wickra-core’s PointAndFigureBars, fixed box_size and N-box reversal on closes), each emitted as a synthetic candle. A rising (X) column opens at its low and closes at its high; a falling (O) column opens high and closes low. box_size must be positive and reversal non-zero.
to_renko
Transform candles into Renko bricks (wickra-core’s RenkoBars, fixed box_size on closes), each emitted as a synthetic candle (open/close = the brick edges, sequential timestamps). Backtest a strategy on price-driven Renko bars instead of time bars. box_size must be positive.