Expand description
Embeddable pre-trade risk engine for trading systems.
openpit focuses on the moment before an order leaves the application.
The crate provides:
Engineto coordinate pre-trade checks and post-trade feedback;paramfor typed financial values such asparam::Priceandparam::Pnl;pretradefor policy traits, rejects, deferred requests, and reservations.
The pipeline is intentionally explicit:
Engine::start_pre_traderuns start-stage policies and returns apretrade::PreTradeRequest.pretrade::PreTradeRequest::executeruns main-stage policies and returns apretrade::PreTradeReservation.pretrade::PreTradeReservation::commitorpretrade::PreTradeReservation::rollbackfinalizes reserved state.Engine::apply_execution_reportfeeds realized outcomes back into policies.Engine::apply_account_adjustmentvalidates non-trade adjustment batches.
The current crate scope is deliberately narrow: in-memory admission control, exact decimal value types, and a small set of built-in start-stage policies. Persistence, market connectivity, and thread synchronization stay with the caller.
Re-exports§
pub use marketdata::AccountInfo;pub use marketdata::AlreadyRegistered;pub use marketdata::InstrumentId;pub use marketdata::LocalTtlGate;pub use marketdata::MarketDataBuilder;pub use marketdata::MarketDataError;pub use marketdata::MarketDataLock;pub use marketdata::MarketDataService;pub use marketdata::MarketDataSync;pub use marketdata::NoopLock;pub use marketdata::PushForError;pub use marketdata::Quote;pub use marketdata::QuoteResolution;pub use marketdata::QuoteTtl;pub use marketdata::RegistrationError;pub use marketdata::ServiceTtlGate;pub use marketdata::UnknownInstrumentId;pub use param::AdjustmentAmount;pub use param::PositionMode;pub use pretrade::PostTradeResult;pub use pretrade::SpotFundsConfigError;pub use pretrade::SpotFundsMarketData;pub use pretrade::SpotFundsOverride;pub use pretrade::SpotFundsOverrideTarget;pub use pretrade::SpotFundsPricingSource;pub use storage::IndexFlag;pub use storage::StorageBuilder;
Modules§
- marketdata
- Pull-based market-data service for supplying live quotes to pre-trade policies and periodic portfolio revaluators.
- param
- Parameter value types for trading operations.
- pretrade
- Pre-trade pipeline types and extension points.
- storage
- Generic key-value storage with pluggable synchronization.
Macros§
- has_
request_ field_ trait - A macro to generate the trait that requests a specific field from the request.
- impl_
request_ has_ field - Generates
Has*request-field trait implementations for a base payload type and its wrapper. - impl_
request_ has_ field_ passthrough - Generates passthrough
Has*implementations for a wrapper through itsinner-like field.
Structs§
- Account
Adjustment Amount - Grouped balance/held/incoming adjustment payload.
- Account
Adjustment Balance Operation - Direct adjustment of a physical asset balance without hedge/netting semantics.
- Account
Adjustment Batch Error - Error returned when account-adjustment batch validation fails.
- Account
Adjustment Batch Result - Outcome of a successful
crate::Engine::apply_account_adjustmentbatch. - Account
Adjustment Bounds - Optional post-adjustment inclusive limits for account adjustment components.
- Account
Adjustment Context - Context of the current account-adjustment operation.
- Account
Adjustment Outcome - Account position outcome with the group tag of the business entity that produced it.
- Account
Adjustment Position Operation - Direct adjustment of a derivatives-like position with explicit position mode.
- Account
Block Handle - Public, opaque handle to the engine’s
BlockedAccountsfacility. - Account
Control - Per-account handle to the engine’s
BlockedAccountsfacility. - Account
KeyConstraint - Engine-level adapter that maps
AccountKeyonto the storage layer’s neutralIndexKeyBound. - Account
Outcome Entry - Raw outcome data produced by a policy for one asset.
- Account
Sync - Account-keyed synchronization mode.
- Account
Sync Handle - Engine handle handed out for account-sharded sequential cross-thread invocation.
- Account
Sync Handle Weak - Weak counterpart of
AccountSyncHandle. - Accounts
- Public handle to the engine’s account registry.
- Configurator
- Engine handle for retuning built-in policies at runtime.
- Engine
- Risk engine orchestrating start-stage and main-stage pre-trade checks.
- Engine
Builder - Fluent builder for
Engine. - Engine
Trait Of - Concrete
EngineTraitimplementation composed from the four individual type choices. - Execution
Report Fill Details - Data: trade reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - Execution
Report Operation - Data: main operation parameters reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - Execution
Report Position Impact - Data: position impact parameters reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - Financial
Impact - Data: financial impact parameters reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - Full
Sync - Full thread-safety synchronization mode.
- Instrument
- Trading instrument definition.
- Local
Sync - Single-thread synchronization mode.
- Mutation
- Commit/rollback pair produced by a policy.
- Mutations
- Collected mutations registered during pre-trade checks.
- Order
Margin - Data: margin configuration parameters.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - Order
Operation - Data: main operation parameters that describe side, instrument, price, and amount.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - Order
Position - Data: position management parameters.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - Outcome
Amount - A delta/absolute pair for one position field.
- PnlOutcome
Amount - A delta/absolute pair for a realized PnL field.
- Policy
Group Id - Opaque policy-group tag attached to an abstract business entity.
- Ready
Engine Builder - Engine builder with a synchronization mode and at least one trading
policy registered. Can produce an
Engineviabuild. - Request
Field Access Error - Returned when a request field could not be delivered to the caller.
- Synced
Engine Builder - Engine builder with a synchronization mode applied.
- With
Account Adjustment Amount - Adds grouped balance/held/incoming adjustment payload.
- With
Account Adjustment Balance Operation - Adds physical-balance adjustment operation payload.
- With
Account Adjustment Bounds - Adds post-adjustment inclusive limits.
- With
Account Adjustment Position Operation - Adds derivatives-position adjustment operation payload.
- With
Execution Report Fill Details - Adds financial impact parameters reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - With
Execution Report Operation - Adds main operation parameters reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - With
Execution Report Position Impact - Adds position impact parameters reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - With
Financial Impact - Adds financial impact parameters reported by the execution.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - With
Order Margin - Adds margin configuration parameters.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - With
Order Operation - Adds main operation parameters that describe side, instrument, price, and amount.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates. - With
Order Position - Adds position management parameters.
No
#[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates.
Enums§
- Account
Block Error - Error returned by the admin block operations on
Accounts. - Account
Group Error - Error returned by
Accounts::register_groupandAccounts::unregister_group. - Configure
Error - Error returned by
Configuratorwhen a runtime reconfiguration fails. - Engine
Build Error - Errors returned by
ReadyEngineBuilder::build.
Constants§
- DEFAULT_
POLICY_ GROUP_ ID - Policy-group tag used when the caller does not assign one.
Traits§
- Account
Key - Storage-key marker for keys that identify an account.
- Engine
Trait - Aggregates the four type-level choices of an
Engineinstance into a single trait, so that engine code carries one generic parameter instead of four. - HasAccount
Adjustment Balance - Actual resulting balance/position value after applying the adjustment.
- HasAccount
Adjustment Balance Average Entry Price - HasAccount
Adjustment Balance Lower Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Balance Realized Pnl - HasAccount
Adjustment Balance Upper Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Held - Amount earmarked for outgoing settlement and unavailable for immediate use.
- HasAccount
Adjustment Held Lower Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Held Upper Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Incoming - Amount in-flight for incoming acquisition and not yet finalized.
- HasAccount
Adjustment Incoming Lower Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Incoming Upper Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Position Leverage - HasAccount
Id - HasAuto
Borrow - HasAverage
Entry Price - HasBalance
Asset - HasClose
Position - HasCollateral
Asset - HasExecution
Report IsFinal - HasExecution
Report Last Trade - HasExecution
Report Position Effect - HasExecution
Report Position Side - HasFee
- HasInstrument
- HasLeaves
Quantity - Remaining order quantity after the fill.
- HasOrder
Collateral Asset - HasOrder
Leverage - HasOrder
Position Side - HasOrder
Price - Requested worst execution price used for size translation and price-sensitive checks.
- HasPnl
- HasPosition
Instrument - HasPosition
Mode - Position accounting mode where exposure is represented either as one net position or as separate hedged legs.
- HasPre
Trade Lock - Reservation lock context captured during pre-trade.
- HasReduce
Only - HasSide
- HasTrade
Amount - Into
Policy Object - Converts a concrete policy into the trait-object shape selected by a
SyncMode. - Sync
Mode - Synchronization mode for an
Engine.
Type Aliases§
- Account
Sync Engine - Account-sharded engine type alias.
- Full
Sync Engine - Multi-threaded engine type alias.
- Local
Engine - Single-threaded engine type alias.