| Crates.io | limitbook |
| lib.rs | limitbook |
| version | 0.1.0 |
| created_at | 2025-08-08 18:57:05.819755+00 |
| updated_at | 2025-08-08 18:57:05.819755+00 |
| description | High-performance Central Limit Order Book (CLOB) implementation with nanosecond-level matching |
| homepage | https://github.com/solarpx/limitbook |
| repository | https://github.com/solarpx/limitbook |
| max_upload_size | |
| id | 1787233 |
| size | 84,337 |
A Rust implementation of a high-performance in-memory Central Limit Order Book (CLOB) that supports limit and market orders with price-time priority matching.
The project uses standard Rust tooling. All dependencies are managed through Cargo.
BTreeMap for ordered price levelsVecDeque for time priority within price levelsHashMap for O(1) order lookupuse rust_decimal_macros::dec;
use orderbook::{OrderBook, OrderSide};
// Create a new order book with 0.01 tick size
let mut book = OrderBook::new(dec!(0.01));
// Add a limit sell order
let (sell_id, _) = book.add_limit_order(
OrderSide::Sell,
dec!(100.00), // Price
dec!(50), // Quantity
);
// Add a limit buy order that crosses the book
let (buy_id, fills) = book.add_limit_order(
OrderSide::Buy,
dec!(100.00), // Price matches -> will execute
dec!(25), // Quantity
);
// Execute a market order
let fills = book.execute_market_order(
OrderSide::Buy,
dec!(25),
).unwrap();
// Cancel an order
book.cancel_limit_order(sell_id)?;
Price Level Organization: BTreeMap<Tick, Orders>
Order Storage: VecDeque<Order>
Order Lookup: HashMap<OrderId, (OrderSide, Tick)>
The matching logic follows standard price-time priority:
Limit Orders:
Market Orders:
# Build the project
cargo build
# Run the test suite
cargo test
# Run benchmarks
cargo bench
Comprehensive test suite covering:
This section describes the benchmarks and performance characteristics of the order book implementation.
Limit Order (No Cross)
Limit Order (With Cross)
Market Order
Cancel Order
Data Structure Choice
Memory vs Speed Trade-offs
Our order book implementation achieves excellent performance:
Limit Orders: 3-5 million orders/second
Market Orders: ~31ns (~30 million/second)
Cancellations: ~31ns (~30 million/second)
These results demonstrate that our choice of data structures (BTreeMap for price levels, VecDeque for order queues, HashMap for lookups) provides an excellent balance of functionality and performance. The implementation can handle high-frequency trading scenarios while maintaining clean, safe Rust code.
Note: Benchmarks run on a standard development machine. Real-world performance may vary based on market conditions, order book depth, and system load.