Skip to main content

chronicle_core/
lib.rs

1//! chronicle-core: a single-threaded, deterministic limit order book and
2//! matching engine with zero steady-state heap allocation.
3//!
4//! The design contract is `docs/ARCHITECTURE.md` in the repository. The
5//! short version:
6//!
7//! - Orders live in a fixed-capacity struct-of-arrays arena and are
8//!   named only by [`OrderId`]. Raw slot handles never leave this crate.
9//! - Prices sit on a bounded tick grid. Active levels are tracked by
10//!   hierarchical bitmaps, so best bid and best ask cost a few word
11//!   reads, independent of how many levels are live.
12//! - An open-addressed table with backward-shift deletion maps
13//!   [`OrderId`] to arena slots at a load factor of at most 50 percent.
14//! - Every mutating command validates and preflights before it mutates,
15//!   so every rejection is atomic. Execution events are written into a
16//!   caller-owned buffer; a buffer that is too small is a typed error
17//!   returned before any state changes.
18//!
19//! This crate is strictly std-only, forbids unsafe code, reads no clock,
20//! and uses no process-seeded randomness. It is the deterministic core
21//! that `chronicle-wal` persists and `chronicle-cli` drives.
22#![forbid(unsafe_code)]
23
24pub(crate) mod arena;
25pub(crate) mod bitmap;
26pub(crate) mod book;
27pub(crate) mod config;
28pub(crate) mod error;
29pub(crate) mod events;
30pub(crate) mod level;
31pub(crate) mod lookup;
32pub(crate) mod types;
33
34#[cfg(test)]
35mod prop_tests;
36#[cfg(test)]
37mod reference_book;
38
39pub use book::{Book, DepthLevel, OrderInfo, OrdersAt};
40pub use config::BookConfig;
41pub use error::BookError;
42pub use events::{CancelReason, EventBuffer, ExecutionEvent};
43pub use types::{
44    LevelState, LiveOrderState, OrderId, OrderType, ParticipantId, Side, SnapshotState, StpPolicy,
45};
46
47#[cfg(doctest)]
48#[doc = include_str!("../README.md")]
49struct ReadmeDoctests;