fin-primitives
Financial market primitives for Rust — the foundational layer for high-frequency trading and quantitative systems.
What's inside
| Module | Description |
|---|---|
types |
Newtypes for Price, Quantity, Symbol, NanoTimestamp, Side with compile-time validation |
orderbook |
Lock-free BTreeMap order book with apply_delta, spread, top-N levels, sequence tracking |
tick |
Tick ingestion, TickFilter (symbol/price/volume gates), TickReplayer for backtesting |
ohlcv |
OHLCV bar construction and aggregation from tick streams, multi-timeframe support |
signals |
SMA, EMA, RSI — streaming indicators with configurable periods |
position |
Position ledger with average-cost tracking, realized/unrealized PnL, commission handling |
risk |
DrawdownTracker, MaxDrawdownRule, MinEquityRule, composable RiskMonitor |
Features
- Zero panics — every fallible operation returns
Result - Decimal precision — all prices and quantities use
rust_decimalto eliminate floating-point drift - Nanosecond timestamps — native
NanoTimestampnewtype for microsecond-accurate event ordering - Composable risk rules — chain multiple risk monitors; each breach is typed and detailed
Quick start
use ;
use ;
use ;
use dec;
let mut ledger = new;
let mut monitor = new
.add_rule;
// Apply a fill
ledger.apply_fill.unwrap;
// Check risk after price move
let prices = .into;
let equity = ledger.equity.unwrap;
let breaches = monitor.update;
for b in &breaches
Add to your project
[]
= { = "https://github.com/Mattbusel/fin-primitives" }
Test coverage
242 tests across unit, integration, and property suites. Run with: