Pit: Pre-trade Integrity Toolkit
openpit is an embeddable pre-trade risk SDK for integrating policy-driven
risk checks into trading systems.
For an overview and links to all resources, see the project website openpit.dev. For full project documentation, see the repository README. For conceptual and architectural pages, see the project wiki.
Versioning Policy (Pre‑1.0)
Until Pit reaches a stable 1.0 release, the project follows a relaxed
interpretation of Semantic Versioning.
During this phase:
PATCHreleases are used for bug fixes and small internal corrections.MINORreleases may introduce new features and may also change the public interface.
This means that breaking API changes can appear in minor releases before 1.0.
Consumers of the library should take this into account when declaring
dependencies and consider using version constraints that tolerate API
evolution during the pre‑stable phase.
Getting Started
Visit the crate page on crates.io and the API documentation on docs.rs.
Install
Run the following Cargo command in your project directory:
Engine
Overview
The engine evaluates an order through a deterministic pre-trade pipeline:
start_pre_trade(order)runs lightweight start-stage policiesRequest::execute()runs main-stage policiesReservation::commit()applies reserved state- dropping
Reservationrolls state back automatically apply_execution_report(report)updates post-trade policy state
Start-stage policies stop on the first reject. Main-stage policies aggregate rejects and roll back registered mutations in reverse order when any reject is produced.
Built-in start-stage policies currently include:
OrderValidationPolicyPnlKillSwitchPolicyRateLimitPolicyOrderSizeLimitPolicy
There are two types of rejections: a full kill switch for the account and a rejection of only the current request. This is useful in algorithmic trading when automatic order submission must be halted until the situation is analyzed.
Usage
use Duration;
use ;
use ;
use ;
use OrderValidationPolicy;
use PnlKillSwitchPolicy;
use RateLimitPolicy;
use ;
#
Errors
Rejects from start_pre_trade(order) and Request::execute() are returned as
Err(Reject) and Result<Reservation, Vec<Reject>>.
Each Reject contains:
policy: policy namecode: stable machine-readable code (for exampleRejectCode::OrderQtyExceedsLimit)reason: short human-readable reject type (for example"order quantity exceeded")details: concrete case details (for example"requested 11, max allowed: 10")scope:RejectScope::OrderorRejectScope::Account
RejectCode values are standardized and stable across Rust, Python, and C FFI.