Thanks to visit codestin.com
Credit goes to docs.rs

hyperliquid_rust_sdk/ws/
sub_structs.rs

1use ethers::types::H160;
2use serde::{Deserialize, Serialize};
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 fee_token: String,
52    pub tid: u64,
53}
54
55#[derive(Deserialize, Clone, Debug)]
56#[serde(rename_all = "camelCase")]
57pub struct UserFillsData {
58    pub is_snapshot: Option<bool>,
59    pub user: H160,
60    pub fills: Vec<TradeInfo>,
61}
62
63#[derive(Deserialize, Clone, Debug)]
64#[serde(rename_all = "camelCase")]
65pub enum UserData {
66    Fills(Vec<TradeInfo>),
67    Funding(UserFunding),
68    Liquidation(Liquidation),
69    NonUserCancel(Vec<NonUserCancel>),
70}
71
72#[derive(Deserialize, Clone, Debug)]
73pub struct Liquidation {
74    pub lid: u64,
75    pub liquidator: String,
76    pub liquidated_user: String,
77    pub liquidated_ntl_pos: String,
78    pub liquidated_account_value: String,
79}
80
81#[derive(Deserialize, Clone, Debug)]
82pub struct NonUserCancel {
83    pub coin: String,
84    pub oid: u64,
85}
86
87#[derive(Deserialize, Clone, Debug)]
88pub struct CandleData {
89    #[serde(rename = "T")]
90    pub time_close: u64,
91    #[serde(rename = "c")]
92    pub close: String,
93    #[serde(rename = "h")]
94    pub high: String,
95    #[serde(rename = "i")]
96    pub interval: String,
97    #[serde(rename = "l")]
98    pub low: String,
99    #[serde(rename = "n")]
100    pub num_trades: u64,
101    #[serde(rename = "o")]
102    pub open: String,
103    #[serde(rename = "s")]
104    pub coin: String,
105    #[serde(rename = "t")]
106    pub time_open: u64,
107    #[serde(rename = "v")]
108    pub volume: String,
109}
110
111#[derive(Deserialize, Clone, Debug)]
112#[serde(rename_all = "camelCase")]
113pub struct OrderUpdate {
114    pub order: BasicOrder,
115    pub status: String,
116    pub status_timestamp: u64,
117}
118
119#[derive(Deserialize, Clone, Debug)]
120#[serde(rename_all = "camelCase")]
121pub struct BasicOrder {
122    pub coin: String,
123    pub side: String,
124    pub limit_px: String,
125    pub sz: String,
126    pub oid: u64,
127    pub timestamp: u64,
128    pub orig_sz: String,
129    pub cloid: Option<String>,
130}
131
132#[derive(Deserialize, Clone, Debug)]
133#[serde(rename_all = "camelCase")]
134pub struct UserFundingsData {
135    pub is_snapshot: Option<bool>,
136    pub user: H160,
137    pub fundings: Vec<UserFunding>,
138}
139
140#[derive(Deserialize, Clone, Debug)]
141#[serde(rename_all = "camelCase")]
142pub struct UserFunding {
143    pub time: u64,
144    pub coin: String,
145    pub usdc: String,
146    pub szi: String,
147    pub funding_rate: String,
148}
149
150#[derive(Deserialize, Clone, Debug)]
151#[serde(rename_all = "camelCase")]
152pub struct UserNonFundingLedgerUpdatesData {
153    pub is_snapshot: Option<bool>,
154    pub user: H160,
155    pub non_funding_ledger_updates: Vec<LedgerUpdateData>,
156}
157
158#[derive(Deserialize, Clone, Debug)]
159pub struct LedgerUpdateData {
160    pub time: u64,
161    pub hash: String,
162    pub delta: LedgerUpdate,
163}
164
165#[derive(Deserialize, Clone, Debug)]
166#[serde(rename_all = "camelCase")]
167#[serde(tag = "type")]
168pub enum LedgerUpdate {
169    Deposit(Deposit),
170    Withdraw(Withdraw),
171    InternalTransfer(InternalTransfer),
172    SubAccountTransfer(SubAccountTransfer),
173    LedgerLiquidation(LedgerLiquidation),
174    VaultDeposit(VaultDelta),
175    VaultCreate(VaultDelta),
176    VaultDistribution(VaultDelta),
177    VaultWithdraw(VaultWithdraw),
178    VaultLeaderCommission(VaultLeaderCommission),
179    AccountClassTransfer(AccountClassTransfer),
180    SpotTransfer(SpotTransfer),
181    SpotGenesis(SpotGenesis),
182}
183
184#[derive(Deserialize, Clone, Debug)]
185pub struct Deposit {
186    pub usdc: String,
187}
188
189#[derive(Deserialize, Clone, Debug)]
190pub struct Withdraw {
191    pub usdc: String,
192    pub nonce: u64,
193    pub fee: String,
194}
195
196#[derive(Deserialize, Clone, Debug)]
197pub struct InternalTransfer {
198    pub usdc: String,
199    pub user: H160,
200    pub destination: H160,
201    pub fee: String,
202}
203
204#[derive(Deserialize, Clone, Debug)]
205pub struct SubAccountTransfer {
206    pub usdc: String,
207    pub user: H160,
208    pub destination: H160,
209}
210
211#[derive(Deserialize, Clone, Debug)]
212#[serde(rename_all = "camelCase")]
213pub struct LedgerLiquidation {
214    pub account_value: u64,
215    pub leverage_type: String,
216    pub liquidated_positions: Vec<LiquidatedPosition>,
217}
218
219#[derive(Deserialize, Clone, Debug)]
220pub struct LiquidatedPosition {
221    pub coin: String,
222    pub szi: String,
223}
224
225#[derive(Deserialize, Clone, Debug)]
226pub struct VaultDelta {
227    pub vault: H160,
228    pub usdc: String,
229}
230
231#[derive(Deserialize, Clone, Debug)]
232#[serde(rename_all = "camelCase")]
233pub struct VaultWithdraw {
234    pub vault: H160,
235    pub user: H160,
236    pub requested_usd: String,
237    pub commission: String,
238    pub closing_cost: String,
239    pub basis: String,
240    pub net_withdrawn_usd: String,
241}
242
243#[derive(Deserialize, Clone, Debug)]
244pub struct VaultLeaderCommission {
245    pub user: H160,
246    pub usdc: String,
247}
248
249#[derive(Deserialize, Clone, Debug)]
250#[serde(rename_all = "camelCase")]
251pub struct AccountClassTransfer {
252    pub usdc: String,
253    pub to_perp: bool,
254}
255
256#[derive(Deserialize, Clone, Debug)]
257#[serde(rename_all = "camelCase")]
258pub struct SpotTransfer {
259    pub token: String,
260    pub amount: String,
261    pub usdc_value: String,
262    pub user: H160,
263    pub destination: H160,
264    pub fee: String,
265}
266
267#[derive(Deserialize, Clone, Debug)]
268pub struct SpotGenesis {
269    pub token: String,
270    pub amount: String,
271}
272
273#[derive(Deserialize, Clone, Debug)]
274pub struct NotificationData {
275    pub notification: String,
276}
277
278#[derive(Deserialize, Clone, Debug)]
279#[serde(rename_all = "camelCase")]
280pub struct WebData2Data {
281    pub user: H160,
282}
283
284#[derive(Deserialize, Clone, Debug)]
285#[serde(rename_all = "camelCase")]
286pub struct ActiveAssetCtxData {
287    pub coin: String,
288    pub ctx: AssetCtx,
289}
290
291#[derive(Deserialize, Serialize, Clone, Debug)]
292#[serde(rename_all = "camelCase")]
293#[serde(untagged)]
294pub enum AssetCtx {
295    Perps(PerpsAssetCtx),
296    Spot(SpotAssetCtx),
297}
298
299#[derive(Deserialize, Serialize, Clone, Debug)]
300#[serde(rename_all = "camelCase")]
301pub struct SharedAssetCtx {
302    pub day_ntl_vlm: String,
303    pub prev_day_px: String,
304    pub mark_px: String,
305    pub mid_px: Option<String>,
306}
307
308#[derive(Deserialize, Serialize, Clone, Debug)]
309#[serde(rename_all = "camelCase")]
310pub struct PerpsAssetCtx {
311    #[serde(flatten)]
312    pub shared: SharedAssetCtx,
313    pub funding: String,
314    pub open_interest: String,
315    pub oracle_px: String,
316}
317
318#[derive(Deserialize, Serialize, Clone, Debug)]
319#[serde(rename_all = "camelCase")]
320pub struct SpotAssetCtx {
321    #[serde(flatten)]
322    pub shared: SharedAssetCtx,
323    pub circulating_supply: String,
324}