| Crates.io | otterbook_core |
| lib.rs | otterbook_core |
| version | 0.1.3 |
| created_at | 2025-07-09 16:17:13.88124+00 |
| updated_at | 2025-07-09 16:17:13.88124+00 |
| description | A high-performance, lock-free price level implementation for limit order books in Rust. This library provides the building blocks for creating efficient trading systems with support for multiple order types and concurrent access patterns. |
| homepage | https://github.com/toxicmaximalist/order-book |
| repository | https://github.com/toxicmaximalist/order-book |
| max_upload_size | |
| id | 1745096 |
| size | 252,927 |
A high-performance, thread-safe limit order book implementation written in Rust. This project provides a comprehensive order matching engine designed for low-latency trading systems, with a focus on concurrent access patterns and lock-free data structures.
Lock-Free Architecture: Built using atomics and lock-free data structures to minimize contention and maximize throughput in high-frequency trading scenarios.
Multiple Order Types: Support for various order types including standard limit orders, iceberg orders, post-only, fill-or-kill, immediate-or-cancel, good-till-date, trailing stop, pegged, market-to-limit, and reserve orders with custom replenishment logic.
Thread-Safe Price Levels: Each price level can be independently and concurrently modified by multiple threads without blocking.
Advanced Order Matching: Efficient matching algorithm that correctly handles complex order types and partial fills.
Performance Metrics: Built-in statistics tracking for benchmarking and monitoring system performance.
Memory Efficient: Designed to scale to millions of orders with minimal memory overhead.
This order book engine is built with the following design principles:
This project is currently in active development and is not yet suitable for production use.
This analyzes the performance of the OrderBook system based on tests conducted on an Apple M4 Max processor. The data comes from two types of tests: a High-Frequency Trading (HFT) simulation and contention pattern tests.
| Metric | Total Operations | Operations/Second |
|---|---|---|
| Orders Added | 587,937 | 117,563.67 |
| Orders Matched | 324,096 | 64,806.12 |
| Orders Cancelled | 4,063,600 | 812,555.98 |
| Total Operations | 4,975,633 | 994,925.77 |
| Metric | Initial State | Final State |
|---|---|---|
| Best Bid | 9,900 | 9,840 |
| Best Ask | 10,000 | 10,110 |
| Spread | 100 | 270 |
| Mid Price | 9,950.00 | 9,975.00 |
| Total Orders | 1,020 | 87,155 |
| Bid Price Levels | 21 | 10 |
| Ask Price Levels | 21 | 6 |
| Total Bid Quantity | 7,750 | 688,791 |
| Total Ask Quantity | 7,750 | 912,992 |
| Read % | Operations/Second |
|---|---|
| 0% | 716,117.91 |
| 25% | 32,470.83 |
| 50% | 29,525.75 |
| 75% | 35,949.69 |
| 95% | 73,484.17 |
| % Operations on Hot Spot | Operations/Second |
|---|---|
| 0% | 8,166,484.48 |
| 25% | 10,277,423.77 |
| 50% | 13,767,842.77 |
| 75% | 19,322,454.84 |
| 100% | 28,327,212.19 |
The system demonstrates an impressive capability to handle nearly 1 million operations per second in the high-frequency trading simulation, distributed across order creations, matches, and cancellations.
This analysis confirms that the system design is highly scalable and appropriate for demanding financial applications requiring high-speed processing with data consistency.
This project includes a Makefile with common tasks to simplify development. Here's a list of useful commands:
make build # Compile the project
make release # Build in release mode
make run # Run the main binary
make test # Run all tests
make fmt # Format code
make fmt-check # Check formatting without applying
make lint # Run clippy with warnings as errors
make lint-fix # Auto-fix lint issues
make fix # Auto-fix Rust compiler suggestions
make check # Run fmt-check + lint + test
make doc # Check for missing docs via clippy
make doc-open # Build and open Rust documentation
make create-doc # Generate internal docs
make readme # Regenerate README using cargo-readme
make publish # Prepare and publish crate to crates.io
make coverage # Generate code coverage report (XML)
make coverage-html # Generate HTML coverage report
make open-coverage # Open HTML report
make bench # Run benchmarks using Criterion
make bench-show # Open benchmark report
make bench-save # Save benchmark history snapshot
make bench-compare # Compare benchmark runs
make bench-json # Output benchmarks in JSON
make bench-clean # Remove benchmark data
make git-log # Show commits on current branch vs main
make check-spanish # Check for Spanish words in code
make zip # Create zip without target/ and temp files
make tree # Visualize project tree (excludes common clutter)
make workflow-build # Simulate build workflow
make workflow-lint # Simulate lint workflow
make workflow-test # Simulate test workflow
make workflow-coverage # Simulate coverage workflow
make workflow # Run all workflows
ℹ️ Requires act for local workflow simulation and cargo-tarpaulin for coverage.
We welcome contributions to this project! If you would like to contribute, please follow these steps:
If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:
Joaquín Béjar García
We appreciate your interest and look forward to your contributions!
License: MIT