@ruvector/neural-trader-wasm
v0.1.1
Published
WASM bindings for Neural Trader — market events, coherence gates, replay memory
Readme
@ruvector/neural-trader-wasm
WASM bindings for the Neural Trader crates — market events, coherence gates, and replay memory running in the browser.
Install
npm install @ruvector/neural-trader-wasmQuick Start
import init, {
GateConfigWasm,
ThresholdGateWasm,
GateContextWasm,
RegimeLabelWasm,
MarketEventWasm,
EventTypeWasm,
ReservoirStoreWasm,
version,
healthCheck,
} from '@ruvector/neural-trader-wasm';
await init();
console.log('version:', version()); // "0.1.0"
console.log('healthy:', healthCheck()); // true
// --- Coherence Gate ---
const config = new GateConfigWasm(); // sensible defaults
config.mincutFloorCalm = 12n;
const gate = new ThresholdGateWasm(config);
const ctx = new GateContextWasm(
42, // symbolId
1, // venueId
1000000n, // tsNs
15n, // mincutValue
'00000000000000000000000000000000', // partitionHash (hex)
1.0, // cusumScore
0.1, // driftScore
RegimeLabelWasm.Calm, // regime
10, // boundaryStableCount
);
const decision = gate.evaluate(ctx);
console.log('allow act:', decision.allowAct); // true
console.log('allow learn:', decision.allowLearn); // true
console.log('all allowed:', decision.allAllowed()); // true
// --- Market Event ---
const evt = new MarketEventWasm(EventTypeWasm.Trade, 42, 1, 500000000n, 10000n);
console.log('symbol:', evt.symbolId); // 42
const json = evt.toJson(); // serializable object
// --- Replay Memory ---
const store = new ReservoirStoreWasm(100);
console.log('empty:', store.isEmpty()); // trueAPI Reference
Functions
| Function | Returns | Description |
|----------|---------|-------------|
| version() | string | Crate version |
| healthCheck() | boolean | true if module loaded |
Classes
| Class | Key Methods |
|-------|-------------|
| MarketEventWasm | new(eventType, symbolId, venueId, priceFp, qtyFp), toJson(), fromJson(val) |
| GraphDeltaWasm | new(), nodesAdded(), edgesAdded(), propertiesUpdated() |
| GateConfigWasm | new() (defaults), getters/setters for all thresholds |
| GateContextWasm | new(symbolId, venueId, tsNs, mincutValue, partitionHash, cusumScore, driftScore, regime, boundaryStableCount) |
| ThresholdGateWasm | new(config), evaluate(ctx) |
| CoherenceDecisionWasm | allowRetrieve, allowWrite, allowLearn, allowAct, reasons(), toJson() |
| ReplaySegmentWasm | toJson(), fromJson(val), segmentId, symbolId |
| ReservoirStoreWasm | new(maxSize), len(), isEmpty(), maybeWrite(segmentJson, decisionJson) |
Enums
| Enum | Variants |
|------|----------|
| EventTypeWasm | NewOrder, ModifyOrder, CancelOrder, Trade, BookSnapshot, SessionMarker, VenueStatus |
| SideWasm | Bid, Ask |
| RegimeLabelWasm | Calm, Normal, Volatile |
| SegmentKindWasm | HighUncertainty, LargeImpact, RegimeTransition, StructuralAnomaly, RareQueuePattern, HeadDisagreement, Routine |
| NodeKindWasm | Symbol, Venue, PriceLevel, Order, Trade, Event, Participant, TimeBucket, Regime, StrategyState |
| EdgeKindWasm | AtLevel, NextTick, Generated, Matched, ModifiedFrom, CanceledBy, BelongsToSymbol, OnVenue, InWindow, CorrelatedWith, InRegime, AffectsState |
Browser Compatibility
Works in all browsers supporting WebAssembly + BigInt (Chrome 85+, Firefox 78+, Safari 15+, Edge 85+).
Architecture
See ADR-086 for design decisions and type mapping strategy.
License
MIT
