
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.
Contact: [email protected].
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.
Install
go get go.openpit.dev/openpit
Quick Start
package 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()
reviews, err := reservation.Reviews()
if err != nil {
log.Fatal(err)
}
if len(reviews) > 0 {
// Leave unsent. On approval, rerun with Confirmed set.
// Add AlreadyHeld only if Spot Funds kept its own hold in the committed
// review.
reservation.Commit()
return
}
// 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.
What Is Inside
Examples
Runnable end-to-end examples live in
examples/go/:
Runtime Delivery
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.GOOS and runtime.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.RuntimeLibraryPath() reports which library the process loaded,
override or extracted copy.
OPENPIT_RUNTIME_CACHE_DIR - override the root directory for extraction
instead of the OS user cache directory.
Local Repository Testing
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-race
Manual:
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-race
Manual:
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
评论