quicknode-hyperliquid-sdk 0.1.9

Hyperliquid SDK for Rust - Simple, performant trading client. HyperCore, HyperEVM, WebSocket and gRPC streams.
Documentation
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//! Info API client for Hyperliquid.
//!
//! Provides read-only queries for market data, account state, and more.

use serde_json::{json, Value};
use std::sync::Arc;

use crate::client::HyperliquidSDKInner;
use crate::error::Result;

/// Info API client
pub struct Info {
    inner: Arc<HyperliquidSDKInner>,
}

impl Info {
    pub(crate) fn new(inner: Arc<HyperliquidSDKInner>) -> Self {
        Self { inner }
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Market Metadata
    // ──────────────────────────────────────────────────────────────────────────

    /// Get exchange metadata (perp assets, decimals, etc.)
    pub async fn meta(&self) -> Result<Value> {
        self.inner.query_info(&json!({"type": "meta"})).await
    }

    /// Get spot metadata
    pub async fn spot_meta(&self) -> Result<Value> {
        self.inner.query_info(&json!({"type": "spotMeta"})).await
    }

    /// Get metadata with asset contexts (real-time funding, open interest)
    pub async fn meta_and_asset_ctxs(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "metaAndAssetCtxs"}))
            .await
    }

    /// Get spot metadata with contexts
    pub async fn spot_meta_and_asset_ctxs(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "spotMetaAndAssetCtxs"}))
            .await
    }

    /// Get exchange status
    pub async fn exchange_status(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "exchangeStatus"}))
            .await
    }

    /// Get all perp DEXes (HIP-3)
    pub async fn perp_dexes(&self) -> Result<Value> {
        self.inner.query_info(&json!({"type": "perpDexs"})).await
    }

    /// Get perp categories
    pub async fn perp_categories(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "perpCategories"}))
            .await
    }

    /// Get perp annotation for an asset
    pub async fn perp_annotation(&self, asset: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "perpAnnotation", "asset": asset}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Pricing
    // ──────────────────────────────────────────────────────────────────────────

    /// Get all mid prices
    pub async fn all_mids(&self, dex: Option<&str>) -> Result<Value> {
        let mut body = json!({"type": "allMids"});
        if let Some(d) = dex {
            body["dex"] = json!(d);
        }
        self.inner.query_info(&body).await
    }

    /// Get mid price for a single asset
    pub async fn get_mid(&self, asset: &str) -> Result<f64> {
        let mids = self.all_mids(None).await?;
        mids.get(asset)
            .and_then(|v| v.as_str())
            .and_then(|s| s.parse::<f64>().ok())
            .ok_or_else(|| crate::Error::ValidationError(format!("No price for {}", asset)))
    }

    /// Get L2 order book
    pub async fn l2_book(
        &self,
        coin: &str,
        n_sig_figs: Option<u32>,
        mantissa: Option<u32>,
    ) -> Result<Value> {
        let mut body = json!({"type": "l2Book", "coin": coin});
        if let Some(n) = n_sig_figs {
            body["nSigFigs"] = json!(n);
        }
        if let Some(m) = mantissa {
            body["mantissa"] = json!(m);
        }
        self.inner.query_info(&body).await
    }

    /// Get recent trades
    pub async fn recent_trades(&self, coin: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "recentTrades", "coin": coin}))
            .await
    }

    /// Get candlestick data
    pub async fn candles(
        &self,
        coin: &str,
        interval: &str,
        start_time: u64,
        end_time: Option<u64>,
    ) -> Result<Value> {
        let mut body = json!({
            "type": "candleSnapshot",
            "req": {
                "coin": coin,
                "interval": interval,
                "startTime": start_time,
            }
        });
        if let Some(end) = end_time {
            body["req"]["endTime"] = json!(end);
        }
        self.inner.query_info(&body).await
    }

    /// Get funding history
    pub async fn funding_history(
        &self,
        coin: &str,
        start_time: u64,
        end_time: Option<u64>,
    ) -> Result<Value> {
        let mut body = json!({
            "type": "fundingHistory",
            "coin": coin,
            "startTime": start_time,
        });
        if let Some(end) = end_time {
            body["endTime"] = json!(end);
        }
        self.inner.query_info(&body).await
    }

    /// Get predicted fundings
    pub async fn predicted_fundings(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "predictedFundings"}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // User Account Data
    // ──────────────────────────────────────────────────────────────────────────

    /// Get clearinghouse state (positions, margin)
    pub async fn clearinghouse_state(&self, user: &str, dex: Option<&str>) -> Result<Value> {
        let mut body = json!({"type": "clearinghouseState", "user": user});
        if let Some(d) = dex {
            body["dex"] = json!(d);
        }
        self.inner.query_info(&body).await
    }

    /// Get spot clearinghouse state (token balances)
    pub async fn spot_clearinghouse_state(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "spotClearinghouseState", "user": user}))
            .await
    }

    /// Get open orders
    pub async fn open_orders(&self, user: &str, dex: Option<&str>) -> Result<Value> {
        let mut body = json!({"type": "openOrders", "user": user});
        if let Some(d) = dex {
            body["dex"] = json!(d);
        }
        self.inner.query_info(&body).await
    }

    /// Get frontend open orders (enhanced)
    pub async fn frontend_open_orders(&self, user: &str, dex: Option<&str>) -> Result<Value> {
        let mut body = json!({"type": "frontendOpenOrders", "user": user});
        if let Some(d) = dex {
            body["dex"] = json!(d);
        }
        self.inner.query_info(&body).await
    }

    /// Get order status
    pub async fn order_status(&self, user: &str, oid: u64, dex: Option<&str>) -> Result<Value> {
        let mut body = json!({"type": "orderStatus", "user": user, "oid": oid});
        if let Some(d) = dex {
            body["dex"] = json!(d);
        }
        self.inner.query_info(&body).await
    }

    /// Get historical orders
    pub async fn historical_orders(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "historicalOrders", "user": user}))
            .await
    }

    /// Get user fills
    pub async fn user_fills(&self, user: &str, aggregate_by_time: bool) -> Result<Value> {
        self.inner
            .query_info(&json!({
                "type": "userFills",
                "user": user,
                "aggregateByTime": aggregate_by_time,
            }))
            .await
    }

    /// Get user fills by time range
    pub async fn user_fills_by_time(
        &self,
        user: &str,
        start_time: u64,
        end_time: Option<u64>,
    ) -> Result<Value> {
        let mut body = json!({
            "type": "userFillsByTime",
            "user": user,
            "startTime": start_time,
        });
        if let Some(end) = end_time {
            body["endTime"] = json!(end);
        }
        self.inner.query_info(&body).await
    }

    /// Get user funding payments
    pub async fn user_funding(
        &self,
        user: &str,
        start_time: Option<u64>,
        end_time: Option<u64>,
    ) -> Result<Value> {
        let mut body = json!({"type": "userFunding", "user": user});
        if let Some(start) = start_time {
            body["startTime"] = json!(start);
        }
        if let Some(end) = end_time {
            body["endTime"] = json!(end);
        }
        self.inner.query_info(&body).await
    }

    /// Get user fees
    pub async fn user_fees(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userFees", "user": user}))
            .await
    }

    /// Get user rate limit
    pub async fn user_rate_limit(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userRateLimit", "user": user}))
            .await
    }

    /// Get user role
    pub async fn user_role(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userRole", "user": user}))
            .await
    }

    /// Get sub-accounts
    pub async fn sub_accounts(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "subAccounts", "user": user}))
            .await
    }

    /// Get extra agents (API keys)
    pub async fn extra_agents(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "extraAgents", "user": user}))
            .await
    }

    /// Get portfolio history
    pub async fn portfolio(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "portfolio", "user": user}))
            .await
    }

    /// Get comprehensive web data
    pub async fn web_data2(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "webData2", "user": user}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Batch Queries
    // ──────────────────────────────────────────────────────────────────────────

    /// Batch query clearinghouse states for multiple users
    pub async fn batch_clearinghouse_states(&self, users: &[&str]) -> Result<Value> {
        self.inner
            .query_info(&json!({
                "type": "batchClearinghouseStates",
                "users": users,
            }))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Vaults
    // ──────────────────────────────────────────────────────────────────────────

    /// Get all vault summaries
    pub async fn vault_summaries(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "vaultSummaries"}))
            .await
    }

    /// Get vault details
    pub async fn vault_details(&self, vault_address: &str, user: Option<&str>) -> Result<Value> {
        let mut body = json!({"type": "vaultDetails", "vaultAddress": vault_address});
        if let Some(u) = user {
            body["user"] = json!(u);
        }
        self.inner.query_info(&body).await
    }

    /// Get user vault equities
    pub async fn user_vault_equities(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userVaultEquities", "user": user}))
            .await
    }

    /// Get leading vaults
    pub async fn leading_vaults(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "leadingVaults", "user": user}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Delegation & Staking
    // ──────────────────────────────────────────────────────────────────────────

    /// Get delegations
    pub async fn delegations(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "delegations", "user": user}))
            .await
    }

    /// Get delegator summary
    pub async fn delegator_summary(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "delegatorSummary", "user": user}))
            .await
    }

    /// Get delegator history
    pub async fn delegator_history(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "delegatorHistory", "user": user}))
            .await
    }

    /// Get delegator rewards
    pub async fn delegator_rewards(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "delegatorRewards", "user": user}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // TWAP
    // ──────────────────────────────────────────────────────────────────────────

    /// Get user TWAP slice fills
    pub async fn user_twap_slice_fills(&self, user: &str, limit: Option<u32>) -> Result<Value> {
        let mut body = json!({"type": "userTwapSliceFills", "user": user});
        if let Some(l) = limit {
            body["limit"] = json!(l);
        }
        self.inner.query_info(&body).await
    }

    /// Get user TWAP history
    pub async fn user_twap_history(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userTwapHistory", "user": user}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Borrow/Lend
    // ──────────────────────────────────────────────────────────────────────────

    /// Get borrow/lend user state
    pub async fn borrow_lend_user_state(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "borrowLendUserState", "user": user}))
            .await
    }

    /// Get borrow/lend reserve state
    pub async fn borrow_lend_reserve_state(&self, token: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "borrowLendReserveState", "token": token}))
            .await
    }

    /// Get all borrow/lend reserve states
    pub async fn all_borrow_lend_reserve_states(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "allBorrowLendReserveStates"}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Account Abstraction
    // ──────────────────────────────────────────────────────────────────────────

    /// Get user abstraction mode
    pub async fn user_abstraction(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userAbstraction", "user": user}))
            .await
    }

    /// Get user DEX abstraction mode
    pub async fn user_dex_abstraction(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userDexAbstraction", "user": user}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Misc
    // ──────────────────────────────────────────────────────────────────────────

    /// Get liquidatable positions
    pub async fn liquidatable(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "liquidatable"}))
            .await
    }

    /// Get max market order notionals
    pub async fn max_market_order_ntls(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "maxMarketOrderNtls"}))
            .await
    }

    /// Get max builder fee
    pub async fn max_builder_fee(&self, user: &str, builder: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({
                "type": "maxBuilderFee",
                "user": user,
                "builder": builder,
            }))
            .await
    }

    /// Get active asset data
    pub async fn active_asset_data(&self, user: &str, asset: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({
                "type": "activeAssetData",
                "user": user,
                "asset": asset,
            }))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Tokens / Spot
    // ──────────────────────────────────────────────────────────────────────────

    /// Get token details
    pub async fn token_details(&self, token_id: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "tokenDetails", "tokenId": token_id}))
            .await
    }

    /// Get spot deployment state for user
    pub async fn spot_deploy_state(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "spotDeployState", "user": user}))
            .await
    }

    /// Get spot pair deploy auction status
    pub async fn spot_pair_deploy_auction_status(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "spotPairDeployAuctionStatus"}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Additional Methods
    // ──────────────────────────────────────────────────────────────────────────

    /// Get user's referral information
    pub async fn referral(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "referral", "user": user}))
            .await
    }

    /// Get user's non-funding ledger updates (deposits, withdrawals, transfers)
    pub async fn user_non_funding_ledger_updates(
        &self,
        user: &str,
        start_time: Option<u64>,
        end_time: Option<u64>,
    ) -> Result<Value> {
        let mut body = json!({"type": "userNonFundingLedgerUpdates", "user": user});
        if let Some(start) = start_time {
            body["startTime"] = json!(start);
        }
        if let Some(end) = end_time {
            body["endTime"] = json!(end);
        }
        self.inner.query_info(&body).await
    }

    /// Get multi-sig signers for a user
    pub async fn user_to_multi_sig_signers(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "userToMultiSigSigners", "user": user}))
            .await
    }

    /// Get gossip root IPs for the network
    pub async fn gossip_root_ips(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "gossipRootIps"}))
            .await
    }

    /// Get perpetual deploy auction status
    pub async fn perp_deploy_auction_status(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "perpDeployAuctionStatus"}))
            .await
    }

    /// Get perps that are at their open interest cap
    pub async fn perps_at_open_interest_cap(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "perpsAtOpenInterestCap"}))
            .await
    }

    /// Get L1 validator votes
    pub async fn validator_l1_votes(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "validatorL1Votes"}))
            .await
    }

    /// Get list of approved builders for a user
    pub async fn approved_builders(&self, user: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "approvedBuilders", "user": user}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Extended Perp DEX Info
    // ──────────────────────────────────────────────────────────────────────────

    /// Get consolidated universe, margin tables, asset contexts across all DEXs
    pub async fn all_perp_metas(&self) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "allPerpMetas"}))
            .await
    }

    /// Get OI caps and transfer limits for builder-deployed markets
    pub async fn perp_dex_limits(&self, dex: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "perpDexLimits", "dex": dex}))
            .await
    }

    /// Get total net deposits for builder-deployed markets
    pub async fn perp_dex_status(&self, dex: &str) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "perpDexStatus", "dex": dex}))
            .await
    }

    // ──────────────────────────────────────────────────────────────────────────
    // Aligned Quote Token
    // ──────────────────────────────────────────────────────────────────────────

    /// Get aligned quote token information
    pub async fn aligned_quote_token_info(&self, token: u32) -> Result<Value> {
        self.inner
            .query_info(&json!({"type": "alignedQuoteTokenInfo", "token": token}))
            .await
    }
}