clob_sync/lib.rs
1//! A synchronous, high-performance Central Limit Order Book implementation in Rust
2//! featuring an in-memory architecture with zero-cost abstractions and type-safe financial
3//! primitives for ultra-low latency trading applications.
4//!
5//! ## Usage
6//!
7//! ```
8//! use clob_sync::prelude::*;
9//! use std::str::FromStr;
10//!
11//! fn main() -> Result<()> {
12//! let symbol = Symbol::from("BTC-USD");
13//! let mut book = InMemoryOrderBookFactory::create_order_book(symbol);
14//!
15//! let sell_order = Order::new(
16//! OrderType::Limit(Price::try_from("50000.50").unwrap()),
17//! Quantity::try_from("100.5").unwrap(),
18//! OrderSide::Sell,
19//! Symbol::from("BTC-USD"),
20//! );
21//!
22//! let sell_exec = book.execute(&sell_order)?;
23//! assert!(matches!(sell_exec, Executions::AllocatedNoExecutions));
24//!
25//! let buy_order = Order::new(
26//! OrderType::Limit(Price::try_from("50000.75").unwrap()),
27//! Quantity::try_from("75.25").unwrap(),
28//! OrderSide::Buy,
29//! Symbol::from("BTC-USD"),
30//! );
31//!
32//! let buy_exec = book.execute(&buy_order)?;
33//! assert!(matches!(buy_exec, Executions::Executed(_)));
34//!
35//! Ok(())
36//! }
37//! ```
38
39mod error;
40pub mod execution;
41pub mod order;
42pub mod order_book;
43pub mod order_book_side;
44pub mod prelude;
45
46pub use error::*;
47pub use order::*;
48pub use order_book::*;
49pub use prelude::f;
50
51pub mod __private {
52 pub trait Sealed {}
53}
54
55#[cfg(test)]
56pub mod insta_test_utils {
57 use insta::Settings;
58
59 pub fn insta_settings_with_masking_filters() -> Settings {
60 let mut settings = Settings::clone_current(); // inherit defaults [web:50]
61 settings.add_filter(
62 r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
63 "********-****-****-****-************",
64 );
65 settings
66 }
67}