Skip to main content

Crate fin_primitives

Crate fin_primitives 

Source
Expand description

§fin-primitives

A zero-panic, decimal-precise foundation for high-frequency trading and quantitative systems in Rust.

§Features

ModuleWhat it providesKey guarantee
typesPrice, Quantity, Symbol, NanoTimestamp, Side newtypesValidation at construction; no invalid value can exist at runtime
tickTick, TickFilter, TickReplayerFilter is pure; replayer yields ticks in ascending timestamp order
orderbookL2 OrderBook with apply_delta, spread, mid-price, VWAP, top-N levelsSequence validation; inverted spreads are detected and rolled back
ohlcvOhlcvBar, Timeframe, OhlcvAggregator, OhlcvSeriesBar invariants (high >= low, etc.) enforced on every push
signalsSignal trait, SignalPipeline, Sma, Ema, RsiReturns Unavailable until warm-up period is satisfied; no silent NaN
positionPosition, Fill, PositionLedgerVWAP average cost; realized and unrealized P&L net of commissions
riskDrawdownTracker, RiskRule trait, MaxDrawdownRule, MinEquityRule, RiskMonitorAll breaches returned as a typed Vec<RiskBreach>; never silently swallowed

§Design Principles

  • Zero panics. Every fallible operation returns Result<_, FinError>. No unwrap or expect in production code paths.
  • Decimal precision. All prices and quantities use rust_decimal::Decimal. Floating-point drift is structurally impossible.
  • Nanosecond timestamps. types::NanoTimestamp is a newtype over i64 nanoseconds since Unix epoch, suitable for microsecond-accurate event ordering.
  • Composable by design. risk::RiskRule, signals::Signal, and tick::TickFilter are traits; plug in your own implementations without forking.

§Errors

All error variants live in FinError (re-exported at the crate root). Every public fallible function documents which variant it may return.

All prices and quantities use rust_decimal::Decimal; never f64.

Re-exports§

pub use error::FinError;

Modules§

error
Error types for the fin-primitives crate.
ohlcv
Module: ohlcv
orderbook
Module: orderbook
position
Module: position
risk
Module: risk
signals
Module: signals
tick
Module: tick
types
Module: types