rust_order_book/journal.rs
1//! Types related to journaling operations for the order book.
2//!
3//! Journaling allows tracking a chronological log of operations
4//! (such as order submissions, cancellations, modifications)
5//! for replay, audit, or recovery purposes.
6
7use crate::{
8    enums::{JournalOp, OrderOptions},
9    order::{LimitOrder, OrderId},
10};
11use serde::{Deserialize, Serialize};
12use std::collections::{BTreeMap, HashMap, VecDeque};
13
14/// Represents a journal entry for an operation performed on the order book.
15///
16/// This struct is used to log operations such as order placements, cancellations,
17/// and modifications, allowing for features like replay, auditing, or persistence.
18///
19/// # Fields
20/// - `op_id`: Unique operation ID, useful for ordering or deduplication.
21/// - `ts`: Timestamp of when the operation was recorded (in milliseconds since epoch).
22/// - `op`: The type of operation performed (e.g., market, limit, cancel).
23/// - `o`: The payload or input associated with the operation.
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub struct JournalLog {
26    pub op_id: u64,
27    pub ts: i64,
28    pub op: JournalOp,
29    pub o: OrderOptions,
30}
31
32#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
33pub struct Snapshot {
34    pub orders: HashMap<OrderId, LimitOrder>,
35    pub bids: BTreeMap<u64, VecDeque<OrderId>>,
36    pub asks: BTreeMap<u64, VecDeque<OrderId>>,
37    pub last_op: u64,
38    pub next_order_id: OrderId,
39    pub ts: i64,
40}