Crate kraken_book

Crate kraken_book 

Source
Expand description

WASM-compatible orderbook engine for Kraken WebSocket API v2

This crate provides the core orderbook data structures and checksum validation. It is designed to compile to both native and WASM targets.

§Features

  • Level 2 (L2): Aggregated price levels with checksum validation
  • Level 3 (L3): Order-level tracking with FIFO queue semantics

§Critical WASM Constraints

  • NO std::time::Instant (panics in WASM)
  • NO tokio (doesn’t compile to WASM)
  • NO networking code

§L2 Example

use kraken_book::{Orderbook, OrderbookState};
use kraken_types::BookData;

let mut book = Orderbook::new("BTC/USD");
assert_eq!(book.state(), OrderbookState::Uninitialized);

§L3 Example

use kraken_book::l3::{L3Book, L3Order, L3Side};
use rust_decimal_macros::dec;

let mut book = L3Book::new("BTC/USD", 10);
book.add_order(L3Order::new("order1", dec!(100), dec!(1)), L3Side::Bid);

if let Some(pos) = book.queue_position("order1") {
    println!("Position: {}, Qty ahead: {}", pos.position, pos.qty_ahead);
}

Re-exports§

pub use checksum::compute_checksum;
pub use checksum::compute_checksum_with_precision;
pub use checksum::ChecksumResult;
pub use checksum::DEFAULT_PRICE_PRECISION;
pub use checksum::DEFAULT_QTY_PRECISION;
pub use history::HistoryBuffer;
pub use history::TimestampedSnapshot;
pub use orderbook::ApplyResult;
pub use orderbook::ChecksumMismatch;
pub use orderbook::Orderbook;
pub use orderbook::OrderbookSnapshot;
pub use orderbook::OrderbookState;
pub use storage::TreeBook;
pub use l3::L3Book;
pub use l3::L3BookSnapshot;
pub use l3::L3ChecksumMismatch;
pub use l3::L3Order;
pub use l3::L3PriceLevel;
pub use l3::L3Side;
pub use l3::QueuePosition;

Modules§

checksum
CRC32 checksum validation for orderbook integrity
history
Ring buffer for orderbook history (time-travel feature)
l3
Level 3 orderbook implementation
orderbook
Orderbook state machine
storage
BTreeMap-based orderbook storage