hyperliquid_sdk_rs/
constants.rs

1// ==================== Network Configuration ====================
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum Network {
5    Mainnet,
6    Testnet,
7}
8
9impl Network {
10    pub fn api_url(&self) -> &'static str {
11        match self {
12            Network::Mainnet => "https://api.hyperliquid.xyz",
13            Network::Testnet => "https://api.hyperliquid-testnet.xyz",
14        }
15    }
16
17    pub fn ws_url(&self) -> &'static str {
18        match self {
19            Network::Mainnet => "wss://api.hyperliquid.xyz/ws",
20            Network::Testnet => "wss://api.hyperliquid-testnet.xyz/ws",
21        }
22    }
23}
24
25// ==================== Chain Configuration ====================
26
27// Chain IDs
28pub const CHAIN_ID_MAINNET: u64 = 42161; // Arbitrum One
29pub const CHAIN_ID_TESTNET: u64 = 421614; // Arbitrum Sepolia
30
31// Agent Sources
32pub const AGENT_SOURCE_MAINNET: &str = "a";
33pub const AGENT_SOURCE_TESTNET: &str = "b";
34
35// Exchange Endpoints
36pub const EXCHANGE_ENDPOINT_MAINNET: &str = "https://api.hyperliquid.xyz/exchange";
37pub const EXCHANGE_ENDPOINT_TESTNET: &str =
38    "https://api.hyperliquid-testnet.xyz/exchange";
39
40// ==================== Rate Limit Weights ====================
41
42// Info endpoints
43pub const WEIGHT_ALL_MIDS: u32 = 2;
44pub const WEIGHT_L2_BOOK: u32 = 1;
45pub const WEIGHT_USER_STATE: u32 = 2;
46pub const WEIGHT_USER_FILLS: u32 = 2;
47pub const WEIGHT_USER_FUNDING: u32 = 2;
48pub const WEIGHT_USER_FEES: u32 = 1;
49pub const WEIGHT_OPEN_ORDERS: u32 = 1;
50pub const WEIGHT_ORDER_STATUS: u32 = 1;
51pub const WEIGHT_RECENT_TRADES: u32 = 1;
52pub const WEIGHT_CANDLES: u32 = 2;
53pub const WEIGHT_FUNDING_HISTORY: u32 = 2;
54pub const WEIGHT_TOKEN_BALANCES: u32 = 1;
55pub const WEIGHT_REFERRAL: u32 = 1;
56
57// Exchange endpoints (these have higher weights)
58pub const WEIGHT_PLACE_ORDER: u32 = 3;
59pub const WEIGHT_CANCEL_ORDER: u32 = 2;
60pub const WEIGHT_MODIFY_ORDER: u32 = 3;
61pub const WEIGHT_BULK_ORDER: u32 = 10;
62pub const WEIGHT_BULK_CANCEL: u32 = 8;
63
64// ==================== Rate Limit Configuration ====================
65
66pub const RATE_LIMIT_MAX_TOKENS: u32 = 1200;
67pub const RATE_LIMIT_REFILL_RATE: u32 = 600; // per minute
68
69// ==================== Time Constants ====================
70
71pub const NONCE_WINDOW_MS: u64 = 60_000; // 60 seconds
72
73// ==================== Order Constants ====================
74
75pub const TIF_GTC: &str = "Gtc";
76pub const TIF_IOC: &str = "Ioc";
77pub const TIF_ALO: &str = "Alo";
78
79pub const TPSL_TP: &str = "tp";
80pub const TPSL_SL: &str = "sl";