Option Chain Order Book - Options Market Making Infrastructure
A high-performance Rust library for options market making infrastructure, providing a complete Option Chain Order Book system built on top of OrderBook-rs, PriceLevel, and OptionStratLib.
Key Features
-
Lock-Free Architecture: Built on OrderBook-rs's lock-free data structures for maximum throughput in high-frequency trading scenarios.
-
Hierarchical Order Book Structure: Multi-level organization from underlying assets down to individual option contracts.
-
Multi-Expiration Option Chain Management: Handle hundreds of options across multiple strikes and expirations simultaneously.
-
Real-Time Order Book per Option: Individual order books for each option contract with full depth, powered by OrderBook-rs.
-
Thread-Safe Concurrent Access: Uses
DashMapfor concurrent access to order books across multiple threads. -
OptionStratLib Integration: Use Greeks calculation,
ExpirationDate,OptionStyle, and pricing models directly from OptionStratLib. -
Result-Based Error Handling: All fallible operations return
Result<T, Error>with descriptive error types.
Architecture
The library follows a hierarchical structure for option chain management:
UnderlyingOrderBookManager (manages all underlyings: BTC, ETH, SPX, etc.)
└── UnderlyingOrderBook (per underlying, all expirations for one asset)
└── ExpirationOrderBookManager (manages all expirations for underlying)
└── ExpirationOrderBook (per expiry date)
└── OptionChainOrderBook (per expiration, option chain)
└── StrikeOrderBookManager (manages all strikes)
└── StrikeOrderBook (per strike price, call/put pair)
└── OptionOrderBook (call or put)
└── OrderBook<T> (from OrderBook-rs)
This architecture enables:
- Efficient aggregation of Greeks and positions at any level
- Fast lookup of specific option contracts
- Scalable management of large option chains
- ATM strike lookup at any level
- Statistics aggregation across the hierarchy
Module Structure
| Module | Description |
|---|---|
[orderbook] |
Hierarchical order book structure with all managers |
[error] |
Error types and Result type alias |
[utils] |
Utility functions (e.g., date formatting) |
Core Components
Order Book Hierarchy ([orderbook])
- [
orderbook::UnderlyingOrderBookManager]: Top-level manager for all underlyings - [
orderbook::UnderlyingOrderBook]: All expirations for a single underlying - [
orderbook::ExpirationOrderBookManager]: Manages expirations for an underlying - [
orderbook::ExpirationOrderBook]: All strikes for a single expiration - [
orderbook::OptionChainOrderBook]: Option chain with strike management - [
orderbook::StrikeOrderBookManager]: Manages strikes for an expiration - [
orderbook::StrikeOrderBook]: Call/put pair at a strike price - [
orderbook::OptionOrderBook]: Single option order book - [
orderbook::Quote]: Two-sided market representation - [
orderbook::QuoteUpdate]: Quote change tracking
Example Usage
Creating a Hierarchical Order Book
use UnderlyingOrderBookManager;
use pos_or_panic;
use ExpirationDate;
use ;
let manager = new;
let exp_date = Days;
// Create BTC option chain (use block to drop guards)
// Get statistics
let stats = manager.stats;
Creating a Single Option Order Book
use OptionOrderBook;
use OptionStyle;
use ;
// Create an order book for a specific option
let book = new;
// Add limit orders
book.add_limit_order.unwrap;
book.add_limit_order.unwrap;
// Get the best quote
let quote = book.best_quote;
assert!;
Using OptionStratLib for Greeks
use pos_or_panic;
use ;
use ;
use ;
use dec;
let option = Options ;
let delta_value = delta.unwrap;
let gamma_value = gamma.unwrap;
Examples
The library includes comprehensive examples demonstrating each level of the hierarchy:
| Example | Description |
|---|---|
01_option_orderbook |
Single option order book operations |
02_strike_orderbook |
Strike level with call/put pairs |
03_chain_orderbook |
Option chain (all strikes for one expiration) |
04_expiration_orderbook |
Expiration level with term structure |
05_underlying_orderbook |
Underlying level (all expirations) |
06_full_hierarchy |
Complete hierarchy with trading scenarios |
Run examples with:
Benchmarks
Comprehensive benchmarks are available for all components:
- orderbook_bench: Single option order book operations
- strike_bench: Strike order book and manager operations
- chain_bench: Option chain order book operations
- expiration_bench: Expiration order book operations
- underlying_bench: Underlying order book operations
- hierarchy_bench: Full hierarchy traversal and trading scenarios
Run benchmarks with:
Performance Characteristics
Built on OrderBook-rs's lock-free architecture:
- Order Operations: O(log N) for add/cancel operations
- Best Quote Lookup: O(1) with caching
- Thread Safety: Lock-free operations for concurrent access
- Hierarchy Traversal: O(1) access via
DashMap
Dependencies
- orderbook-rs (0.4): Lock-free order book engine
- optionstratlib (0.13): Options pricing, Greeks, and strategy analysis
- dashmap (6.1): Concurrent hash map for thread-safe access
- rust_decimal (1.39): Precise decimal arithmetic
- thiserror (2.0): Error handling
- serde (1.0): Serialization support
🛠 Makefile Commands
This project includes a Makefile with common tasks to simplify development. Here's a list of useful commands:
🔧 Build & Run
🧪 Test & Quality
📦 Packaging & Docs
📈 Coverage & Benchmarks
🧪 Git & Workflow Helpers
🤖 GitHub Actions (via act)
ℹ️ Requires act for local workflow simulation and cargo-tarpaulin for coverage.
Contribution and Contact
We welcome contributions to this project! If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and ensure that the project still builds and all tests pass.
- Commit your changes and push your branch to your forked repository.
- Submit a pull request to the main repository.
If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:
Contact Information
- Author: Joaquín Béjar García
- Email: jb@taunais.com
- Telegram: @joaquin_bejar
- Repository: https://github.com/joaquinbejar/Option-Chain-OrderBook
- Documentation: https://docs.rs/option-chain-orderbook
We appreciate your interest and look forward to your contributions!
License: MIT