1use rust_decimal::Decimal;
2use serde::{self, Deserialize};
3
4#[derive(Debug, Deserialize)]
5#[serde(untagged)]
6#[serde(rename_all = "camelCase")]
7pub enum NotificationEvent {
8 Subscribed(SubscriptionMessage),
9 Pong(PongMessage),
10}
11
12#[derive(Debug, Deserialize)]
13#[serde(untagged)]
14#[serde(rename_all = "camelCase")]
15pub enum DataEvent {
16 TickerEvent(TickerData),
17 TradesEvent(TradesData),
18 OrderBookEvent(OrderBookData),
19 FillsEvent(FillsData),
20 OrdersEvent(OrdersData),
21}
22
23#[derive(Debug, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct SubscriptionMessage {
26 #[serde(rename = "type")]
27 pub option_type: String,
28 pub channel: String,
29 pub market: Option<String>,
30 pub grouping: Option<f64>,
31}
32
33#[derive(Debug, Deserialize)]
34#[serde(rename_all = "camelCase")]
35pub struct PongMessage {
36 #[serde(rename = "type")]
37 pub option_type: String,
38}
39
40#[derive(Debug, Deserialize)]
41pub struct TradeInfo {
42 pub id: i64,
43 pub price: Decimal,
44 pub size: Decimal,
45 pub side: String,
46 pub liquidation: bool,
47 pub time: String,
48}
49
50#[derive(Debug, Deserialize)]
51#[serde(rename_all = "camelCase")]
52pub struct TradesData {
53 pub channel: String,
54 pub market: String,
55 #[serde(rename = "type")]
56 pub option_type: String,
57 pub data: Vec<TradeInfo>,
58}
59
60#[derive(Debug, Deserialize)]
61pub struct OrderBookInfo {
62 pub time: Decimal,
63 pub checksum: i64,
64 pub bids: Vec<Vec<Decimal>>,
65 pub asks: Vec<Vec<Decimal>>,
66 pub action: String,
67}
68
69#[derive(Debug, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct OrderBookData {
72 pub channel: String,
73 pub market: String,
74 #[serde(rename = "type")]
75 pub option_type: String,
76 pub data: OrderBookInfo,
77}
78
79#[derive(Debug, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct TickerInfo {
82 pub bid: Decimal,
83 pub ask: Decimal,
84 pub bid_size: Decimal,
85 pub ask_size: Decimal,
86 pub last: Decimal,
87 pub time: Decimal,
88}
89
90#[derive(Debug, Deserialize)]
91#[serde(rename_all = "camelCase")]
92pub struct TickerData {
93 pub channel: String,
94 pub market: String,
95 #[serde(rename = "type")]
96 pub option_type: String,
97 pub data: TickerInfo,
98}
99
100#[derive(Debug, Deserialize)]
101#[serde(rename_all = "camelCase")]
102pub struct FillInfo {
103 pub fee: Decimal,
104 pub fee_rate: Decimal,
105 pub future: String,
106 pub id: i64,
107 pub liquidity: String,
108 pub market: String,
109 pub order_id: i64,
110 pub trade_id: i64,
111 pub price: Decimal,
112 pub side: String,
113 pub size: Decimal,
114 pub time: String,
115 #[serde(rename = "type")]
116 pub option_type: String,
117}
118
119#[derive(Debug, Deserialize)]
120#[serde(rename_all = "camelCase")]
121pub struct FillsData {
122 pub channel: String,
123 #[serde(rename = "type")]
124 pub option_type: String,
125 pub data: FillInfo,
126}
127
128#[derive(Debug, Deserialize)]
129#[serde(rename_all = "camelCase")]
130pub struct OrderInfo {
131 pub id: i64,
132 pub client_id: Option<String>,
133 pub market: String,
134 #[serde(rename = "type")]
135 pub option_type: String,
136 pub side: String,
137 pub size: Decimal,
138 pub price: Decimal,
139 pub reduce_only: bool,
140 pub ioc: bool,
141 pub post_only: bool,
142 pub status: String,
143 pub filled_size: Decimal,
144 pub remaining_size: Decimal,
145 pub avg_fill_price: Decimal,
146}
147
148#[derive(Debug, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct OrdersData {
151 pub channel: String,
152 #[serde(rename = "type")]
153 pub option_type: String,
154 pub data: OrderInfo,
155}