use std::collections::BTreeMap;
use jiff::Timestamp;
use v_utils::trades::{PrecisionPriceQty, Timestamped};
#[derive(Clone, Debug, Default)]
pub struct BookShape {
pub ts_event: Timestamp,
pub ts_init: Timestamp,
pub ts_last: Timestamp,
pub prec: PrecisionPriceQty,
pub asks: BTreeMap<i32, u32>,
pub bids: BTreeMap<i32, u32>,
}
impl Timestamped for BookShape {
fn ts_event(&self) -> Timestamp {
self.ts_event
}
fn ts_init(&self) -> Timestamp {
self.ts_init
}
fn ts_last(&self) -> Timestamp {
self.ts_last
}
}
#[derive(Clone, Debug)]
pub enum BookUpdate {
Snapshot(BookShape),
BatchDelta {
shape: BookShape,
gapped: bool,
},
}
impl BookUpdate {
pub fn shape(&self) -> &BookShape {
match self {
Self::Snapshot(s) | Self::BatchDelta { shape: s, .. } => s,
}
}
}
impl Timestamped for BookUpdate {
fn ts_event(&self) -> Timestamp {
self.shape().ts_event
}
fn ts_init(&self) -> Timestamp {
self.shape().ts_init
}
fn ts_last(&self) -> Timestamp {
self.shape().ts_last
}
}