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 param::AdjustmentAmount;pub use param::PositionMode;pub use pretrade::PostTradeResult;
Modules§
- param
- Parameter value types for trading operations.
- pretrade
- Pre-trade pipeline types and extension points.
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 total/reserved/pending 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 Bounds - Optional post-adjustment inclusive limits for account adjustment components.
- Account
Adjustment Context - Context of the current account-adjustment operation.
- Account
Adjustment Position Operation - Direct adjustment of a derivatives-like position with explicit position mode.
- Engine
- Risk engine orchestrating start-stage and main-stage pre-trade checks.
- Engine
Builder - Fluent builder for
Engine. - 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. - Instrument
- Trading instrument definition.
- 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. - Request
Field Access Error - Returned when a request field could not be delivered to the caller.
- With
Account Adjustment Amount - Adds grouped total/reserved/pending 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§
- Engine
Build Error - Errors returned by
EngineBuilder::build.
Traits§
- Account
Adjustment Policy - Policy contract for account-adjustment batch validation.
- HasAccount
Adjustment Balance Average Entry Price - HasAccount
Adjustment Pending - Amount in-flight for incoming acquisition and not yet finalized.
- HasAccount
Adjustment Pending Lower Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Pending Upper Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Position Leverage - HasAccount
Adjustment Reserved - Amount earmarked for outgoing settlement and unavailable for immediate use.
- HasAccount
Adjustment Reserved Lower Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Reserved Upper Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Total - Actual resulting balance/position value after applying the adjustment.
- HasAccount
Adjustment Total Lower Bound - Allowed post-adjustment range for the corresponding component.
- HasAccount
Adjustment Total Upper Bound - Allowed post-adjustment range for the corresponding component.
- 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.
- HasLock
- Reservation lock context captured during pre-trade.
- 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.
- HasReduce
Only - HasSide
- HasTrade
Amount