openpit is an embeddable pre-trade risk SDK for integrating policy-driven
risk checks into trading systems from C++.
The C++ SDK is a header-only C++17 wrapper over the native OpenPit runtime. It
is packaged as a CMake config package and exposes the OpenPit::openpit target.
For an overview and links to all resources, see the project website openpit.dev. For the C++ API reference, see the C++ API docs. For full project documentation, see the repository README. For conceptual and architectural pages, see the project wiki.
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.
CMake find_package
Use the package generated by cmake --install from another CMake project:
find_package(OpenPit CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE OpenPit::openpit)On Windows, OpenPit resolves both the runtime DLL and the MSVC import library. If your application needs the DLL copied next to the executable, call:
openpit_copy_runtime_dll(your_target)Include <openpit/openpit.hpp> for the complete SDK surface, or include
<openpit/fwd.hpp> in precompiled headers when only forward declarations are
needed.
Declare the dependency in the project manifest, vcpkg.json:
{
"name": "your-project",
"version-string": "0",
"builtin-baseline": "<microsoft-vcpkg-commit>",
"dependencies": ["openpit"]
}builtin-baseline is a commit of the microsoft/vcpkg checkout the project
builds against; vcpkg x-update-baseline --add-initial-baseline fills it in.
It fixes the package versions of the whole build and is required for both
installation paths below.
Consume the port like any other CMake package:
find_package(OpenPit CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE OpenPit::openpit)Configure your project with the vcpkg toolchain file. The normal OpenPit runtime resolver then downloads and verifies the matching released runtime asset.
Public microsoft/vcpkg registry
The preferred path: the manifest above is the whole setup, because vcpkg
resolves openpit from the registry it already ships with. Ports land there
through upstream review, so a fresh OpenPit release becomes installable this
way with a delay.
openpitkit/vcpkg-registry
receives every OpenPit release first. Use it when the release you need has not
reached the public registry yet, or when pinning an exact OpenPit version. The
cost is one extra file next to the manifest, vcpkg-configuration.json:
{
"registries": [
{
"kind": "git",
"repository": "https://github.com/openpitkit/vcpkg-registry.git",
"baseline": "<openpit-registry-commit>",
"packages": ["openpit"]
}
]
}This baseline is a commit of the managed registry, not of microsoft/vcpkg;
every OpenPit release note publishes the commit to use.
#include <openpit/openpit.hpp>
#include <iostream>
int main() {
namespace model = openpit::model;
namespace param = openpit::param;
namespace policies = openpit::pretrade::policies;
// Build the engine once, at platform initialization.
openpit::EngineBuilder builder(openpit::SyncPolicy::None);
builder.Add(policies::OrderValidationPolicy{});
openpit::Engine engine = builder.Build();
// Describe the order: buy 100 AAPL at 185 USD.
const model::Order order = model::Order::Limit(
model::Instrument(param::Asset("AAPL"), param::Asset("USD")),
param::AccountId::FromUint64(99224416), model::Side::Buy,
model::TradeAmount::OfQuantity(param::Quantity::FromString("100")),
param::Price::FromString("185"));
// Run the pre-trade pipeline and read the verdict.
openpit::pretrade::ExecuteResult result = engine.ExecutePreTrade(order);
if (!result.Passed()) {
for (const openpit::pretrade::Reject& rejection : result.rejects) {
std::cout << "rejected by " << rejection.policy << ": "
<< rejection.reason << '\n';
}
return 1;
}
// The venue accepted the order, so the reserved state stays. Destroying an
// unresolved reservation rolls it back instead.
result.reservation->Commit();
return 0;
}The explicit two-stage flow, drop copy, and post-trade reports are described on the Pre-trade Pipeline page.
SpotFundsPolicy- per-account solvency gate over spendable fundsOrderValidationPolicy- structural integrity checks on every orderRateLimitPolicy- throttle order flow per broker, asset, or accountOrderSizeLimitPolicy- fat-finger caps on quantity and notionalPnlBoundsKillSwitchPolicy- halt an account when realized P&L breaches bounds- Custom C++ 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.
- Async Engine -
openpit::asyncengine::MakeTypedAsyncEngine(engine, workers)for per-account queues. - Threading Contract -
SyncPolicy::None,Full, orAccount, chosen when the engine is built. - Rejects and errors with stable reject codes.
Runnable end-to-end examples live in examples/cpp/:
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.spot_loadtest- synthetic load test for pre-trade request throughput and latency.
POSIX (Linux, macOS, etc)
Dependencies: Rust, CMake, and a C++17 compiler.
Build and install the C++ package from a local checkout:
cargo build -p openpit-ffi --release --locked
cmake -S bindings/cpp -B bindings/cpp/build \
-DOPENPIT_RUNTIME_LIBRARY="$PWD/target/release/libopenpit_ffi.dylib"
cmake --build bindings/cpp/build
cmake --install bindings/cpp/build --prefix "$PWD/.openpit"The command above uses the macOS .dylib; on Linux, point
OPENPIT_RUNTIME_LIBRARY at target/release/libopenpit_ffi.so.
Windows
Install rustup, target x86_64-pc-windows-msvc,
Visual Studio Build Tools,
and CMake. Optional:
Just.
With Just:
rustup target add x86_64-pc-windows-msvc
just build-cpp-release
just test-cpp-releaseManual:
rustup target add x86_64-pc-windows-msvc
cargo build -p openpit-ffi --release --locked --target x86_64-pc-windows-msvc
cmake -S bindings/cpp -B bindings/cpp/build `
-DOPENPIT_RUNTIME_LIBRARY="$PWD\target\x86_64-pc-windows-msvc\release\openpit_ffi.dll" `
-DOPENPIT_RUNTIME_IMPORT_LIBRARY="$PWD\target\x86_64-pc-windows-msvc\release\openpit_ffi.dll.lib"
cmake --build bindings/cpp/build
cmake --install bindings/cpp/build --prefix "$PWD\.openpit"When a released package is consumed through find_package(OpenPit CONFIG REQUIRED), the runtime resolver uses this order:
OPENPIT_RUNTIME_LIBRARY- absolute path to a prebuilt runtime library.OPENPIT_RUNTIME_DIR- directory containing the platform runtime library.- Download the matching release asset from GitHub and verify its SHA-256 sidecar.