nautechsystems/nautilus_trader · error

Failed to create HTTP client

Error message

Failed to create HTTP client: {e}

What it means

When credentials are configured, the data factory builds an `AxHttpClient::with_credentials(...)`; any error constructing that client (bad base URL, invalid proxy URL, retry config) is wrapped as "Failed to create HTTP client: {e}". The inner `{e}` carries the concrete cause from the HTTP client constructor.

Solutions

  1. Inspect the wrapped `{e}` in the message for the root cause.
  2. Fix `http_base_url` in the config to a valid absolute HTTP(S) URL.
  3. Fix `proxy_url` to include a scheme, e.g. `http://proxy.corp:8080`, or remove it.
  4. Verify `http_timeout_secs`, `max_retries`, and `retry_delay_max_ms` are sane non-degenerate values.

Example fix

// before
proxy_url: Some("localhost:8080"), // no scheme

// after
proxy_url: Some("http://localhost:8080"),
Defensive patterns

Strategy: validation

Validate before calling

// before create
let base = ax_config.http_base_url();
assert!(base.starts_with("http"), "http_base_url must include scheme: {base}");
if let Some(p) = &ax_config.proxy_url {
    let p = p.expose_secret();
    assert!(p.starts_with("http://") || p.starts_with("https://"), "proxy_url needs scheme: {p}");
}
assert!(ax_config.http_timeout_secs > 0);

Try / catch

match factory.create(name, config, ...) {
    Err(e) if e.to_string().starts_with("Failed to create HTTP client") => {
        eprintln!("HTTP client init failed: {e:#} — check base/proxy URLs and timeouts");
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: `AxDataClientFactory.create` with valid credentials but a malformed `http_base_url`, an unparsable `proxy_url`, or a constructor failure such as TLS/runtime initialization inside `AxHttpClient::with_credentials`.

Common situations: Proxy set to a URL missing its scheme (e.g. `localhost:8080` without `http://`); base URL with a typo or trailing garbage; corporate proxy requiring auth that the simple URL form can't express.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at crates/adapters/architect_ax/src/factories.rs:123

                ax_config.api_secret.clone().map(|value| value.into_inner()),
            )
            .ok_or_else(|| anyhow::anyhow!("API credentials not configured"))?;

            AxHttpClient::with_credentials(
                credential.api_key().to_string(),
                credential.api_secret().to_string(),
                Some(ax_config.http_base_url()),
                None, // orders_base_url
                ax_config.http_timeout_secs,
                ax_config.max_retries,
                ax_config.retry_delay_initial_ms,
                ax_config.retry_delay_max_ms,
                ax_config
                    .proxy_url
                    .as_ref()
                    .map(|url| url.expose_secret().to_owned()),
            )
            .map_err(|e| anyhow::anyhow!("Failed to create HTTP client: {e}"))?
        } else {
            AxHttpClient::new(
                Some(ax_config.http_base_url()),
                None, // orders_base_url
                ax_config.http_timeout_secs,
                ax_config.max_retries,
                ax_config.retry_delay_initial_ms,
                ax_config.retry_delay_max_ms,
                ax_config
                    .proxy_url
                    .as_ref()
                    .map(|url| url.expose_secret().to_owned()),
            )
            .map_err(|e| anyhow::anyhow!("Failed to create HTTP client: {e}"))?
        };

        let ws_url = ax_config.ws_public_url();

View on GitHub (pinned to 18893faf8b)