1use ethers::types::H160;
2use serde::Deserialize;
3use std::collections::HashMap;
4
5#[derive(Deserialize, Clone, Debug)]
6pub struct Trade {
7 pub coin: String,
8 pub side: String,
9 pub px: String,
10 pub sz: String,
11 pub time: u64,
12 pub hash: String,
13 pub tid: u64,
14}
15
16#[derive(Deserialize, Clone, Debug)]
17pub struct BookLevel {
18 pub px: String,
19 pub sz: String,
20 pub n: u64,
21}
22
23#[derive(Deserialize, Clone, Debug)]
24pub struct L2BookData {
25 pub coin: String,
26 pub time: u64,
27 pub levels: Vec<Vec<BookLevel>>,
28}
29
30#[derive(Deserialize, Clone, Debug)]
31pub struct AllMidsData {
32 pub mids: HashMap<String, String>,
33}
34
35#[derive(Deserialize, Clone, Debug)]
36#[serde(rename_all = "camelCase")]
37pub struct TradeInfo {
38 pub coin: String,
39 pub side: String,
40 pub px: String,
41 pub sz: String,
42 pub time: u64,
43 pub hash: String,
44 pub start_position: String,
45 pub dir: String,
46 pub closed_pnl: String,
47 pub oid: u64,
48 pub cloid: Option<String>,
49 pub crossed: bool,
50 pub fee: String,
51 pub tid: u64,
52}
53
54#[derive(Deserialize, Clone, Debug)]
55pub struct UserFillsData {
56 pub user: H160,
57 pub fills: Vec<TradeInfo>,
58}
59
60#[derive(Deserialize, Clone, Debug)]
61#[serde(rename_all = "camelCase")]
62pub enum UserData {
63 Fills(Vec<TradeInfo>),
64 Funding(UserFunding),
65 Liquidation(Liquidation),
66 NonUserCancel(Vec<NonUserCancel>),
67}
68
69#[derive(Deserialize, Clone, Debug)]
70pub struct Liquidation {
71 pub lid: u64,
72 pub liquidator: String,
73 pub liquidated_user: String,
74 pub liquidated_ntl_pos: String,
75 pub liquidated_account_value: String,
76}
77
78#[derive(Deserialize, Clone, Debug)]
79pub struct NonUserCancel {
80 pub coin: String,
81 pub oid: u64,
82}
83
84#[derive(Deserialize, Clone, Debug)]
85pub struct CandleData {
86 #[serde(rename = "T")]
87 pub time_close: u64,
88 #[serde(rename = "c")]
89 pub close: String,
90 #[serde(rename = "h")]
91 pub high: String,
92 #[serde(rename = "i")]
93 pub interval: String,
94 #[serde(rename = "l")]
95 pub low: String,
96 #[serde(rename = "n")]
97 pub num_trades: u64,
98 #[serde(rename = "o")]
99 pub open: String,
100 #[serde(rename = "s")]
101 pub coin: String,
102 #[serde(rename = "t")]
103 pub time_open: u64,
104 #[serde(rename = "v")]
105 pub volume: String,
106}
107
108#[derive(Deserialize, Clone, Debug)]
109#[serde(rename_all = "camelCase")]
110pub struct OrderUpdate {
111 pub order: BasicOrder,
112 pub status: String,
113 pub status_timestamp: u64,
114}
115
116#[derive(Deserialize, Clone, Debug)]
117#[serde(rename_all = "camelCase")]
118pub struct BasicOrder {
119 pub coin: String,
120 pub side: String,
121 pub limit_px: String,
122 pub sz: String,
123 pub oid: u64,
124 pub timestamp: u64,
125 pub orig_sz: String,
126 pub cloid: Option<String>,
127}
128
129#[derive(Deserialize, Clone, Debug)]
130#[serde(rename_all = "camelCase")]
131pub struct UserFundingsData {
132 pub is_snapshot: Option<bool>,
133 pub user: H160,
134 pub fundings: Vec<UserFunding>,
135}
136
137#[derive(Deserialize, Clone, Debug)]
138#[serde(rename_all = "camelCase")]
139pub struct UserFunding {
140 pub time: u64,
141 pub coin: String,
142 pub usdc: String,
143 pub szi: String,
144 pub funding_rate: String,
145}
146
147#[derive(Deserialize, Clone, Debug)]
148#[serde(rename_all = "camelCase")]
149pub struct UserNonFundingLedgerUpdatesData {
150 pub is_snapshot: Option<bool>,
151 pub user: H160,
152 pub non_funding_ledger_updates: Vec<LedgerUpdateData>,
153}
154
155#[derive(Deserialize, Clone, Debug)]
156pub struct LedgerUpdateData {
157 pub time: u64,
158 pub hash: String,
159 pub delta: LedgerUpdate,
160}
161
162#[derive(Deserialize, Clone, Debug)]
163#[serde(rename_all = "camelCase")]
164#[serde(tag = "type")]
165pub enum LedgerUpdate {
166 Deposit(Deposit),
167 Withdraw(Withdraw),
168 InternalTransfer(InternalTransfer),
169 SubAccountTransfer(SubAccountTransfer),
170 LedgerLiquidation(LedgerLiquidation),
171 VaultDeposit(VaultDelta),
172 VaultCreate(VaultDelta),
173 VaultDistribution(VaultDelta),
174 VaultWithdraw(VaultWithdraw),
175 VaultLeaderCommission(VaultLeaderCommission),
176 AccountClassTransfer(AccountClassTransfer),
177 SpotTransfer(SpotTransfer),
178 SpotGenesis(SpotGenesis),
179}
180
181#[derive(Deserialize, Clone, Debug)]
182pub struct Deposit {
183 pub usdc: String,
184}
185
186#[derive(Deserialize, Clone, Debug)]
187pub struct Withdraw {
188 pub usdc: String,
189 pub nonce: u64,
190 pub fee: String,
191}
192
193#[derive(Deserialize, Clone, Debug)]
194pub struct InternalTransfer {
195 pub usdc: String,
196 pub user: H160,
197 pub destination: H160,
198 pub fee: String,
199}
200
201#[derive(Deserialize, Clone, Debug)]
202pub struct SubAccountTransfer {
203 pub usdc: String,
204 pub user: H160,
205 pub destination: H160,
206}
207
208#[derive(Deserialize, Clone, Debug)]
209#[serde(rename_all = "camelCase")]
210pub struct LedgerLiquidation {
211 pub account_value: u64,
212 pub leverage_type: String,
213 pub liquidated_positions: Vec<LiquidatedPosition>,
214}
215
216#[derive(Deserialize, Clone, Debug)]
217pub struct LiquidatedPosition {
218 pub coin: String,
219 pub szi: String,
220}
221
222#[derive(Deserialize, Clone, Debug)]
223pub struct VaultDelta {
224 pub vault: H160,
225 pub usdc: String,
226}
227
228#[derive(Deserialize, Clone, Debug)]
229#[serde(rename_all = "camelCase")]
230pub struct VaultWithdraw {
231 pub vault: H160,
232 pub user: H160,
233 pub requested_usd: String,
234 pub commission: String,
235 pub closing_cost: String,
236 pub basis: String,
237 pub net_withdrawn_usd: String,
238}
239
240#[derive(Deserialize, Clone, Debug)]
241pub struct VaultLeaderCommission {
242 pub user: H160,
243 pub usdc: String,
244}
245
246#[derive(Deserialize, Clone, Debug)]
247#[serde(rename_all = "camelCase")]
248pub struct AccountClassTransfer {
249 pub usdc: String,
250 pub to_perp: bool,
251}
252
253#[derive(Deserialize, Clone, Debug)]
254#[serde(rename_all = "camelCase")]
255pub struct SpotTransfer {
256 pub token: String,
257 pub amount: String,
258 pub usdc_value: String,
259 pub user: H160,
260 pub destination: H160,
261 pub fee: String,
262}
263
264#[derive(Deserialize, Clone, Debug)]
265pub struct SpotGenesis {
266 pub token: String,
267 pub amount: String,
268}
269
270#[derive(Deserialize, Clone, Debug)]
271pub struct NotificationData {
272 pub notification: String,
273}