wickra-terminal-wasm
v0.2.0
Published
WebAssembly bindings for wickra-terminal — the data-driven core in the browser, feeding the web renderer.
Readme
Wickra Terminal — WASM
▶ Live demo: the Wickra library's own 514 indicators over real Binance market data, computed live in your browser — live.wickra.org · zero backend, powered by
wickra-wasm.
One core. Ten languages. Two renderers — for WASM. npm install wickra-terminal-wasm — pure WebAssembly, runs anywhere a modern JS engine does.
WebAssembly bindings for the wickra-terminal data-driven core, built
with wasm-bindgen. This is the binding the web renderer runs on: build a
Terminal from a JSON config, drive it with command JSON, read back frame
view-models — the same protocol as the native TUI and every other binding.
The native exchange client cannot run in a browser sandbox, so the core's live
feature is disabled here. The web renderer opens its own WebSocket and hands the
events in through the Feed command, which is why Feed matters more to this
binding than to any other.
Install
npm install wickra-terminal-wasmRequirements
wasm-packand thewasm32-unknown-unknowntarget- A bundler or an ES-module-capable browser for the
webtarget
Building from this repository (contributors)
Build.
wasm-pack build bindings/wasm --target web # for the browser
wasm-pack build bindings/wasm --target nodejs --out-dir pkg-node # for the test suiteThe web target is what web/ imports; the nodejs
target is the only form require() can load, which is what the tests run against.
Test.
node --test bindings/wasm/tests/*.test.cjsQuick start
import init, { Terminal, version } from "wickra-terminal-wasm";
await init();
const term = new Terminal(JSON.stringify({
sources: [{ Synth: { seed: 1 } }],
layout: { panels: [{ kind: "Chart", rect: { x: 0, y: 0, w: 100, h: 100 } }] },
}));
term.command(JSON.stringify({ type: "Subscribe", source: 0, symbol: "BTC/USDT" }));
const frame = JSON.parse(term.command(JSON.stringify({ type: "Tick" })));
console.log(frame.panels[0], version());API
| Name | Returns |
|------|---------|
| new Terminal(configJson) | A handle; throws on an invalid config |
| term.command(cmdJson) | The frame JSON; throws on an invalid command |
| term.version() | The library version |
| version() | The same string, as a free function |
| term.free() | Releases the handle |
free() is not optional housekeeping: wasm-bindgen hands out a pointer with no
finaliser, so a terminal dropped without it leaks its linear-memory allocation
for the lifetime of the page. Anything that rebuilds a terminal — a config
change, a source swap — must release the old one.
The command protocol
Every binding drives the same nineteen commands, and the frame that comes back is the same JSON in all of them:
| Command | Effect |
|---------|--------|
| Tick | Poll every source, fold what arrived, return the frame |
| Subscribe / Unsubscribe | Add or drop a market on one source |
| SetFocus | Choose the market the panels render |
| AddSource / RemoveSource | Attach or detach a feed at run time |
| Seek | Rewind or fast-forward a replay source (the time machine) |
| Feed | Hand an event to a Manual source from the host |
| FeedDerivatives | Fold a derivatives update -- funding, open interest, positioning, mark/index/futures -- into a market |
| AddIndicator / RemoveIndicator | Track or drop an indicator on every market |
| SetTimeframe | Set the bar size the candle-input indicators are fed at |
| ListIndicators | The catalogue: every indicator, profile and bar type this build accepts, each with its default parameters |
| ReplayPosition | Where a replayable source stands, for a time-machine scrubber. Answers 0/0 for a source that is not a recording |
| ExportRecording / SetRecording | Save the recorded events in the shape Replay takes, and turn recording on or off |
| AddPanel / RemovePanel / MovePanel | Place a panel on the layout, take one off, or move and resize one -- the layout is no longer fixed at start-up |
ListIndicators is the one command that answers rather than renders, and each
row carries needs_reference, which marks the pairwise indicators that compare
two markets and so require a reference symbol in their spec. A row for one of
the two friendly aliases also carries alias_of naming the canonical kind it
builds, so Macd and MacdIndicator read as one indicator rather than two.
A frame is {"panels": [...]}, one entry per configured panel, each tagged with
its panel kind — chart, book, tape, watchlist, footprint, profile, bars. See
docs/ for the panel and source references.
Cross-language equality
The same config and the same command sequence produce a byte-identical frame in
Rust, Python, Node.js, WASM, C, C++, C#, Go, Java and R. That is not an aspiration:
golden/ holds a recorded feed and the expected frame,
and every binding's test suite asserts its own output against that one file.
Benchmark
benchmarks/ reports this binding's throughput over the shared core. It measures
the call overhead of wasm-bindgen, not a cross-library ratio (the same Rust core runs
under every binding) — see the repository
BENCHMARKS.md for the
numbers, the machine and how each harness is run.
Documentation
The full guide, the spec reference and the API documentation live in the main repository and the documentation site:
Repository: https://github.com/wickra-lib/wickra-terminal
Docs (guides, spec reference, cookbook): https://terminal.wickra.org
Runnable example:
examples/wasm/Repository: https://github.com/wickra-lib/wickra-terminal
Panels, sources, renderers, streaming:
docs/Cookbook:
docs/Cookbook.mdBuilt on Wickra: https://github.com/wickra-lib/wickra · https://docs.wickra.org
Wickra Terminal ships native bindings for Python, Node.js, WASM and Rust, plus a C ABI hub that any
C-capable language (C, C++, C#, Go, Java, R) links against — all forwarding to the
same data-driven, unsafe-forbidden Rust core.
Security
Found a security issue? Please don't open a public issue. Report it privately
via the repository's Security tab ("Report a vulnerability") or email
[email protected] with a subject line starting [wickra security]. Full
policy: https://github.com/wickra-lib/wickra-terminal/blob/main/SECURITY.md.
Disclaimer
This software is provided "as is", without warranty of any kind. It is a research and engineering tool, not financial advice. Trading carries risk of loss. Run in paper mode and against exchange testnets, and review the code before risking real capital.
License
Licensed under either of Apache-2.0 or MIT at your option.
