Files
wickra/examples/README.md
T
kingchenc 21c86f348f examples + bindings: Node/WASM strategy parity + test/benchmark parity (P2 + P3) (#81)
* examples(node): add RSI mean-reversion strategy

Node counterpart of strategy_rsi_mean_reversion.{py,rs}: RSI(14) < 30 long,
> 70 exit, 0.1% fees, hourly BTCUSDT. Output verified byte-identical to the
Rust reference (37 trades W24/L13, -17.84% return, 46.89% max drawdown).

* examples(node): add MACD + ADX trend-filter strategy

Node counterpart of strategy_macd_adx.{py,rs}: MACD(12,26,9) histogram
crossover entries gated by ADX(14) > 20, hourly BTCUSDT, 0.1% fees. Output
verified byte-identical to the Rust reference (246 trades W90/L156, -47.19%
return, 53.75% max drawdown).

* examples(node): add Bollinger-squeeze breakout strategy

Node counterpart of strategy_bollinger_squeeze.{py,rs}: enter on a fresh
180-bar Bollinger-bandwidth low + close above the upper band, exit on a
2*ATR(14) stop or upper-band collapse, daily BTCUSDT, 0.1% fees. Output
verified byte-identical to the Rust reference (1 trade, -7.82% return,
13.01% max drawdown).

* examples(wasm): add RSI mean-reversion strategy demo

Browser counterpart of strategy_rsi_mean_reversion.{py,js,rs}: RSI(14) < 30
long, > 70 exit, 0.1% fees, summary table. Same signal/fill/PnL/equity loop as
the runtime-verified Node example; loads via the established wickra_wasm.js
init + fetch-CSV pattern. (wasm32 build runs in CI.)

* examples(wasm): add MACD + ADX trend-filter strategy demo

Browser counterpart of strategy_macd_adx.{py,js,rs}: MACD(12,26,9) histogram
crossover gated by ADX(14) > 20, hourly BTCUSDT, 0.1% fees. Logic identical to
the runtime-verified Node example; standard wickra_wasm.js init + fetch-CSV
loader. (wasm32 build runs in CI.)

* examples(wasm): add Bollinger-squeeze breakout strategy demo

Browser counterpart of strategy_bollinger_squeeze.{py,js,rs}: fresh 180-bar
Bollinger-bandwidth low + upper-band breakout, 2*ATR(14) stop, daily BTCUSDT,
0.1% fees. Logic identical to the runtime-verified Node example; standard
wickra_wasm.js init + fetch-CSV loader. (wasm32 build runs in CI.)

* ci: add examples syntax-smoke job (P2.3)

The Rust examples are built by 'cargo build -p wickra-examples --bins'; the
Node, browser-WASM and Python examples had no build gate. New job parse-checks
every examples/{node,wasm}/*.js, extracts and node --checks each WASM .html
module script, and python -m py_compile's every examples/python/*.py — so a
broken example edit fails CI instead of landing silently.

* docs(examples): list the new Node + WASM strategy examples

Add the three Node strategy scripts and three WASM strategy demos to the
examples README tables, bringing Node and WASM to parity with the existing
Rust and Python strategy rows.

* chore(examples): refresh examples/node lockfile for the linked wickra binding

npm install rewrote the file: dependency snapshot of the local wickra binding
that the examples link against (version 0.1.4 -> 0.3.1, license + engines
fields), which had gone stale in the committed lockfile.

* test(node): add input-validation suite

Node counterpart of bindings/python/tests/test_input_validation.py: invalid
constructor parameters (ATR zero period, MACD non-increasing fast/slow,
BollingerBands negative multiplier, PSAR step > max, ValueArea period/pct,
InitialBalance/OpeningRange zero period, Ichimoku non-increasing periods,
Ehlers-family ordering) and unequal-length candle/ValueArea batch inputs all
throw a JS Error. Validated against the built binding.

* test(node): add indicator completeness contract

Introspects every exported indicator class and asserts the full interface
(update / batch / reset / isReady / warmupPeriod) plus the pre-warmup contract
for zero-arg indicators, and guards that the full catalogue (>= 200 classes)
is exported. Catches a new indicator wired without the standard methods, or a
stale/partial native build dropping exports, with no per-indicator boilerplate.

* test(wasm): broaden scalar streaming-vs-batch coverage

Extend the inline wasm-bindgen-test suite with a streaming==batch check across
~70 scalar indicators spanning moving averages, momentum, volatility,
statistics/regression, Ehlers/cycle and risk/performance families (previously
only EMA + the candle-input group were covered per-indicator), plus four more
invalid-constructor assertions. Constructor args mirror the CI-passing Node
factories. Host-compiles (cargo test -p wickra-wasm --no-run); executed in CI
via wasm-pack test --node.

* bench(node): add indicator throughput benchmark

Node counterpart of the Rust criterion benches / Python compare_libraries:
measures streaming (per-tick update) and batch throughput in Mupd/s across a
representative indicator set over a synthetic OHLCV series (--bars, default
200k). Dependency-free; wired as 'npm run bench'.

* docs(wasm): list strategy demos + document the benchmark story

Add the three new strategy demos to the WASM examples table and a Performance
section: parallel_assets.html is the in-browser benchmark, with raw throughput
covered by the Rust criterion / Python / Node benchmarks (the WASM engine is the
same core compiled to wasm32).
2026-05-31 05:09:26 +02:00

6.8 KiB
Raw Blame History

Wickra examples

Runnable examples for every Wickra binding. Rust and Node examples live next to the code they exercise so the language tooling (cargo run --example, node) can find them; the Python examples have no crate of their own and live here under python/.

Rust — examples/rust/

The Rust examples live in the wickra-examples workspace member crate.

Example What it does Run
streaming.rs Feed a synthetic price series through SMA / EMA / RSI / MACD tick by tick. cargo run -p wickra-examples --bin streaming
backtest.rs Compute a basket of indicators over an OHLCV CSV and print a summary. cargo run -p wickra-examples --bin backtest -- <ohlcv.csv>
multi_timeframe.rs Resample a 1-minute CSV via wickra-data and print indicators per timeframe. cargo run -p wickra-examples --bin multi_timeframe
parallel_assets.rs Serial vs BatchExt::batch_parallel (rayon) over a synthetic panel, with speedup. cargo run --release -p wickra-examples --bin parallel_assets -- --assets 200 --bars 5000
fetch_btcusdt.rs Download real BTCUSDT klines from the Binance REST API into examples/data/. cargo run -p wickra-examples --bin fetch_btcusdt
live_binance.rs Stream live Binance klines through an indicator over a resilient WebSocket. cargo run -p wickra-examples --bin live_binance
strategy_rsi_mean_reversion.rs Hourly BTCUSDT mean-reversion using RSI(14) thresholds, with PnL / Sharpe / max-DD summary. cargo run --release -p wickra-examples --bin strategy_rsi_mean_reversion
strategy_macd_adx.rs Hourly BTCUSDT trend-follower: MACD crossover entries gated by ADX(14) > 20. cargo run --release -p wickra-examples --bin strategy_macd_adx
strategy_bollinger_squeeze.rs Daily BTCUSDT Bollinger-squeeze breakout with ATR(14) trailing stop. cargo run --release -p wickra-examples --bin strategy_bollinger_squeeze

Python — examples/python/

Example What it does Run
streaming.py Feed a synthetic price series through SMA / EMA / RSI / MACD tick by tick. python -m examples.python.streaming
backtest.py Basket of indicators over an OHLCV CSV. python -m examples.python.backtest <ohlcv.csv>
live_trading.py Live Binance feed → RSI / MACD / Bollinger → signals. python -m examples.python.live_trading --symbol BTCUSDT --interval 1m
multi_timeframe.py Resample a 1-minute CSV to coarser timeframes and compare. python -m examples.python.multi_timeframe <1m.csv>
parallel_assets.py Process many symbols in parallel — the Rust extension releases the GIL during batch computation. python -m examples.python.parallel_assets --assets 200 --bars 5000
fetch_btcusdt.py Download real BTCUSDT klines from the Binance REST API into examples/data/ (urllib + stdlib only). python -m examples.python.fetch_btcusdt
strategy_rsi_mean_reversion.py Hourly BTCUSDT mean-reversion using RSI(14) thresholds, with PnL / Sharpe / max-DD summary. python -m examples.python.strategy_rsi_mean_reversion
strategy_macd_adx.py Hourly BTCUSDT trend-follower: MACD crossover entries gated by ADX(14) > 20. python -m examples.python.strategy_macd_adx
strategy_bollinger_squeeze.py Daily BTCUSDT Bollinger-squeeze breakout with ATR(14) trailing stop. python -m examples.python.strategy_bollinger_squeeze

live_trading.py additionally needs pip install websockets.

Node.js — examples/node/

Build the native binding once, then link it into the examples directory:

cd bindings/node && npm install && npx napi build --platform --release
cd ../../examples/node && npm install        # links wickra + installs `ws`
Example What it does Run
streaming.js Feed a synthetic price series through several indicators tick by tick. node streaming.js
backtest.js Basket of indicators over an OHLCV CSV; defaults to the bundled BTCUSDT daily dataset. node backtest.js [ohlcv.csv]
multi_timeframe.js Roll a 1-minute CSV up to 5m / 15m / 1h / 4h / 1d and print indicators per timeframe. node multi_timeframe.js [path/to/1m.csv]
parallel_assets.js Serial vs worker_threads pool over a synthetic panel, with speedup. node parallel_assets.js --assets 200 --bars 5000
live_trading.js Live Binance feed → RSI / MACD / Bollinger → signals. node live_trading.js --symbol BTCUSDT --interval 1m
fetch_btcusdt.js Download real BTCUSDT klines from the Binance REST API into examples/data/ (built-in fetch, Node 18+). node fetch_btcusdt.js
strategy_rsi_mean_reversion.js Hourly BTCUSDT mean-reversion using RSI(14) thresholds, with PnL / Sharpe / max-DD summary. node strategy_rsi_mean_reversion.js
strategy_macd_adx.js Hourly BTCUSDT trend-follower: MACD crossover entries gated by ADX(14) > 20. node strategy_macd_adx.js
strategy_bollinger_squeeze.js Daily BTCUSDT Bollinger-squeeze breakout with ATR(14) trailing stop. node strategy_bollinger_squeeze.js

WebAssembly — examples/wasm/

Build the WASM module first (one-time):

wasm-pack build bindings/wasm --target web --release --features panic-hook

Then serve the repository root (python -m http.server, npx http-server, …) and open the demo you want in a browser.

Example What it does
index.html Streams a synthetic price series through six indicators and draws a live <canvas> chart.
backtest.html Streams a fetched OHLCV CSV through a basket of indicators (SMA, EMA, RSI, MACD, Bollinger, ATR, ADX, OBV) and prints a per-series summary table.
live_trading.html Opens a browser-native WebSocket to Binance, runs RSI / MACD / Bollinger and flags BUY/SELL candidates.
multi_timeframe.html Fetches a 1-minute CSV, rolls it up to 5m / 15m / 1h / 4h / 1d in-page, prints RSI / MACD hist / ADX per timeframe.
parallel_assets.html Spawns a pool of module Workers (each loading its own copy of the WASM module) and reports the speedup over a serial baseline.
strategy_rsi_mean_reversion.html Hourly BTCUSDT RSI(14) mean-reversion (long < 30, exit > 70); prints a PnL / Sharpe / max-DD summary table.
strategy_macd_adx.html Hourly BTCUSDT MACD crossover gated by ADX(14) > 20, with the same summary table.
strategy_bollinger_squeeze.html Daily BTCUSDT Bollinger-squeeze breakout with a 2×ATR(14) stop and summary table.

Example datasets

examples/data/ holds seven real BTCUSDT OHLCV datasets, one per timeframe (1m, 5m, 15m, 1h, 12h, 1d, 1month), in the standard timestamp,open,high,low,close,volume layout. The Rust and Node backtest examples and the indicator benchmarks run against them. Regenerate them with the latest market history via cargo run -p wickra-examples --bin fetch_btcusdt.