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::Request.
  2. pretrade::Request::execute runs main-stage policies and returns a pretrade::Reservation.
  3. pretrade::Reservation::commit or pretrade::Reservation::rollback finalizes reserved state.
  4. Engine::apply_execution_report feeds realized outcomes back into policies.

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 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

Structs§

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.
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.
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§

HasAutoBorrow
HasClosePosition
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
HasReduceOnly
HasSide
HasTradeAmount