nautechsystems/nautilus_trader · error

Failed to create default BybitRawHttpClient

Error message

Failed to create default BybitRawHttpClient

What it means

BybitRawHttpClient::default() calls Self::new with sensible defaults (60s timeout, 3 retries, etc.) and expects success. new only fails on invalid configuration, so with these fixed defaults it cannot fail; the expect turns any such failure into a panic at client construction. Users hit a panic during Default/Geo init rather than a returned error.

Source

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

)]
#[derive(Clone)]
pub struct BybitRawHttpClient {
    base_url: String,
    client: Arc<ArcSwap<HttpClient>>,
    rate_limiter: BybitRateLimiter,
    credential: Option<Credential>,
    recv_window_ms: u64,
    timeout_secs: u64,
    proxy_url: Option<String>,
    session_generation: Arc<AtomicU64>,
    retry_manager: RetryManager<BybitHttpError>,
    cancellation_token: Arc<parking_lot::Mutex<CancellationToken>>,
}

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

impl Debug for BybitRawHttpClient {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct(stringify!(BybitRawHttpClient))
            .field("base_url", &self.base_url)
            .field("has_credentials", &self.credential.is_some())
            .field("recv_window_ms", &self.recv_window_ms)
            .finish()
    }
}

impl BybitRawHttpClient {
    /// Cancels all pending HTTP requests.
    pub fn cancel_all_requests(&self) {
        self.cancellation_token.lock().cancel();
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Call BybitRawHttpClient::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)? directly and handle the error
  2. Check the error message from new() for TLS/proxy/root-certificate issues in your environment
  3. Ensure the correct TLS feature (native-tls vs rustls) is enabled for your target platform
  4. Avoid Default in fallible contexts; construct explicitly and propagate the error

Example fix

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

Strategy: try-catch

Validate before calling

// construct explicitly instead of relying on Default
let client = BybitRawHttpClient::new(
    None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None,
)?;

Try / catch

let client = BybitRawHttpClient::new(
    None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None,
)
.map_err(|e| {
    eprintln!("Bybit HTTP client init failed: {e}");
    e
})?;

Prevention

When it happens

Trigger: Calling BybitRawHttpClient::default() (or code paths that use it) when the underlying new() fails — realistically only if environment/proxy/TLS setup makes even the default configuration invalid (e.g. reqwest client cannot build due to TLS backend issues).

Common situations: Embedded environments or musl builds where the TLS backend fails to initialize; a static proxy config that reqwest rejects at client build time; running in a context where Default is invoked implicitly.

Related errors


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