nautechsystems/nautilus_trader · error · anyhow::Error

Failed to create HTTP client {i}: {e}

Error message

Failed to create HTTP client {i}: {e}

What it means

One of the BitMEX broadcast submitter's HTTP transport clients could not be constructed. During `new`, each transport builds an HTTP client with retry, rate-limit, recv-window and proxy settings; a failure for client index `{i}` is wrapped in this error, aborting submitter construction.

Source

Thrown at crates/adapters/bitmex/src/broadcast/submitter.rs:451

                .proxy_urls
                .get(i)
                .and_then(|value| value.as_ref())
                .map(|value| value.expose_secret().to_owned());

            let client = BitmexHttpClient::with_credentials(
                config.api_key.clone().map(SecretString::into_inner),
                config.api_secret.clone().map(SecretString::into_inner),
                base_url.clone(),
                config.timeout_secs,
                config.max_retries,
                config.retry_delay_ms,
                config.retry_delay_max_ms,
                config.recv_window_ms,
                config.max_requests_per_second,
                config.max_requests_per_minute,
                proxy_url,
            )
            .map_err(|e| anyhow::anyhow!("Failed to create HTTP client {i}: {e}"))?;

            transports.push(TransportClient::new(client, format!("bitmex-submit-{i}")));
        }

        Ok(Self {
            config,
            transports: Arc::from(transports),
            health_check_task: Arc::new(RwLock::new(None)),
            running: Arc::new(AtomicBool::new(false)),
            total_submits: Arc::new(AtomicU64::new(0)),
            successful_submits: Arc::new(AtomicU64::new(0)),
            failed_submits: Arc::new(AtomicU64::new(0)),
            expected_rejects: Arc::new(AtomicU64::new(0)),
        })
    }

    /// Starts the broadcaster and health check loop.
    ///

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the wrapped `{e}` for the precise client-builder failure.
  2. Validate `proxy_url` format (must include scheme, e.g. `http://host:port`).
  3. Fix TLS/CA setup in the deployment environment (SSL_CERT_FILE, ca-certificates package).
  4. Confirm retry/rate-limit config values are valid positive numbers.

Example fix

// before
proxy_url = Some("localhost:8888".to_string());
// after
proxy_url = Some("http://localhost:8888".to_string());
Defensive patterns

Strategy: validation

Validate before calling

fn validate_submit_http_config(proxy_url: &Option<String>, max_rps: u32, max_rpm: u32) -> Result<(), String> {
    if let Some(url) = proxy_url {
        url::Url::parse(url).map_err(|e| format!("invalid proxy_url '{url}': {e}"))?;
    }
    if max_rps == 0 || max_rpm == 0 {
        return Err("rate limits must be > 0".into());
    }
    Ok(())
}

Try / catch

match HttpClient::new(...).map_err(|e| anyhow::anyhow!("Failed to create HTTP client {i}: {e}")) {
    Ok(client) => transports.push(TransportClient::new(client, format!("bitmex-submit-{i}"))),
    Err(e) => return Err(e.context("bitmex submitter init failed")),
}

Prevention

When it happens

Trigger: Creating the BitMEX broadcast submitter and transport `{i}`'s HTTP client builder fails — invalid `proxy_url`, TLS/CA config error, or invalid rate-limit/retry parameters.

Common situations: Misconfigured proxy in the BitMEX submit config; missing CA certificates in a container; malformed max-requests-per-second/minute values; same root causes as the canceller's identical error.

Related errors


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