1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::subscription::book::Level;
use serde::{Deserialize, Serialize};
pub mod l1;
pub mod l2;
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug, Deserialize, Serialize)]
pub struct BinanceLevel {
#[serde(deserialize_with = "barter_integration::de::de_str")]
pub price: f64,
#[serde(deserialize_with = "barter_integration::de::de_str")]
pub amount: f64,
}
impl From<BinanceLevel> for Level {
fn from(level: BinanceLevel) -> Self {
Self {
price: level.price,
amount: level.amount,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
mod de {
use super::*;
#[test]
fn test_binance_level() {
let input = r#"["4.00000200", "12.00000000"]"#;
assert_eq!(
serde_json::from_str::<BinanceLevel>(input).unwrap(),
BinanceLevel {
price: 4.00000200,
amount: 12.0
},
)
}
}
}