@@ -6,74 +6,105 @@ pub struct BinanceStreamWrapper<T> {
66 pub data : T ,
77}
88
9- #[ derive( Debug , Deserialize , Serialize ) ]
9+ #[ derive( Debug , Serialize , Deserialize ) ]
10+ #[ serde( from = "RawTicker" ) ]
1011pub struct BinanceTicker {
11- #[ serde( rename = "e" ) ]
1212 pub event_type : String ,
13- #[ serde( rename = "E" ) ]
1413 pub event_time : u64 ,
15- #[ serde( rename = "s" ) ]
1614 pub symbol : String ,
17- #[ serde( rename = "a" ) ]
1815 pub agg_trade_id : u64 ,
19- #[ serde( rename = "p" ) ]
2016 pub price : String ,
21- #[ serde( rename = "q" ) ]
2217 pub quantity : String ,
23- #[ serde( rename = "f" ) ]
2418 pub first_trade_id : u64 ,
25- #[ serde( rename = "l" ) ]
2619 pub last_trade_id : u64 ,
27- #[ serde( rename = "T" ) ]
2820 pub trade_time : u64 ,
29- #[ serde( rename = "m" ) ]
3021 pub is_buyer_market_maker : bool ,
31- #[ serde( rename = "M" ) ]
3222 pub ignore : bool ,
3323}
3424
35- #[ derive( Debug , Deserialize , Serialize ) ]
25+ #[ derive( Deserialize ) ]
26+ struct RawTicker {
27+ e : String , E : u64 , s : String , a : u64 , p : String , q : String ,
28+ f : u64 , l : u64 , T : u64 , m : bool , M : bool ,
29+ }
30+
31+ impl From < RawTicker > for BinanceTicker {
32+ fn from ( r : RawTicker ) -> Self {
33+ Self {
34+ event_type : r. e , event_time : r. E , symbol : r. s , agg_trade_id : r. a ,
35+ price : r. p , quantity : r. q , first_trade_id : r. f , last_trade_id : r. l ,
36+ trade_time : r. T , is_buyer_market_maker : r. m , ignore : r. M ,
37+ }
38+ }
39+ }
40+
41+ #[ derive( Debug , Serialize , Deserialize ) ]
42+ #[ serde( from = "RawDepth" ) ]
3643pub struct BinanceDepth {
37- #[ serde( rename = "u" ) ]
3844 pub last_update_id : u64 ,
39- #[ serde( rename = "b" ) ]
4045 pub bids : Vec < [ String ; 2 ] > ,
41- #[ serde( rename = "a" ) ]
4246 pub asks : Vec < [ String ; 2 ] > ,
4347}
4448
45- #[ derive( Debug , Deserialize , Serialize ) ]
49+ #[ derive( Deserialize ) ]
50+ struct RawDepth {
51+ u : u64 , b : Vec < [ String ; 2 ] > , a : Vec < [ String ; 2 ] > ,
52+ }
53+
54+ impl From < RawDepth > for BinanceDepth {
55+ fn from ( r : RawDepth ) -> Self {
56+ Self { last_update_id : r. u , bids : r. b , asks : r. a }
57+ }
58+ }
59+
60+ #[ derive( Debug , Serialize , Deserialize ) ]
61+ #[ serde( from = "RawLiquidation" ) ]
4662pub struct BinanceLiquidation {
47- #[ serde( rename = "e" ) ]
4863 pub event_type : String ,
49- #[ serde( rename = "E" ) ]
5064 pub event_time : u64 ,
51- #[ serde( rename = "o" ) ]
5265 pub order : Order ,
5366}
5467
55- #[ derive( Debug , Deserialize , Serialize ) ]
68+ #[ derive( Deserialize ) ]
69+ struct RawLiquidation {
70+ e : String , E : u64 , o : Order ,
71+ }
72+
73+ impl From < RawLiquidation > for BinanceLiquidation {
74+ fn from ( r : RawLiquidation ) -> Self {
75+ Self { event_type : r. e , event_time : r. E , order : r. o }
76+ }
77+ }
78+
79+ #[ derive( Debug , Serialize , Deserialize ) ]
80+ #[ serde( from = "RawOrder" ) ]
5681pub struct Order {
57- #[ serde( rename = "s" ) ]
5882 pub symbol : String ,
59- #[ serde( rename = "S" ) ]
6083 pub side : String ,
61- #[ serde( rename = "o" ) ]
6284 pub order_type : String ,
63- #[ serde( rename = "f" ) ]
6485 pub time_in_force : String ,
65- #[ serde( rename = "q" ) ]
6686 pub original_quantity : String ,
67- #[ serde( rename = "p" ) ]
6887 pub price : String ,
69- #[ serde( rename = "ap" ) ]
7088 pub average_price : String ,
71- #[ serde( rename = "X" ) ]
7289 pub order_status : String ,
73- #[ serde( rename = "l" ) ]
7490 pub last_filled_quantity : String ,
75- #[ serde( rename = "z" ) ]
7691 pub cumulative_filled_quantity : String ,
77- #[ serde( rename = "T" ) ]
7892 pub order_trade_time : u64 ,
7993}
94+
95+ #[ derive( Deserialize ) ]
96+ struct RawOrder {
97+ s : String , S : String , o : String , f : String , q : String ,
98+ p : String , ap : String , X : String , l : String , z : String , T : u64 ,
99+ }
100+
101+ impl From < RawOrder > for Order {
102+ fn from ( r : RawOrder ) -> Self {
103+ Self {
104+ symbol : r. s , side : r. S , order_type : r. o , time_in_force : r. f ,
105+ original_quantity : r. q , price : r. p , average_price : r. ap ,
106+ order_status : r. X , last_filled_quantity : r. l ,
107+ cumulative_filled_quantity : r. z , order_trade_time : r. T ,
108+ }
109+ }
110+ }
0 commit comments