rustrade_data/exchange/binance/book/
mod.rs1use crate::books::Level;
2use rust_decimal::Decimal;
3use serde::{Deserialize, Serialize};
4
5pub mod l1;
7
8pub mod l2;
10
11#[derive(Clone, Copy, PartialEq, PartialOrd, Debug, Deserialize, Serialize)]
19pub struct BinanceLevel {
20 #[serde(with = "rust_decimal::serde::str")]
21 pub price: Decimal,
22 #[serde(with = "rust_decimal::serde::str")]
23 pub amount: Decimal,
24}
25
26impl From<BinanceLevel> for Level {
27 fn from(level: BinanceLevel) -> Self {
28 Self {
29 price: level.price,
30 amount: level.amount,
31 }
32 }
33}
34
35#[cfg(test)]
36#[allow(clippy::unwrap_used)] mod tests {
38 use super::*;
39
40 mod de {
41 use super::*;
42 use rust_decimal_macros::dec;
43
44 #[test]
45 fn test_binance_level() {
46 let input = r#"["4.00000200", "12.00000000"]"#;
47 assert_eq!(
48 serde_json::from_str::<BinanceLevel>(input).unwrap(),
49 BinanceLevel {
50 price: dec!(4.00000200),
51 amount: dec!(12.0)
52 },
53 )
54 }
55 }
56}