nautechsystems/nautilus_trader · error

Failed to create default Hyperliquid HTTP client

Error message

Failed to create default Hyperliquid HTTP client

What it means

`HyperliquidHttpClient::default()` hardcodes Mainnet, a 60-second timeout, and no credentials, calling `Self::new(...)` and `expect`ing success. Since `new` performs environment/URL resolution and client construction that can fail (e.g. invalid environment URL, builder error), Default cannot propagate the error and instead panics. This only fires if the built-in default configuration is somehow invalid.

Source

Thrown at crates/adapters/hyperliquid/src/http/client.rs:949

    /// Mapping from symbol to asset index for order submission.
    asset_indices: Arc<AtomicMap<Ustr, u32>>,
    /// Mapping from spot fill coin (`@{pair_index}`) to instrument symbol.
    spot_fill_coins: Arc<AtomicMap<Ustr, Ustr>>,
    client_order_id_cloids: Arc<Mutex<AHashMap<ClientOrderId, Cloid>>>,
    account_id: Option<AccountId>,
    /// Optional override address for queries (agent wallet / API sub-key support).
    /// When set, used for balance queries, position reports, and WS subscriptions
    /// instead of the address derived from the private key.
    account_address: Option<String>,
    normalize_prices: bool,
    market_order_slippage_bps: u32,
    include_builder_attribution: bool,
}

impl Default for HyperliquidHttpClient {
    fn default() -> Self {
        Self::new(HyperliquidEnvironment::Mainnet, 60, None)
            .expect("Failed to create default Hyperliquid HTTP client")
    }
}

impl HyperliquidHttpClient {
    /// Creates a new [`HyperliquidHttpClient`] for public endpoints only.
    ///
    /// # Errors
    ///
    /// Returns an error if the HTTP client cannot be created.
    pub fn new(
        environment: HyperliquidEnvironment,
        timeout_secs: u64,
        proxy_url: Option<String>,
    ) -> std::result::Result<Self, HttpClientError> {
        let raw_client = HyperliquidRawHttpClient::new(environment, timeout_secs, proxy_url)?;
        Ok(Self::from_raw(raw_client))
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Prefer calling `HyperliquidHttpClient::new(env, timeout, credentials)` directly and handle the Result, instead of relying on Default.
  2. If Default must be used, verify the HyperliquidEnvironment::Mainnet URL configuration is intact.
  3. Investigate the underlying error from `new` (URL parsing, TLS/backend init) by calling new explicitly to get the actual Err.
  4. In test environments, construct the client with Testnet or an explicit URL via new.

Example fix

// before
let client = HyperliquidHttpClient::default(); // panics on config error
// after
let client = HyperliquidHttpClient::new(
    HyperliquidEnvironment::Mainnet,
    60,
    None,
)?;
Defensive patterns

Strategy: try-catch

Validate before calling

// prefer explicit construction so the error is catchable:
let client = HyperliquidHttpClient::new(HyperliquidEnvironment::Mainnet, 60, None)
    .map_err(|e| { eprintln!("client init failed: {e}"); e })?;

Prevention

When it happens

Trigger: Using `HyperliquidHttpClient::default()` (or a type that derefs/derives Default) when `HyperliquidHttpClient::new(Mainnet, 60, None)` fails — typically because the resolved Mainnet base URL is malformed or an internal client-builder step errors.

Common situations: Rare in practice; can surface if the environment constant/URL table is changed, in restricted environments where URL parsing or TLS setup fails, or in tests that alter environment configuration globally.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/0ae66c1c30be4636. Report an issue: GitHub.