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_FEE_ADDRESS: &str = "0x0c8d970c462726e014ad36f6c5a63e99db48a8e7";
39pub const NAUTILUS_BUILDER_FEE_TAKER_TENTHS_BP: u32 = 10; pub const NAUTILUS_BUILDER_FEE_MAKER_TENTHS_BP: u32 = 5; pub const HYPERLIQUID_CHAIN_ID: u64 = 421614;
44
45pub const HYPERLIQUID_POST_ONLY_WOULD_MATCH: &str =
47 "Post only order would have immediately matched";
48pub const HYPERLIQUID_BUILDER_FEE_NOT_APPROVED: &str = "Builder fee has not been approved";
49
50pub const HYPERLIQUID_SUPPORTED_ORDER_TYPES: &[OrderType] = &[
60 OrderType::Market, OrderType::Limit, OrderType::StopMarket, OrderType::StopLimit, OrderType::MarketIfTouched, OrderType::LimitIfTouched, ];
67
68pub const HYPERLIQUID_CONDITIONAL_ORDER_TYPES: &[OrderType] = &[
73 OrderType::StopMarket,
74 OrderType::StopLimit,
75 OrderType::MarketIfTouched,
76 OrderType::LimitIfTouched,
77];
78
79pub fn ws_url(is_testnet: bool) -> &'static str {
81 if is_testnet {
82 HYPERLIQUID_TESTNET_WS_URL
83 } else {
84 HYPERLIQUID_WS_URL
85 }
86}
87
88pub fn info_url(is_testnet: bool) -> &'static str {
90 if is_testnet {
91 HYPERLIQUID_TESTNET_INFO_URL
92 } else {
93 HYPERLIQUID_INFO_URL
94 }
95}
96
97pub fn exchange_url(is_testnet: bool) -> &'static str {
99 if is_testnet {
100 HYPERLIQUID_TESTNET_EXCHANGE_URL
101 } else {
102 HYPERLIQUID_EXCHANGE_URL
103 }
104}
105
106pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(30);
109pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
110pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
111pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
112pub const INFLIGHT_MAX: usize = 100;
114pub const QUEUE_MAX: usize = 1000;
115
116#[cfg(test)]
117mod tests {
118 use rstest::rstest;
119
120 use super::*;
121
122 #[rstest]
123 fn test_ws_url() {
124 assert_eq!(ws_url(false), HYPERLIQUID_WS_URL);
125 assert_eq!(ws_url(true), HYPERLIQUID_TESTNET_WS_URL);
126 }
127
128 #[rstest]
129 fn test_info_url() {
130 assert_eq!(info_url(false), HYPERLIQUID_INFO_URL);
131 assert_eq!(info_url(true), HYPERLIQUID_TESTNET_INFO_URL);
132 }
133
134 #[rstest]
135 fn test_exchange_url() {
136 assert_eq!(exchange_url(false), HYPERLIQUID_EXCHANGE_URL);
137 assert_eq!(exchange_url(true), HYPERLIQUID_TESTNET_EXCHANGE_URL);
138 }
139
140 #[rstest]
141 fn test_constants_values() {
142 assert_eq!(HEARTBEAT_INTERVAL, Duration::from_secs(30));
143 assert_eq!(RECONNECT_BASE_BACKOFF, Duration::from_millis(250));
144 assert_eq!(RECONNECT_MAX_BACKOFF, Duration::from_secs(30));
145 assert_eq!(HTTP_TIMEOUT, Duration::from_secs(10));
146 assert_eq!(INFLIGHT_MAX, 100);
147 assert_eq!(QUEUE_MAX, 1000);
148 }
149}