Read-only mirror. This repository is a mirror of
bindings/go/from the openpitkit/pit monorepo. Do not open pull requests here - contribute to the monorepo instead.
openpit is an embeddable pre-trade risk SDK for integrating policy-driven
risk checks into trading systems from Go.
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. For the public Go module source, see go.openpit.dev/openpit.
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.
go get go.openpit.dev/openpitpackage main
import (
"log"
"go.openpit.dev/openpit"
"go.openpit.dev/openpit/model"
"go.openpit.dev/openpit/param"
"go.openpit.dev/openpit/pretrade/policies"
)
func main() {
// Build the engine once, at platform initialization.
engine, err := openpit.NewEngineBuilder().
FullSync().
Builtin(policies.BuildOrderValidation()).
Build()
if err != nil {
log.Fatal(err)
}
defer engine.Stop()
aapl, err := param.NewAsset("AAPL")
if err != nil {
log.Fatal(err)
}
usd, err := param.NewAsset("USD")
if err != nil {
log.Fatal(err)
}
qty, err := param.NewQuantityFromString("100")
if err != nil {
log.Fatal(err)
}
price, err := param.NewPriceFromString("185")
if err != nil {
log.Fatal(err)
}
// Describe the order: buy 100 AAPL at 185 USD.
order := model.NewOrder()
operation := order.EnsureOperationView()
operation.SetInstrument(param.NewInstrument(aapl, usd))
operation.SetAccountID(param.NewAccountIDFromUint64(99224416))
operation.SetSide(param.SideBuy)
operation.SetTradeAmount(param.NewQuantityTradeAmount(qty))
operation.SetPrice(price)
// Run the pre-trade pipeline and read the verdict.
reservation, rejects, err := engine.ExecutePreTrade(order)
if err != nil {
log.Fatal(err)
}
if rejects != nil {
log.Fatalf("order rejected: %v", rejects)
}
// Close rolls the reservation back unless it was committed.
defer reservation.Close()
// The venue accepted the order, so the reserved state stays.
reservation.Commit()
}The explicit two-stage flow, drop copy, and post-trade reports are described on the Pre-trade Pipeline page.
- 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 Go 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 - per-account queues for concurrent submission.
- Threading Contract - goroutine migration and synchronization modes.
- Rejects and errors with stable reject codes.
Runnable end-to-end examples live in examples/go/:
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.
The native runtime library is embedded inside the Go module at build time using
Go's embed package. No network download happens at runtime.
On first use, the embedded library is extracted to the user cache directory
under a path that includes the SDK version and the GOOS-GOARCH target tuple.
Subsequent process starts find the cached file and skip extraction.
- Target selection uses
runtime.GOOSandruntime.GOARCH. - Extraction cache path:
<user-cache>/pit-go/<version>/<goos>-<goarch>/.
Environment overrides:
OPENPIT_RUNTIME_LIBRARY_PATH- use an explicit pre-extracted library path instead of the embedded copy; extraction is skipped entirely.OPENPIT_RUNTIME_CACHE_DIR- override the root directory for extraction instead of the OS user cache directory.
Install Go and golangci-lint before running local checks.
POSIX (Linux, macOS, etc)
Install a C compiler through your OS package manager. The Go SDK uses cgo. Optional: Just.
With Just:
just test-go-debug
just test-go-raceManual:
cargo build -p openpit-ffi --release --locked
cd bindings/go
export OPENPIT_RUNTIME_LIBRARY_PATH="$(pwd)/../../target/release/libopenpit_ffi.so"
# macOS: use libopenpit_ffi.dylib instead.
go test ./...
go test -race ./...Windows
Install LLVM and add
clang/lld to PATH. Optional: Just.
With Just:
just test-go-debug
just test-go-raceManual:
cargo build -p openpit-ffi --release --locked --target x86_64-pc-windows-msvc
$env:OPENPIT_RUNTIME_LIBRARY_PATH = `
(Resolve-Path target\x86_64-pc-windows-msvc\release\openpit_ffi.dll)
$env:CGO_ENABLED = "1"
$env:CC = "clang -fuse-ld=lld"
$env:CXX = "clang++ -fuse-ld=lld"
Push-Location bindings\go
go test ./...
go test -race ./...
Pop-Location