use crate::markets::Level;
use crate::utils::Dec;
use serde::Deserialize;
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(from = "RawBbo")]
pub struct Bbo {
pub coin: String,
pub time: u64,
pub bid: Option<Level>,
pub ask: Option<Level>,
}
#[derive(Deserialize)]
struct RawBbo {
coin: String,
time: u64,
bbo: (Option<Level>, Option<Level>),
}
impl From<RawBbo> for Bbo {
fn from(raw: RawBbo) -> Self {
let (bid, ask) = raw.bbo;
Bbo { coin: raw.coin, time: raw.time, bid, ask }
}
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct Mids {
#[serde(default)]
pub dex: String,
pub mids: crate::markets::mids::Mids,
}
impl Mids {
#[must_use]
pub fn get(&self, coin: &str) -> Option<Dec> {
self.mids.get(coin)
}
}
#[cfg(test)]
#[path = "tests/market.rs"]
mod tests;