openpit 0.8.1

Embeddable pre-trade risk SDK
Documentation

OpenPit: Pre-trade Integrity Toolkit

Verify Release Rust crates.io docs.rs License

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)

Before the 1.0 release OpenPit follows a relaxed Semantic Versioning:

  • PATCH releases carry bug fixes and small internal corrections.
  • MINOR releases may introduce new features and may also change the public interface.

Breaking API changes can appear in minor releases before 1.0. Pick 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:

cargo add openpit

Quick Start

use openpit::param::{AccountId, Asset, Price, Quantity, Side, TradeAmount, Volume};
use openpit::pretrade::policies::{
    OrderSizeBrokerBarrier, OrderSizeLimit, OrderSizeLimitPolicy, OrderSizeLimitSettings,
};
use openpit::storage::NoLocking;
use openpit::{Engine, Instrument, OrderOperation};

// One fat-finger control, wired once at startup.
let engine = Engine::builder::<OrderOperation, (), ()>()
    .no_sync()
    .pre_trade(OrderSizeLimitPolicy::<NoLocking>::new(
        OrderSizeLimitSettings::new(
            Some(OrderSizeBrokerBarrier {
                limit: OrderSizeLimit {
                    max_quantity: Some(Quantity::from_str("500")?),
                    max_notional: Some(Volume::from_str("100000")?),
                },
            }),
            [],
            [],
        )?,
    ))
    .build()?;

let order = OrderOperation {
    instrument: Instrument::new(Asset::new("AAPL")?, Asset::new("USD")?),
    account_id: AccountId::from_u64(99224416),
    side: Side::Buy,
    trade_amount: TradeAmount::Quantity(Quantity::from_str("1000")?),
    price: Some(Price::from_str("185")?),
};

// The verdict: either a reservation to finalize once the venue answers,
// or the rejects that stopped the order.
match engine.execute_pre_trade(order) {
    Ok(mut reservation) => reservation.commit(),
    Err(rejects) => println!("order rejected: {rejects}"),
}

The explicit two-stage flow, drop copy, and post-trade reports are described on the Pre-trade Pipeline page.

What Is Inside