Files
wickra/examples/wasm
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
..

Wickra WASM examples

Browser demos for the wickra-wasm WebAssembly binding. Every demo loads the module the same way (init() then construct indicators) so the patterns transfer one-to-one to your own page.

Build

The WASM module ships as a wasm-pack --target web bundle. Build it once from the repository root:

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

This drops bindings/wasm/pkg/ with the .wasm binary, the JS loader and TypeScript types. Every demo here imports the loader via ../../bindings/wasm/pkg/wickra_wasm.js.

Serve

ES-module workers and fetch() over CSV both need a real HTTP origin, not file://. Any static server from the repository root works:

# Python:
python -m http.server 8000

# Or Node:
npx http-server -p 8000

Then open the demo you want at http://localhost:8000/examples/wasm/<file>.

Demos

File What it does
index.html The original showcase: streams a synthetic price series through six indicators and draws a live <canvas> chart with SMA, EMA, RSI, MACD, BollingerBands and ATR cards.
backtest.html Backtest: fetches an OHLCV CSV (default the bundled BTCUSDT daily dataset), streams every candle through a basket of eight indicators, prints a summary table. Mirrors examples/python/backtest.py.
live_trading.html Browser-native WebSocket to Binance kline streams; runs RSI / MACD / Bollinger on the incoming closes and flags BUY/SELL candidates when the three agree. Mirrors examples/python/live_trading.py.
multi_timeframe.html Fetches a 1-minute CSV, rolls it up in-page to 5m / 15m / 1h / 4h / 1d buckets and prints RSI / MACD-histogram / ADX per timeframe. Mirrors examples/python/multi_timeframe.py.
parallel_assets.html Synthetic (assets, bars) panel, serial baseline on the main thread vs. a pool of module Workers each loading its own copy of the WASM module. Mirrors examples/python/parallel_assets.py.
parallel_worker.js Module worker used by parallel_assets.html (not loaded directly).
strategy_rsi_mean_reversion.html RSI(14) mean-reversion (long < 30, exit > 70), 0.1% fees, summary table. Mirrors examples/python/strategy_rsi_mean_reversion.py.
strategy_macd_adx.html MACD(12,26,9) crossover gated by ADX(14) > 20, summary table. Mirrors examples/python/strategy_macd_adx.py.
strategy_bollinger_squeeze.html Bollinger-squeeze breakout with a 2×ATR(14) stop, summary table. Mirrors examples/python/strategy_bollinger_squeeze.py.

Performance

The in-browser benchmark is parallel_assets.html: it times a serial main-thread baseline against a pool of module Workers and reports the speedup. For raw single-thread throughput numbers see the sibling benchmarks — Rust criterion (crates/wickra/benches/), Python (bindings/python/benchmarks/compare_libraries.py) and Node (bindings/node/benchmarks/throughput.js, npm run bench). The WASM engine is the same Rust core compiled to wasm32, so its relative ordering of indicators tracks those.

See also

  • Quickstart: WASM — module-load flow, wasm-pack targets, and the streaming API.
  • examples/README.md — cross-language index, including the Rust, Python and Node siblings of every demo above.