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";
38pub const NAUTILUS_BUILDER_FEE_TENTHS_BP: u32 = 10; pub const HYPERLIQUID_POST_ONLY_WOULD_MATCH: &str =
42 "Post only order would have immediately matched";
43pub const HYPERLIQUID_BUILDER_FEE_NOT_APPROVED: &str = "Builder fee has not been approved";
44
45pub const HYPERLIQUID_SUPPORTED_ORDER_TYPES: &[OrderType] = &[
55 OrderType::Market, OrderType::Limit, OrderType::StopMarket, OrderType::StopLimit, OrderType::MarketIfTouched, OrderType::LimitIfTouched, ];
62
63pub const HYPERLIQUID_CONDITIONAL_ORDER_TYPES: &[OrderType] = &[
68 OrderType::StopMarket,
69 OrderType::StopLimit,
70 OrderType::MarketIfTouched,
71 OrderType::LimitIfTouched,
72];
73
74pub fn ws_url(is_testnet: bool) -> &'static str {
76 if is_testnet {
77 HYPERLIQUID_TESTNET_WS_URL
78 } else {
79 HYPERLIQUID_WS_URL
80 }
81}
82
83pub fn info_url(is_testnet: bool) -> &'static str {
85 if is_testnet {
86 HYPERLIQUID_TESTNET_INFO_URL
87 } else {
88 HYPERLIQUID_INFO_URL
89 }
90}
91
92pub fn exchange_url(is_testnet: bool) -> &'static str {
94 if is_testnet {
95 HYPERLIQUID_TESTNET_EXCHANGE_URL
96 } else {
97 HYPERLIQUID_EXCHANGE_URL
98 }
99}
100
101pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(30);
104pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
105pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
106pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
107pub const INFLIGHT_MAX: usize = 100;
109pub const QUEUE_MAX: usize = 1000;
110
111#[cfg(test)]
112mod tests {
113 use rstest::rstest;
114
115 use super::*;
116
117 #[rstest]
118 fn test_ws_url() {
119 assert_eq!(ws_url(false), HYPERLIQUID_WS_URL);
120 assert_eq!(ws_url(true), HYPERLIQUID_TESTNET_WS_URL);
121 }
122
123 #[rstest]
124 fn test_info_url() {
125 assert_eq!(info_url(false), HYPERLIQUID_INFO_URL);
126 assert_eq!(info_url(true), HYPERLIQUID_TESTNET_INFO_URL);
127 }
128
129 #[rstest]
130 fn test_exchange_url() {
131 assert_eq!(exchange_url(false), HYPERLIQUID_EXCHANGE_URL);
132 assert_eq!(exchange_url(true), HYPERLIQUID_TESTNET_EXCHANGE_URL);
133 }
134
135 #[rstest]
136 fn test_constants_values() {
137 assert_eq!(HEARTBEAT_INTERVAL, Duration::from_secs(30));
138 assert_eq!(RECONNECT_BASE_BACKOFF, Duration::from_millis(250));
139 assert_eq!(RECONNECT_MAX_BACKOFF, Duration::from_secs(30));
140 assert_eq!(HTTP_TIMEOUT, Duration::from_secs(10));
141 assert_eq!(INFLIGHT_MAX, 100);
142 assert_eq!(QUEUE_MAX, 1000);
143 }
144}