OpenPit (Pre-trade Integrity Toolkit) for Python
openpit is an embeddable pre-trade risk SDK for integrating policy-driven
risk checks into trading systems from Python.
For an overview and links to all resources, see the project website openpit.dev. For the Python API guide and reference, see openpit.readthedocs.io. 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:
PATCHreleases carry bug fixes and small internal corrections.MINORreleases 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 PyPI package.
Examples
Runnable end-to-end examples live in examples/python/:
spot_funds- simplest SpotFunds policy integration (limit-only).spot_table- table-driven test runner for the SpotFunds policy.rate_pnl_killswitch- rate-limit + P&L kill-switch supervisor.
Install
For normal end-user installation, use the published PyPI package:
pip install openpit
POSIX (Linux, macOS, etc)
Install Rust and Python 3.10+. Just is optional but recommended.
If you need local development/debugging, clone this repository and build from source with Maturin:
With Just:
just python-develop-debug
Local release build:
just python-develop-release
Manual:
python3 -m venv .venv
.venv/bin/python -m pip install -r ./requirements.txt
.venv/bin/python -m maturin develop --manifest-path bindings/python/Cargo.toml
.venv/bin/python -m maturin develop --release --manifest-path bindings/python/Cargo.toml
Windows
Install rustup, target x86_64-pc-windows-msvc, and
Python 3.10+. Just
is optional but recommended.
With Just:
rustup target add x86_64-pc-windows-msvc
just python-develop-debug
just python-develop-release
Manual:
rustup target add x86_64-pc-windows-msvc
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r .\requirements.txt
.\.venv\Scripts\python.exe -m maturin develop `
--manifest-path bindings/python/Cargo.toml `
--target x86_64-pc-windows-msvc
.\.venv\Scripts\python.exe -m maturin develop `
--release `
--manifest-path bindings/python/Cargo.toml `
--target x86_64-pc-windows-msvc
Quick Start
import openpit
from openpit.param import AccountId, Price, Quantity, Side, TradeAmount, Volume
from openpit.pretrade.policies import (
OrderSizeBrokerBarrier,
OrderSizeLimit,
build_order_size_limit,
)
# Build the engine once, at start-up: one broker-wide fat-finger cap.
engine = (
openpit.Engine.builder()
.no_sync()
.builtin(
build_order_size_limit().broker_barrier(
OrderSizeBrokerBarrier(
limit=OrderSizeLimit(
max_quantity=Quantity("500"),
max_notional=Volume("1000000"),
),
),
),
)
.build()
)
order = openpit.Order(
operation=openpit.OrderOperation(
instrument=openpit.Instrument("AAPL", "USD"),
account_id=AccountId.from_int(99224416),
side=Side.BUY,
trade_amount=TradeAmount.quantity("1000"),
price=Price("185"),
),
)
result = engine.execute_pre_trade(order=order)
if result.ok:
# Send the order to the venue, then commit or roll the reservation back.
result.reservation.commit()
else:
for reject in result.rejects:
# OrderSizeLimitPolicy [OrderQtyExceedsLimit]: order quantity exceeded
print(f"{reject.policy} [{reject.code}]: {reject.reason}")
The explicit two-stage flow, drop copy, and post-trade reports are described on the Pre-trade Pipeline page.
What Is Inside
- Spot Funds - per-account solvency gate over spendable funds.
- Order Validation - structural integrity checks on every order.
- Rate Limit - throttle order flow per broker, asset, or account.
- Order Size Limit - fat-finger caps on quantity and notional.
- P&L Kill Switch - halt an account when realized P&L breaches bounds.
- Custom Python policies - the primary integration model.
- Account Blocking, Account Groups, Account Adjustments, and Balance Reconciliation.
- Drop Copy - record already executed orders without pre-trade enforcement.
- Market Data.
- Dynamic Reconfiguration of a live policy.
- Threading Contract - the GIL is held across callbacks, so Python policies run on the calling thread.
- Rejects and errors with stable reject codes; the full Python exception guide is on readthedocs.
Local Testing
POSIX (Linux, macOS, etc)
Recommended local flow:
With Just:
just test-python-debug
just test-python-unit-debug
just test-python-integration-debug
Manual:
python3 -m venv .venv
.venv/bin/python -m pip install -r ./requirements.txt
.venv/bin/python -m maturin develop --manifest-path bindings/python/Cargo.toml
.venv/bin/python -m pytest bindings/python/tests
Run only unit tests:
.venv/bin/python -m maturin develop --manifest-path bindings/python/Cargo.toml
.venv/bin/python -m pytest bindings/python/tests/unit
Run only integration test:
.venv/bin/python -m maturin develop --manifest-path bindings/python/Cargo.toml
.venv/bin/python -m pytest bindings/python/tests/integration
Windows
Optional: Just.
With Just:
just test-python-debug
just test-python-unit-debug
just test-python-integration-debug
Manual:
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r .\requirements.txt
.\.venv\Scripts\python.exe -m maturin develop `
--manifest-path bindings/python/Cargo.toml `
--target x86_64-pc-windows-msvc
.\.venv\Scripts\python.exe -m pytest bindings/python/tests
.\.venv\Scripts\python.exe -m pytest bindings/python/tests/unit
.\.venv\Scripts\python.exe -m pytest bindings/python/tests/integration
For full build/test command matrix (manual and just), see
the repository README.
Release files for openpit 0.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openpit-0.8.2.tar.gz | 689.5 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| openpit-0.8.2-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| openpit-0.8.2-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| openpit-0.8.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| openpit-0.8.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| openpit-0.8.2-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| openpit-0.8.2-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 6.7 MB
Release files / openpit-0.8.2.tar.gz
| Download URL | openpit-0.8.2.tar.gz |
|---|---|
| Size | 689.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c911b07362134c2fd8534ea5484a82038360e6d12d7eeef807aee94de0f430f5
|
|
BLAKE2b-256 checksum How to use checksums |
ec9276b9a3c4eb84d0f3acd88decac8e5357d3567e8dd7ceaedd36d0e1c377a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / openpit-0.8.2-cp310-abi3-win_amd64.whl
| Download URL | openpit-0.8.2-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 978.8 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e7918ed272beff0f00ad222c677095ce21d92f737a93be3340da11e5798b09f3
|
|
BLAKE2b-256 checksum How to use checksums |
31dc618236f4689f347fda70a8e9b45574d65179cd9eb740c74f92b81bd0d82f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / openpit-0.8.2-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | openpit-0.8.2-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1986c246d4eb1e2b4bca0c18c18b0b739354a2350b4752a177e6f286e1e92c38
|
|
BLAKE2b-256 checksum How to use checksums |
704e5408a6e142267ae32b6b9712eebf36950b4fb2000cede961502859e084e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / openpit-0.8.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | openpit-0.8.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
86787121e7047a9400ac7fe201c545a31adce93763f3e704bf67b81801faf91a
|
|
BLAKE2b-256 checksum How to use checksums |
d49001e8383053635029a9060e522eb841d71548eb354ed2df219e489297af21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / openpit-0.8.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | openpit-0.8.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
df4d58d0c9e31b324ef281a790d9f6b66fc6dd99697b4ab75e0dbbba42787ba9
|
|
BLAKE2b-256 checksum How to use checksums |
7f58abab46b6bcc0e46f55a84a928e514bb2a021a517061eaec01d061d887244
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / openpit-0.8.2-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | openpit-0.8.2-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 937.7 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
85d2b946b83d5daf88ecbcfa1a59d34c37e320a12c578356b28e273900c97a33
|
|
BLAKE2b-256 checksum How to use checksums |
cf881234742467b3d6c137bd9a8e7c779b5c70a9ffeaeae9c4b62bf7d4f345af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / openpit-0.8.2-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | openpit-0.8.2-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
0e95d6e3cbafc6537be5bc3d84e68c8a24863bcb804bfe8aabd0bb59feaa02a2
|
|
BLAKE2b-256 checksum How to use checksums |
cb5138f736523296f6ead0502eda54de67a05a58a34c17c5baf2a49bc4aadabd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|