kraken_book/
lib.rs

1//! WASM-compatible orderbook engine for Kraken WebSocket API v2
2//!
3//! This crate provides the core orderbook data structures and checksum validation.
4//! It is designed to compile to both native and WASM targets.
5//!
6//! # Features
7//!
8//! - **Level 2 (L2)**: Aggregated price levels with checksum validation
9//! - **Level 3 (L3)**: Order-level tracking with FIFO queue semantics
10//!
11//! # Critical WASM Constraints
12//!
13//! - NO `std::time::Instant` (panics in WASM)
14//! - NO `tokio` (doesn't compile to WASM)
15//! - NO networking code
16//!
17//! # L2 Example
18//!
19//! ```
20//! use kraken_book::{Orderbook, OrderbookState};
21//! use kraken_types::BookData;
22//!
23//! let mut book = Orderbook::new("BTC/USD");
24//! assert_eq!(book.state(), OrderbookState::Uninitialized);
25//! ```
26//!
27//! # L3 Example
28//!
29//! ```
30//! use kraken_book::l3::{L3Book, L3Order, L3Side};
31//! use rust_decimal_macros::dec;
32//!
33//! let mut book = L3Book::new("BTC/USD", 10);
34//! book.add_order(L3Order::new("order1", dec!(100), dec!(1)), L3Side::Bid);
35//!
36//! if let Some(pos) = book.queue_position("order1") {
37//!     println!("Position: {}, Qty ahead: {}", pos.position, pos.qty_ahead);
38//! }
39//! ```
40
41pub mod checksum;
42pub mod history;
43pub mod l3;
44pub mod orderbook;
45pub mod storage;
46
47// Re-export main types
48pub use checksum::{
49    compute_checksum, compute_checksum_with_precision, ChecksumResult,
50    DEFAULT_PRICE_PRECISION, DEFAULT_QTY_PRECISION,
51};
52pub use history::{HistoryBuffer, TimestampedSnapshot};
53pub use orderbook::{ApplyResult, ChecksumMismatch, Orderbook, OrderbookSnapshot, OrderbookState};
54pub use storage::TreeBook;
55
56// Re-export L3 types at crate root for convenience
57pub use l3::{L3Book, L3BookSnapshot, L3ChecksumMismatch, L3Order, L3PriceLevel, L3Side, QueuePosition};