Skip to main content

chronicle-lob

Deterministic limit order book and matching engine in Rust, with zero hot-path allocation.

chronicle-lob maintains a single-market price-time limit order book on a bounded integer tick grid, matches incoming orders against resting liquidity, persists every accepted command to a checksummed write-ahead log, and rebuilds exact book state across crashes and checkpoints in bounded memory.

Docs · Architecture · Invariants · Performance · Releases

CI on main crates.io version PyPI version docs.rs MIT or Apache-2.0 license

A two-part view with live order book depth and durability telemetry above and real terminal runs below, executing book_session, wal_recovery across a snapshot and checkpoint seam, and the 1,000,000-operation zero-allocation proof

Every terminal line above comes from real runs of the book_session and wal_recovery examples and the alloc_proof test target, pinned and checked in continuous integration on Linux, macOS, and Windows.

Why chronicle-lob

Order books sit on the critical path of exchanges, matching simulators, risk gates, and historical replay pipelines. General-purpose collection types allocate on the heap during bursts, scatter resting orders across cache lines, and drift when hash iteration or wall-clock calls enter matching logic. chronicle-lob fixes memory layout up front and treats determinism as a hard invariant rather than an accident.

  • Strict price-time priority. Buy and sell orders rest on a bounded integer tick grid and match by best price first and arrival order second, always executing at the resting maker price.
  • Zero steady-state heap allocation. Orders live in a preallocated struct-of-arrays arena indexed by 32-bit slot indices, active price levels sit under a 64-ary hierarchical bitmap (O(bitmap depth) best-price and sparse level walks), and events write into a caller-owned EventBuffer.
  • Atomic preflight before mutation. Every command checks grid bounds, capacity, fill-or-kill liquidity, post-only crossing, and event buffer room before touching book state. A rejected command mutates nothing, emits zero events, and leaves sequence numbers untouched.
  • Four order types, priority-aware amend, mass cancel, and self-trade prevention. Supports Limit, Ioc, Fok, and PostOnly orders, quantity reductions that keep FIFO priority, price or size increases that re-queue at tail, single-call participant mass cancel, and per-order self-trade prevention policies.
  • Crash-safe persistence in bounded memory. chronicle-wal frames commands with Castagnoli CRC32C checksums, writes atomic snapshots and verified checkpoints, rejects crafted corrupt snapshots unconditionally in both debug and release builds, and streams verification, replay, and crash recovery in roughly 8 KiB of buffer space.
  • Pure standard-library core. chronicle-core has zero external dependencies, forbids unsafe code, reads no clock, and draws no ambient randomness.

Four verified chronicle-lob guarantees covering zero steady-state allocations across one million operations, zero external crates in chronicle-core, 8 KiB bounded streaming recovery, and dual-seed 10,000-case differential property sweeps

How it works

Inbound add, amend, cancel, and query commands flow into chronicle-core with preflight validation, 64-ary bitmaps, a struct-of-arrays arena, open-addressed ID lookup, checked u128 arithmetic, and caller EventBuffer, backed by chronicle-wal CRC32C frames and snapshots, producing deterministic execution events, exact crash recovery, and CLI operations

Crate Kind External runtime deps Role
chronicle-core library none (std only) Deterministic matching engine, 64-ary hierarchical bitmaps, SoA order arena, zero-allocation L2 and L3 book queries, and independent ReferenceBook differential oracle.
chronicle-wal library none (std only) Slicing-by-8 CRC32C write-ahead log, atomic snapshot codec with unconditional invariant checks, multi-cycle checkpointing, and bounded-memory streaming recovery.
chronicle-lob-cli binary (chronicle-cli) clap, serde, serde_json Operator CLI for verify, replay, snapshot, checkpoint, and seeded synthetic bench runs.

Quickstart

Install the operator CLI from crates.io, with cargo-binstall, or from PyPI, or add chronicle-core and chronicle-wal to a Rust project.

cargo install chronicle-lob-cli
# or install the CLI and Python SDK from PyPI
pip install chronicle-lob
[dependencies]
chronicle-core = "0.3"
chronicle-wal = "0.3"
import chronicle_lob

summary = chronicle_lob.bench(ops=100_000, seed=42)

Embedding the matching engine

Prices are plain integers in the smallest quote unit, and BookConfig defines the valid tick grid and arena capacity. Commands append typed ExecutionEvent records into a caller-owned buffer.

use chronicle_core::{
    Book, BookConfig, EventBuffer, ExecutionEvent, OrderId, OrderType,
    ParticipantId, Side, StpPolicy,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut book = Book::new(BookConfig {
        max_orders: 1024,
        grid_len: 4096,
        tick_size: 1,
        grid_start_tick: 0,
        default_stp: StpPolicy::CancelIncoming,
    })?;

    let mut storage: Vec<ExecutionEvent> = Vec::with_capacity(64);
    let mut events = EventBuffer::new(&mut storage);

    // Rest a sell order for 10 units at price 100.
    book.add_order(
        OrderId(1),
        ParticipantId(7),
        Side::Ask,
        OrderType::Limit,
        100,
        10,
        None,
        &mut events,
    )?;

    // A buy order at the same price trades with it in full.
    book.add_order(
        OrderId(2),
        ParticipantId(8),
        Side::Bid,
        OrderType::Limit,
        100,
        10,
        None,
        &mut events,
    )?;

    // storage now holds Accepted, Accepted, Trade, Filled, Filled events.
    assert_eq!(book.live_order_count(), 0);
    Ok(())
}

Persistence, checkpointing, and CLI inspection

The wal_recovery worked example writes a five-command trading session to a write-ahead log, saves a snapshot partway through, recovers the book from the snapshot and log tail, checkpoints the session onto a fresh log, and verifies recovery across the checkpoint seam.

The wal_recovery example recovering a book from its write-ahead log and checkpointing it, with the recovered book matching the live book

cargo run --locked -p chronicle-wal --example wal_recovery

chronicle-cli inspects, replays, snapshots, checkpoints, and benchmarks session files in bounded memory. Every subcommand accepts --seed and honours SIM_SEED.

chronicle-cli verify --wal session.wal --snapshot session.snapshot
snapshot: ok last_included_seq=3 live_orders=2
wal: ok frames=5 discarded=0 last_seq=5
verdict: ok
chronicle-cli replay --wal session.wal --snapshot session.snapshot
seed=0
4 amended order=1 price=99 qty=6
5 cancelled order=2 reason=requested
chronicle-cli bench --ops 100000 --seed 42 --json

Verification and performance

Run the full workspace verification gate locally.

cargo fmt --all -- --check
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
cargo test --workspace --locked
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked
cargo bench --workspace --locked -- --test

Property tests run the production Book lockstep against an independent BTreeMap and VecDeque ReferenceBook and compare full event streams and book snapshots after every command. Pull requests run 1,000 cases per property and main runs two independent 10,000-case sweeps on rotating seeds. Dedicated counting-allocator proof targets verify zero steady-state heap allocations across one million mixed commands, and CRC-recomputing structural mutation suites exercise snapshot and WAL decoders against adversarial byte tampering.

Per CHECK-DOC-1, measured Criterion baselines live exclusively in docs/PERFORMANCE.md alongside the exact benchmark name, book occupancy, commit hash, and runner class that produced them.

Documentation

If you want to... Read
Navigate every document in the repository Documentation index
Understand the arena, bitmaps, WAL framing, and snapshot byte layout Architecture · Decisions
Audit every correctness, durability, and allocation invariant Invariants and traceability matrix
Inspect recorded Criterion latency and throughput baselines Performance baseline
Check crate APIs and operator subcommands chronicle-core · chronicle-wal · chronicle-lob-cli
Review security scope, threat model, and release history Security policy · Roadmap · Changelog

Contributing

CONTRIBUTING.md covers toolchain setup, determinism rules, contract-first testing, and the pull request gate.

License

Licensed under either of MIT or Apache-2.0 at your option.

Metadata

Release files for chronicle-lob 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chronicle-lob 0.3.0
File Size Uploaded Provenance Actions
chronicle_lob-0.3.0.tar.gz 155.6 kB With provenance Details for chronicle_lob-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for chronicle-lob 0.3.0
File Actions
chronicle_lob-0.3.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for chronicle_lob-0.3.0-py3-none-win_amd64.whl
chronicle_lob-0.3.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for chronicle_lob-0.3.0-py3-none-manylinux_2_28_x86_64.whl
chronicle_lob-0.3.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for chronicle_lob-0.3.0-py3-none-manylinux_2_28_aarch64.whl
chronicle_lob-0.3.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for chronicle_lob-0.3.0-py3-none-macosx_11_0_arm64.whl
chronicle_lob-0.3.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for chronicle_lob-0.3.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 2.4 MB

Release files / chronicle_lob-0.3.0.tar.gz

Download URL chronicle_lob-0.3.0.tar.gz
Size 155.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0c225f9f2b4ebee4abfabb39cfa8d7c92d8c902d3edeb350df56c5c2e1f77b1e
BLAKE2b-256 checksum
How to use checksums
245ef55ef520bcd528b475f4fd41f0857470f653f529cd590a6d05a7033ee0b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / chronicle_lob-0.3.0-py3-none-win_amd64.whl

Download URL chronicle_lob-0.3.0-py3-none-win_amd64.whl
Size 397.8 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
4c933ca36080c09495990011b51f8ad1c57a10b8ea764bfea2e476083b1e510a
BLAKE2b-256 checksum
How to use checksums
75f8bb61cac0ddc89a268d9f013bb84a2f2e823b4c4761c2c33138d502220ce8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / chronicle_lob-0.3.0-py3-none-manylinux_2_28_x86_64.whl

Download URL chronicle_lob-0.3.0-py3-none-manylinux_2_28_x86_64.whl
Size 489.2 kB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
c079fe0f06da90c9ad8c50ea52c2f8964095fe40ccaa29a2c5dba78d976ada80
BLAKE2b-256 checksum
How to use checksums
b97b6190b85133c171d20397737ed343b300f9386e1c82167114a846a9f9e81d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / chronicle_lob-0.3.0-py3-none-manylinux_2_28_aarch64.whl

Download URL chronicle_lob-0.3.0-py3-none-manylinux_2_28_aarch64.whl
Size 464.7 kB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
97ad63676060ac6464adc678ee0fbdd14a6c70c39bd0c703cb895a3205fc50ed
BLAKE2b-256 checksum
How to use checksums
d8922646d79bdc2d8d12380109546d593348b5c6e746a02f2b58fe72e122a6d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / chronicle_lob-0.3.0-py3-none-macosx_11_0_arm64.whl

Download URL chronicle_lob-0.3.0-py3-none-macosx_11_0_arm64.whl
Size 459.9 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
00f08bd4729cc7410103e18028c6a9c33e0092cd67593f42083bf2b5423a7845
BLAKE2b-256 checksum
How to use checksums
ca77200e454aa9dce6bbed6b0e3239d9cd22fe7bb4516dbc02eecdc1618dc5dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / chronicle_lob-0.3.0-py3-none-macosx_10_12_x86_64.whl

Download URL chronicle_lob-0.3.0-py3-none-macosx_10_12_x86_64.whl
Size 474.4 kB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fd52446b4d703a583581c6551ac55024b433023088f543264065a943961f5192
BLAKE2b-256 checksum
How to use checksums
687f5e3857a85c4d5e82dab29d3eed26210b7e7bbbbf95d820b70cec05589c08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for chronicle-lob 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for chronicle_lob-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page