hyperliquid_rust_sdk_extended/
meta.rs1use std::collections::HashMap;
2
3use alloy::primitives::B128;
4use serde::Deserialize;
5
6#[derive(Deserialize, Debug, Clone)]
7pub struct Meta {
8 pub universe: Vec<AssetMeta>,
9}
10
11#[derive(Deserialize, Debug, Clone)]
12pub struct SpotMeta {
13 pub universe: Vec<SpotAssetMeta>,
14 pub tokens: Vec<TokenInfo>,
15}
16
17impl SpotMeta {
18 pub fn add_pair_and_name_to_index_map(
19 &self,
20 mut coin_to_asset: HashMap<String, u32>,
21 ) -> HashMap<String, u32> {
22 let index_to_name: HashMap<usize, &str> = self
23 .tokens
24 .iter()
25 .map(|info| (info.index, info.name.as_str()))
26 .collect();
27
28 for asset in self.universe.iter() {
29 let spot_ind: u32 = 10000 + asset.index as u32;
30 let name_to_ind = (asset.name.clone(), spot_ind);
31
32 let Some(token_1_name) = index_to_name.get(&asset.tokens[0]) else {
33 continue;
34 };
35
36 let Some(token_2_name) = index_to_name.get(&asset.tokens[1]) else {
37 continue;
38 };
39
40 coin_to_asset.insert(format!("{token_1_name}/{token_2_name}"), spot_ind);
41 coin_to_asset.insert(name_to_ind.0, name_to_ind.1);
42 }
43
44 coin_to_asset
45 }
46}
47
48#[derive(Deserialize, Debug, Clone)]
49#[serde(untagged)]
50pub enum SpotMetaAndAssetCtxs {
51 SpotMeta(SpotMeta),
52 Context(Vec<SpotAssetContext>),
53}
54
55#[derive(Deserialize, Debug, Clone)]
56#[serde(untagged)]
57pub enum MetaAndAssetCtxs {
58 Meta(Meta),
59 Context(Vec<AssetContext>),
60}
61
62#[derive(Deserialize, Debug, Clone)]
63#[serde(rename_all = "camelCase")]
64pub struct SpotAssetContext {
65 pub day_ntl_vlm: String,
66 pub mark_px: String,
67 pub mid_px: Option<String>,
68 pub prev_day_px: String,
69 pub circulating_supply: String,
70 pub coin: String,
71}
72
73#[derive(Deserialize, Debug, Clone)]
74#[serde(rename_all = "camelCase")]
75pub struct AssetContext {
76 pub day_ntl_vlm: String,
77 pub funding: String,
78 pub impact_pxs: Option<Vec<String>>,
79 pub mark_px: String,
80 pub mid_px: Option<String>,
81 pub open_interest: String,
82 pub oracle_px: String,
83 pub premium: Option<String>,
84 pub prev_day_px: String,
85}
86
87#[derive(Deserialize, Debug, Clone)]
88#[serde(rename_all = "camelCase")]
89pub struct AssetMeta {
90 pub name: String,
91 pub sz_decimals: u32,
92 pub max_leverage: usize,
93 #[serde(default)]
94 pub only_isolated: Option<bool>,
95}
96
97#[derive(Deserialize, Debug, Clone)]
98#[serde(rename_all = "camelCase")]
99pub struct SpotAssetMeta {
100 pub tokens: [usize; 2],
101 pub name: String,
102 pub index: usize,
103 pub is_canonical: bool,
104}
105
106#[derive(Debug, Deserialize, Clone)]
107#[serde(rename_all = "camelCase")]
108pub struct TokenInfo {
109 pub name: String,
110 pub sz_decimals: u8,
111 pub wei_decimals: u8,
112 pub index: usize,
113 pub token_id: B128,
114 pub is_canonical: bool,
115}