nautilus_hyperliquid/common/
consts.rs1use std::{sync::LazyLock, time::Duration};
17
18use nautilus_model::{enums::OrderType, identifiers::Venue};
19use ustr::Ustr;
20
21pub const HYPERLIQUID: &str = "HYPERLIQUID";
22pub static HYPERLIQUID_VENUE: LazyLock<Venue> =
23 LazyLock::new(|| Venue::new(Ustr::from(HYPERLIQUID)));
24
25pub const HYPERLIQUID_WS_URL: &str = "wss://api.hyperliquid.xyz/ws";
26pub const HYPERLIQUID_INFO_URL: &str = "https://api.hyperliquid.xyz/info";
27pub const HYPERLIQUID_EXCHANGE_URL: &str = "https://api.hyperliquid.xyz/exchange";
28
29pub const HYPERLIQUID_TESTNET_WS_URL: &str = "wss://api.hyperliquid-testnet.xyz/ws";
30pub const HYPERLIQUID_TESTNET_INFO_URL: &str = "https://api.hyperliquid-testnet.xyz/info";
31pub const HYPERLIQUID_TESTNET_EXCHANGE_URL: &str = "https://api.hyperliquid-testnet.xyz/exchange";
32
33pub const NAUTILUS_BUILDER_ADDRESS: &str = "0x0c8d970c462726e014ad36f6c5a63e99db48a8e7";
36
37pub const HYPERLIQUID_CHAIN_ID: u64 = 421614;
39
40pub const HYPERLIQUID_POST_ONLY_WOULD_MATCH: &str =
42 "Post only order would have immediately matched";
43
44pub const HYPERLIQUID_SUPPORTED_ORDER_TYPES: &[OrderType] = &[
59 OrderType::Market, OrderType::Limit, OrderType::StopMarket, OrderType::StopLimit, OrderType::MarketIfTouched, OrderType::LimitIfTouched, ];
66
67pub const HYPERLIQUID_CONDITIONAL_ORDER_TYPES: &[OrderType] = &[
72 OrderType::StopMarket,
73 OrderType::StopLimit,
74 OrderType::MarketIfTouched,
75 OrderType::LimitIfTouched,
76];
77
78pub fn ws_url(is_testnet: bool) -> &'static str {
80 if is_testnet {
81 HYPERLIQUID_TESTNET_WS_URL
82 } else {
83 HYPERLIQUID_WS_URL
84 }
85}
86
87pub fn info_url(is_testnet: bool) -> &'static str {
89 if is_testnet {
90 HYPERLIQUID_TESTNET_INFO_URL
91 } else {
92 HYPERLIQUID_INFO_URL
93 }
94}
95
96pub fn exchange_url(is_testnet: bool) -> &'static str {
98 if is_testnet {
99 HYPERLIQUID_TESTNET_EXCHANGE_URL
100 } else {
101 HYPERLIQUID_EXCHANGE_URL
102 }
103}
104
105pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(30);
108pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
109pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
110pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
111pub const INFLIGHT_MAX: usize = 100;
113pub const QUEUE_MAX: usize = 1000;
114
115#[cfg(test)]
116mod tests {
117 use rstest::rstest;
118
119 use super::*;
120
121 #[rstest]
122 fn test_ws_url() {
123 assert_eq!(ws_url(false), HYPERLIQUID_WS_URL);
124 assert_eq!(ws_url(true), HYPERLIQUID_TESTNET_WS_URL);
125 }
126
127 #[rstest]
128 fn test_info_url() {
129 assert_eq!(info_url(false), HYPERLIQUID_INFO_URL);
130 assert_eq!(info_url(true), HYPERLIQUID_TESTNET_INFO_URL);
131 }
132
133 #[rstest]
134 fn test_exchange_url() {
135 assert_eq!(exchange_url(false), HYPERLIQUID_EXCHANGE_URL);
136 assert_eq!(exchange_url(true), HYPERLIQUID_TESTNET_EXCHANGE_URL);
137 }
138
139 #[rstest]
140 fn test_constants_values() {
141 assert_eq!(HEARTBEAT_INTERVAL, Duration::from_secs(30));
142 assert_eq!(RECONNECT_BASE_BACKOFF, Duration::from_millis(250));
143 assert_eq!(RECONNECT_MAX_BACKOFF, Duration::from_secs(30));
144 assert_eq!(HTTP_TIMEOUT, Duration::from_secs(10));
145 assert_eq!(INFLIGHT_MAX, 100);
146 assert_eq!(QUEUE_MAX, 1000);
147 }
148}