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 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 its inner-like field.

Structs§

AccountAdjustmentAmount
Grouped balance/held/incoming adjustment payload.
AccountAdjustmentBalanceOperation
Direct adjustment of a physical asset balance without hedge/netting semantics.
AccountAdjustmentBatchError
Error returned when account-adjustment batch validation fails.
AccountAdjustmentBatchResult
Outcome of a successful crate::Engine::apply_account_adjustment batch.
AccountAdjustmentBounds
Optional post-adjustment inclusive limits for account adjustment components.
AccountAdjustmentContext
Context of the current account-adjustment operation.
AccountAdjustmentOutcome
Account position outcome with the group tag of the business entity that produced it.
AccountAdjustmentPositionOperation
Direct adjustment of a derivatives-like position with explicit position mode.
AccountBlockHandle
Public, opaque handle to the engine’s BlockedAccounts facility.
AccountControl
Per-account handle to the engine’s BlockedAccounts facility.
AccountKeyConstraint
Engine-level adapter that maps AccountKey onto the storage layer’s neutral IndexKeyBound.
AccountOutcomeEntry
Raw outcome data produced by a policy for one asset.
AccountSync
Account-keyed synchronization mode.
AccountSyncHandle
Engine handle handed out for account-sharded sequential cross-thread invocation.
AccountSyncHandleWeak
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.
EngineBuilder
Fluent builder for Engine.
EngineTraitOf
Concrete EngineTrait implementation composed from the four individual type choices.
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.
FullSync
Full thread-safety synchronization mode.
Instrument
Trading instrument definition.
LocalSync
Single-thread synchronization mode.
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.
OutcomeAmount
A delta/absolute pair for one position field.
PnlOutcomeAmount
A delta/absolute pair for a realized PnL field.
PolicyGroupId
Opaque policy-group tag attached to an abstract business entity.
ReadyEngineBuilder
Engine builder with a synchronization mode and at least one trading policy registered. Can produce an Engine via build.
RequestFieldAccessError
Returned when a request field could not be delivered to the caller.
SyncedEngineBuilder
Engine builder with a synchronization mode applied.
WithAccountAdjustmentAmount
Adds grouped balance/held/incoming 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§

AccountBlockError
Error returned by the admin block operations on Accounts.
AccountGroupError
Error returned by Accounts::register_group and Accounts::unregister_group.
ConfigureError
Error returned by Configurator when a runtime reconfiguration fails.
EngineBuildError
Errors returned by ReadyEngineBuilder::build.

Constants§

DEFAULT_POLICY_GROUP_ID
Policy-group tag used when the caller does not assign one.

Traits§

AccountKey
Storage-key marker for keys that identify an account.
EngineTrait
Aggregates the four type-level choices of an Engine instance into a single trait, so that engine code carries one generic parameter instead of four.
HasAccountAdjustmentBalance
Actual resulting balance/position value after applying the adjustment.
HasAccountAdjustmentBalanceAverageEntryPrice
HasAccountAdjustmentBalanceLowerBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentBalanceRealizedPnl
HasAccountAdjustmentBalanceUpperBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentHeld
Amount earmarked for outgoing settlement and unavailable for immediate use.
HasAccountAdjustmentHeldLowerBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentHeldUpperBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentIncoming
Amount in-flight for incoming acquisition and not yet finalized.
HasAccountAdjustmentIncomingLowerBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentIncomingUpperBound
Allowed post-adjustment range for the corresponding component.
HasAccountAdjustmentPositionLeverage
HasAccountId
HasAutoBorrow
HasAverageEntryPrice
HasBalanceAsset
HasClosePosition
HasCollateralAsset
HasExecutionReportIsFinal
HasExecutionReportLastTrade
HasExecutionReportPositionEffect
HasExecutionReportPositionSide
HasFee
HasInstrument
HasLeavesQuantity
Remaining order quantity after the fill.
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.
HasPreTradeLock
Reservation lock context captured during pre-trade.
HasReduceOnly
HasSide
HasTradeAmount
IntoPolicyObject
Converts a concrete policy into the trait-object shape selected by a SyncMode.
SyncMode
Synchronization mode for an Engine.

Type Aliases§

AccountSyncEngine
Account-sharded engine type alias.
FullSyncEngine
Multi-threaded engine type alias.
LocalEngine
Single-threaded engine type alias.