use crate::orderbooks::{Orderbook, OrderbookDelta};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum OrderbookUpdateType {
Snapshot,
Delta,
}
#[derive(Debug, Clone)]
pub struct OrderbookUpdate {
pub update_type: OrderbookUpdateType,
pub bids_modified: usize,
pub asks_modified: usize,
pub levels_deleted: usize,
pub levels_inserted: usize,
pub was_reset: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderbookTarget {
Delta,
Snapshot,
}
#[derive(Debug)]
pub enum OrderbookTargetData {
Delta(OrderbookDelta),
Snapshot(Vec<Orderbook>),
}
impl OrderbookTargetData {
#[inline]
pub fn is_delta(&self) -> bool {
matches!(self, Self::Delta(_))
}
#[inline]
pub fn is_snapshot(&self) -> bool {
matches!(self, Self::Snapshot(_))
}
pub fn into_delta(self) -> Option<OrderbookDelta> {
match self {
Self::Delta(m) => Some(m),
Self::Snapshot(_) => None,
}
}
pub fn into_snapshot(self) -> Option<Vec<Orderbook>> {
match self {
Self::Delta(_) => None,
Self::Snapshot(obs) => Some(obs),
}
}
pub fn symbol(&self) -> &str {
match self {
Self::Delta(m) => m.symbol(),
Self::Snapshot(obs) => obs.first().map(|ob| ob.symbol.as_str()).unwrap_or(""),
}
}
pub fn len(&self) -> usize {
match self {
Self::Delta(_) => 1,
Self::Snapshot(obs) => obs.len(),
}
}
pub fn is_empty(&self) -> bool {
match self {
Self::Delta(_) => false,
Self::Snapshot(obs) => obs.is_empty(),
}
}
}