-
Notifications
You must be signed in to change notification settings - Fork 1
Architecture
This page describes the current public architecture of OpenPit.
-
Embeddable: no separate service, no network hop, no runtime requirement -
Deterministic: the same order, policy state, and policy set produce the same decision -
Fail-safe by default: unfinalized reservations roll back automatically -
Financially precise: domain values use exact decimal semantics throughparamtypes
- Go module
go.openpit.dev/openpit - Python package
openpit - Rust crate
openpit
-
Domain values: prices, quantities, pnl, cash flow, volume, side, leverage Go:openpit/paramPython:openpit.paramRust:openpit::param -
Core entities: order, execution report, account adjustment, instrument, engine Go: package rootopenpitPython: package root andopenpit.coreRust: crate root andopenpit::core -
Pre-trade pipeline: policies, rejects, requests, reservations, reports Go:openpit/pretradePython:openpit.pretradeRust:openpit::pretrade
Engine coordinates the public pre-trade lifecycle:
- Build an engine.
- Run the
start stage. - Execute the deferred request.
- Finalize the reservation.
- Apply post-trade feedback.
- Optionally validate non-trade operation (NTO) batches through
apply account adjustments.
Current engine behavior:
- Policy names must be unique across both stages.
- Engine handle threading capability follows from the chosen sync policy. Full sync supports concurrent invocation on the same handle; Local sync keeps the handle single-threaded; Account sync supports sequential cross-thread access with caller-pinned per-account chains. See Threading Contract.
- A deferred request or reservation depends on the engine instance that created it.
- Account-adjustment batch validation is atomic: first reject aborts the whole batch.
OpenPit currently exposes public integration models for orders, execution reports, and non-trading account adjustments:
- Rust can evaluate caller-defined order and execution-report types directly
when they implement the required capability traits. Order traits include
HasTradeAmount,HasOrderPrice,HasInstrument, andHasSide. Report traits includeHasPnl,HasFee, andHasInstrument. Policies declare only the traits they actually use, so a policy that only inspects trade amount and price requiresO: HasTradeAmount + HasOrderPriceand is compatible with any order type that provides those two capabilities. - Python exposes fixed public record models:
openpit.Order,openpit.ExecutionReport, andopenpit.AccountAdjustment.
Both SDKs use the same staged flow and the same standard reject shape.
Rust-specific guidance for manual trait implementations and derive-based wrapper composition is documented in Custom Rust Types.
OpenPit separates early admission checks from main-stage checks that may reserve state.
Order
│
▼
Start stage
│
├─ Reject
▼
Pre-trade request
│
▼
Execute request
│
├─ Reject list
▼
Pre-trade reservation
│
├─ Commit
└─ Rollback
Stage semantics:
-
Start stagestops at the first reject. -
Main stageevaluates all configured policies. - If any main-stage policy rejects, accumulated mutations roll back before the reject list is returned.
Account adjustment is validated through a dedicated atomic batch flow:
Account adjustment batch
│
▼
Batch validation
│
├─ Accepted batch
└─ Rejected batch { failed index, reject reason }
Semantics:
- Deterministic traversal by batch order and policy registration order
- First reject stops evaluation
- All-or-nothing batch outcome
Main-stage policies do not finalize state directly. They emit Pre-trade mutation
pairs that the engine applies later.
Current public mutation kinds are:
- Reserve notional for a settlement asset
- Set a kill-switch state
OpenPit is intentionally narrow in scope:
- It is a pre-trade engine, not an OMS or EMS.
- It does not provide persistence or external data sources.
- It does not provide venue connectivity.
- The current built-in policies are all
start stagepolicies.
- Getting Started: First engine construction
- Custom Rust Types: Capability traits and wrapper authoring
- Pre-trade Pipeline: Request and reservation lifecycle
- Account Adjustments: Non-trade operation (NTO) batch model and semantics
- Policies: Built-in controls and custom policy hooks
- Domain Types: Typed financial values used by the engine