nautechsystems/nautilus_trader · error

Failed to create default BybitHttpClient

Error message

Failed to create default BybitHttpClient

What it means

`impl Default for BybitHttpClient` calls `Self::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)` and unwraps with `expect`. This panics if `BybitHttpClient::new` fails — typically invalid configuration such as an unusable proxy URL, invalid timeouts, or internal construction failure (e.g. TLS/client builder error).

Source

Thrown at crates/adapters/bybit/src/http/client.rs:1611

    use_spot_position_reports: Arc<AtomicBool>,
}

impl Clone for BybitHttpClient {
    fn clone(&self) -> Self {
        Self {
            inner: self.inner.clone(),
            instruments_cache: self.instruments_cache.clone(),
            cache_initialized: self.cache_initialized.clone(),
            use_spot_position_reports: self.use_spot_position_reports.clone(),
            clock: self.clock,
        }
    }
}

impl Default for BybitHttpClient {
    fn default() -> Self {
        Self::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)
            .expect("Failed to create default BybitHttpClient")
    }
}

impl Debug for BybitHttpClient {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct(stringify!(BybitHttpClient))
            .field("inner", &self.inner)
            .finish()
    }
}

impl BybitHttpClient {
    /// Creates a new [`BybitHttpClient`] using the default Bybit HTTP URL.
    ///
    /// # Errors
    ///
    /// Returns an error if the retry manager cannot be created.
    pub fn new(

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Call `BybitHttpClient::new(...)` directly and handle the `Result` instead of relying on `Default`
  2. Check proxy environment variables (`HTTPS_PROXY`, `HTTP_PROXY`, `ALL_PROXY`) for malformed URLs and unset or fix them
  3. Verify the runtime has valid TLS/CA roots for reqwest
  4. Log the underlying `BybitHttpError` from `new` to identify the exact construction failure

Example fix

// before
let client = BybitHttpClient::default();
// after
let client = BybitHttpClient::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)?;
Defensive patterns

Strategy: try-catch

Validate before calling

// Avoid Default in proxy-heavy environments; construct explicitly and validate env first
for v in ["HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY"] {
    if let Ok(p) = std::env::var(v) {
        assert!(p.starts_with("http://") || p.starts_with("https://"), "malformed proxy: {v}={p}");
    }
}

Try / catch

// Replace default() with explicit construction and error handling:
let client = BybitHttpClient::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)
    .map_err(|e| { log::error!("client init failed: {e}"); e })?;

Prevention

When it happens

Trigger: Using `BybitHttpClient::default()` (or `Default::default()`) in an environment where the underlying HTTP client cannot be constructed — e.g. a misconfigured proxy env var (HTTPS_PROXY) pointing at an invalid URL, or reqwest failing to build its TLS backend.

Common situations: Corporate proxies with malformed `HTTPS_PROXY`/`HTTP_PROXY` values; restricted environments without TLS roots; embedding in services that construct the client via `Default` without validation.

Related errors


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