Skip to main content

Crate openpit

Crate openpit 

Source
Expand description

Embeddable pre-trade risk engine for trading systems.

openpit focuses on the moment before an order leaves the application. The crate provides:

  • Engine to coordinate pre-trade checks and post-trade feedback;
  • param for typed financial values such as param::Price and param::Pnl;
  • pretrade for policy traits, rejects, deferred requests, and reservations.

The pipeline is intentionally explicit:

  1. Engine::start_pre_trade runs start-stage policies and returns a pretrade::PreTradeRequest.
  2. pretrade::PreTradeRequest::execute runs main-stage policies and returns a pretrade::PreTradeReservation.
  3. pretrade::PreTradeReservation::commit or pretrade::PreTradeReservation::rollback finalizes reserved state.
  4. Engine::apply_execution_report feeds realized outcomes back into policies.
  5. Engine::apply_account_adjustment validates 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 its inner-like field.

Structs§

AccountAdjustmentAmount
Grouped total/reserved/pending adjustment payload.
AccountAdjustmentBalanceOperation
Direct adjustment of a physical asset balance without hedge/netting semantics.
AccountAdjustmentBatchError
Error returned when account-adjustment batch validation fails.
AccountAdjustmentBounds
Optional post-adjustment inclusive limits for account adjustment components.
AccountAdjustmentContext
Context of the current account-adjustment operation.
AccountAdjustmentPositionOperation
Direct adjustment of a derivatives-like position with explicit position mode.
Engine
Risk engine orchestrating start-stage and main-stage pre-trade checks.
EngineBuilder
Fluent builder for Engine.
ExecutionReportFillDetails
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.
ExecutionReportOperation
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.
ExecutionReportPositionImpact
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.
FinancialImpact
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.
OrderMargin
Data: margin configuration parameters. No #[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates.
OrderOperation
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.
OrderPosition
Data: position management parameters. No #[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates.
RequestFieldAccessError
Returned when a request field could not be delivered to the caller.
WithAccountAdjustmentAmount
Adds grouped total/reserved/pending adjustment payload.
WithAccountAdjustmentBalanceOperation
Adds physical-balance adjustment operation payload.
WithAccountAdjustmentBounds
Adds post-adjustment inclusive limits.
WithAccountAdjustmentPositionOperation
Adds derivatives-position adjustment operation payload.
WithExecutionReportFillDetails
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.
WithExecutionReportOperation
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.
WithExecutionReportPositionImpact
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.
WithFinancialImpact
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.
WithOrderMargin
Adds margin configuration parameters. No #[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates.
WithOrderOperation
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.
WithOrderPosition
Adds position management parameters. No #[non_exhaustive]: these are client-facing convenience structs meant to be constructed via struct literals from external crates.

Enums§

EngineBuildError
Errors returned by EngineBuilder::build.

Traits§

AccountAdjustmentPolicy
Policy contract for account-adjustment batch validation.
HasAccountAdjustmentBalanceAverageEntryPrice
HasAccountAdjustmentPending
Amount in-flight for incoming acquisition and not yet finalized.
HasAccountAdjustmentPendingLowerBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentPendingUpperBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentPositionLeverage
HasAccountAdjustmentReserved
Amount earmarked for outgoing settlement and unavailable for immediate use.
HasAccountAdjustmentReservedLowerBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentReservedUpperBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentTotal
Actual resulting balance/position value after applying the adjustment.
HasAccountAdjustmentTotalLowerBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentTotalUpperBound
Allowed post-adjustment range for the corresponding component.
HasAccountId
HasAutoBorrow
HasAverageEntryPrice
HasBalanceAsset
HasClosePosition
HasCollateralAsset
HasExecutionReportIsTerminal
HasExecutionReportLastTrade
HasExecutionReportPositionEffect
HasExecutionReportPositionSide
HasFee
HasInstrument
HasLeavesQuantity
Remaining order quantity after the fill.
HasLock
Reservation lock context captured during pre-trade.
HasOrderCollateralAsset
HasOrderLeverage
HasOrderPositionSide
HasOrderPrice
Requested worst execution price used for size translation and price-sensitive checks.
HasPnl
HasPositionInstrument
HasPositionMode
Position accounting mode where exposure is represented either as one net position or as separate hedged legs.
HasReduceOnly
HasSide
HasTradeAmount