use crate::orderbooks::delta::NormalizedDelta;
use serde::Deserialize;
#[derive(Deserialize, Debug, Clone)]
pub struct BinanceDepthUpdate {
#[serde(rename = "e")]
pub event_type: String,
#[serde(rename = "E")]
pub event_time: u64,
#[serde(rename = "s")]
pub symbol: String,
#[serde(rename = "U")]
pub first_update_id: u64,
#[serde(rename = "u")]
pub last_update_id: u64,
#[serde(rename = "b")]
pub bids: Vec<[String; 2]>,
#[serde(rename = "a")]
pub asks: Vec<[String; 2]>,
}
impl BinanceDepthUpdate {
pub fn to_normalized(&self) -> NormalizedDelta {
NormalizedDelta {
symbol: self.symbol.clone(),
bids: self
.bids
.iter()
.map(|l| (l[0].clone(), l[1].clone()))
.collect(),
asks: self
.asks
.iter()
.map(|l| (l[0].clone(), l[1].clone()))
.collect(),
update_id: self.last_update_id,
sequence: self.first_update_id,
is_snapshot: false,
}
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct BinanceDepthSnapshot {
#[serde(rename = "lastUpdateId")]
pub last_update_id: u64,
pub bids: Vec<[String; 2]>,
pub asks: Vec<[String; 2]>,
}
impl BinanceDepthSnapshot {
pub fn to_normalized(&self, symbol: &str) -> NormalizedDelta {
NormalizedDelta {
symbol: symbol.to_string(),
bids: self
.bids
.iter()
.map(|l| (l[0].clone(), l[1].clone()))
.collect(),
asks: self
.asks
.iter()
.map(|l| (l[0].clone(), l[1].clone()))
.collect(),
update_id: self.last_update_id,
sequence: self.last_update_id,
is_snapshot: true,
}
}
}