@openpit/engine is an embeddable pre-trade risk SDK for integrating
policy-driven risk checks into trading systems from JavaScript and TypeScript.
It is a WebAssembly build of the OpenPit engine that runs the same way in Node,
browsers, Deno, Bun, and edge runtimes (Cloudflare Workers) behind a single
import, with no native add-on to compile and no await in the common path.
For an overview and links to all resources, see the project website openpit.dev. For the generated API reference, see the JS API docs. For full project documentation, see the repository README. For conceptual and architectural pages, see the project wiki.
Before the 1.0 release OpenPit follows a relaxed Semantic Versioning:
PATCH releases carry bug fixes and small internal corrections.MINOR releases may introduce new features and may also change the
public interface.Breaking API changes can appear in minor releases before 1.0. Pick
version constraints that tolerate API evolution during the pre-stable
phase.
npm install @openpit/engine
The package ships two platform builds behind one import. Both instantiate the
wasm synchronously at load, so there is no await in the common path:
.wasm from disk (smallest footprint, fastest
cold start).fetch, no fs, no extra
asset to host. It works on any CDN with zero configuration.CDN / no build step (browser, Deno) via esm.sh:
<script type="module">
import { Engine } from "https://esm.sh/@openpit/engine";
// or: https://cdn.jsdelivr.net/npm/@openpit/engine/+esm
</script>
Deno, via the npm specifier:
import { Engine as DenoEngine } from "npm:@openpit/engine";
End users should install the published
npm package; a source build is
needed only for local development on the binding itself. It requires Rust,
Node.js >=18, the wasm32-unknown-unknown target, and wasm-bindgen-cli at the
exact version pinned in bindings/js/Cargo.toml (currently 0.2.122). From
the repository root, on POSIX:
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli --version 0.2.122 --locked --root target/wasm-tools
export PATH="$PWD/target/wasm-tools/bin:$PATH"
cd bindings/js
npm ci
npm run build
In PowerShell, use $env:PATH = "$PWD/target/wasm-tools/bin;$env:PATH" in
place of export. The local build uses wasm-opt when available; release
publishing requires it (OPENPIT_WASM_OPT=require).
Just is optional. just install at the repository
root provisions the complete repository toolchain, including other bindings;
just build-js builds this package once its prerequisites are installed.
Money and quantities cross the boundary as lossless decimal strings (or
bigint for 64-bit ids), never as floating-point number; assets are
validated strings. The full input contract is on
Domain Types.
import {
Engine,
OrderSizeBrokerBarrier,
TradeAmount,
buildOrderSizeLimit,
} from "@openpit/engine";
// Build the engine once, at start-up: one broker-wide fat-finger cap.
const engine = Engine.builder()
.builtin(
buildOrderSizeLimit().brokerBarrier(
new OrderSizeBrokerBarrier({
maxQuantity: "500",
maxNotional: "1000000",
}),
),
)
.build();
const result = engine.executePreTrade({
operation: {
underlyingAsset: "AAPL",
settlementAsset: "USD",
accountId: 99224416,
side: "BUY",
tradeAmount: TradeAmount.quantity("1000"),
price: "185",
},
});
if (result.ok) {
// Send the order to the venue, then commit or roll the reservation back.
result.reservation?.commit();
} else {
for (const reject of result.rejects) {
// OrderSizeLimitPolicy [OrderQtyExceedsLimit]: order quantity exceeded
console.error(`${reject.policy} [${reject.code}]: ${reject.reason}`);
}
}
The explicit two-stage flow, drop copy, and post-trade reports are described on the Pre-trade Pipeline page.
The package ships ESM and CommonJS builds for Node >=18 and browser/edge
bundlers. Every environment resolves the root . or any subpath to the matching
node/ or browser/ entry and module format:
| Environment | Resolves to | Wasm |
|---|---|---|
Node ESM (>=18) |
node/<entry>.js |
from disk |
Node CommonJS (>=18) |
node/<entry>.cjs |
from disk |
| Bundlers (Vite, webpack, Rollup, esbuild) | browser/<entry>.{js,cjs} |
inlined |
| Browsers via CDN (esm.sh, jsDelivr, unpkg) | browser/<entry>.js |
inlined |
Deno (npm: specifier or esm.sh) |
node / browser ESM entry |
disk / inlined |
| Bun | node/<entry>.{js,cjs} |
from disk |
| Cloudflare Workers / edge | browser/<entry>.{js,cjs} |
inlined |
<entry> is index for the root import or the subpath name (for example
param, marketdata, pretrade/policies). The inlined browser build needs no
asset-loader configuration and makes no network request at import, so CDN and
Workers usage is zero-config.
Apache-2.0. See
LICENSE and
OWNERS. Licenses of the
third-party crates compiled into the WebAssembly module are in
THIRD-PARTY-LICENSES.