use std::{sync::LazyLock, time::Duration};
use nautilus_model::{enums::OrderType, identifiers::Venue};
use ustr::Ustr;
pub const HYPERLIQUID: &str = "HYPERLIQUID";
pub static HYPERLIQUID_VENUE: LazyLock<Venue> =
LazyLock::new(|| Venue::new(Ustr::from(HYPERLIQUID)));
pub const HYPERLIQUID_WS_URL: &str = "wss://api.hyperliquid.xyz/ws";
pub const HYPERLIQUID_INFO_URL: &str = "https://api.hyperliquid.xyz/info";
pub const HYPERLIQUID_EXCHANGE_URL: &str = "https://api.hyperliquid.xyz/exchange";
pub const HYPERLIQUID_TESTNET_WS_URL: &str = "wss://api.hyperliquid-testnet.xyz/ws";
pub const HYPERLIQUID_TESTNET_INFO_URL: &str = "https://api.hyperliquid-testnet.xyz/info";
pub const HYPERLIQUID_TESTNET_EXCHANGE_URL: &str = "https://api.hyperliquid-testnet.xyz/exchange";
pub const NAUTILUS_BUILDER_ADDRESS: &str = "0x0c8d970c462726e014ad36f6c5a63e99db48a8e7";
pub const HYPERLIQUID_CHAIN_ID: u64 = 421614;
pub const HYPERLIQUID_POST_ONLY_WOULD_MATCH: &str =
"Post only order would have immediately matched";
pub const HYPERLIQUID_SUPPORTED_ORDER_TYPES: &[OrderType] = &[
OrderType::Market, OrderType::Limit, OrderType::StopMarket, OrderType::StopLimit, OrderType::MarketIfTouched, OrderType::LimitIfTouched, ];
pub const HYPERLIQUID_CONDITIONAL_ORDER_TYPES: &[OrderType] = &[
OrderType::StopMarket,
OrderType::StopLimit,
OrderType::MarketIfTouched,
OrderType::LimitIfTouched,
];
pub fn ws_url(is_testnet: bool) -> &'static str {
if is_testnet {
HYPERLIQUID_TESTNET_WS_URL
} else {
HYPERLIQUID_WS_URL
}
}
pub fn info_url(is_testnet: bool) -> &'static str {
if is_testnet {
HYPERLIQUID_TESTNET_INFO_URL
} else {
HYPERLIQUID_INFO_URL
}
}
pub fn exchange_url(is_testnet: bool) -> &'static str {
if is_testnet {
HYPERLIQUID_TESTNET_EXCHANGE_URL
} else {
HYPERLIQUID_EXCHANGE_URL
}
}
pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(30);
pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
pub const INFLIGHT_MAX: usize = 100;
pub const QUEUE_MAX: usize = 1000;
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::*;
#[rstest]
fn test_ws_url() {
assert_eq!(ws_url(false), HYPERLIQUID_WS_URL);
assert_eq!(ws_url(true), HYPERLIQUID_TESTNET_WS_URL);
}
#[rstest]
fn test_info_url() {
assert_eq!(info_url(false), HYPERLIQUID_INFO_URL);
assert_eq!(info_url(true), HYPERLIQUID_TESTNET_INFO_URL);
}
#[rstest]
fn test_exchange_url() {
assert_eq!(exchange_url(false), HYPERLIQUID_EXCHANGE_URL);
assert_eq!(exchange_url(true), HYPERLIQUID_TESTNET_EXCHANGE_URL);
}
#[rstest]
fn test_constants_values() {
assert_eq!(HEARTBEAT_INTERVAL, Duration::from_secs(30));
assert_eq!(RECONNECT_BASE_BACKOFF, Duration::from_millis(250));
assert_eq!(RECONNECT_MAX_BACKOFF, Duration::from_secs(30));
assert_eq!(HTTP_TIMEOUT, Duration::from_secs(10));
assert_eq!(INFLIGHT_MAX, 100);
assert_eq!(QUEUE_MAX, 1000);
}
}