{"record":{"id":"67bfcd404341a0be","repo":"nautechsystems/nautilus_trader","slug":"failed-derive-private-ws-subscriptions","errorCode":null,"errorMessage":"failed Derive private WS subscriptions","messagePattern":"failed Derive private WS subscriptions","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/execution.rs","lineNumber":651,"sourceCode":"            }\n            return Err(e);\n        };\n\n        let subaccount_id = self.credential.subaccount_id();\n        let channels = vec![\n            DeriveWsChannel::orders(subaccount_id),\n            DeriveWsChannel::private_trades(subaccount_id),\n            DeriveWsChannel::balances(subaccount_id),\n        ];\n\n        if let Err(e) = self.ws_client.subscribe_channels(channels).await {\n            log::warn!(\"Derive private WS subscriptions failed: {e}; tearing down\");\n            if let Err(teardown_error) = self.teardown_partial_connect().await {\n                return Err(anyhow::Error::new(e).context(format!(\n                    \"Derive execution startup teardown failed: {teardown_error}\"\n                )));\n            }\n            return Err(anyhow::Error::new(e).context(\"failed Derive private WS subscriptions\"));\n        }\n\n        if let Err(e) = self.start_ws_dispatch(rx) {\n            if let Err(teardown_error) = self.teardown_partial_connect().await {\n                return Err(e.context(format!(\n                    \"Derive execution startup teardown failed: {teardown_error}\"\n                )));\n            }\n            return Err(e.context(\"failed to register Derive execution WebSocket dispatch task\"));\n        }\n\n        // Fail-fast if the initial account snapshot cannot load: without it,\n        // `await_account_registered` would block the full timeout window and\n        // surface a misleading registration timeout. Tear down the WS we\n        // already started so the caller does not leak the dispatch task.\n        if let Err(e) = self.refresh_account_state().await {\n            log::warn!(\"Initial Derive account state refresh failed: {e}; tearing down\");\n            if let Err(teardown_error) = self.teardown_partial_connect().await {","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/execution.rs#L633-L669","documentation":"This error is returned by Derive execution client connect() when subscribing to the private WebSocket channels (orders, balances) fails but the partial-connect teardown succeeded cleanly. The original subscription error is the source; the context confirms startup was rolled back and no partial connection remains. It surfaces from connect().","triggerScenarios":"ws_client.subscribe_channels(channels) returns Err and teardown_partial_connect() completes successfully.","commonSituations":"Invalid or expired Derive API credentials rejecting subscriptions; Derive rejecting a channel due to wrong subaccount; transient network failure at startup; Derive service outage.","solutions":["Verify Derive API credentials, wallet, and subaccount_id configuration","Read the chained source error to see the specific subscription rejection","Retry connect() — transient network/service issues resolve on retry","Check Derive API status for outages","Ensure the WS client version/protocol matches the current Derive API"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Validate Derive credentials and subaccount before attempting subscription\nif !derive_credentials_valid(config) {\n    return Err(anyhow!(\"invalid Derive credentials; refusing connect\"));\n}","typeGuard":"fn is_clean_subscription_failure(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"failed Derive private WS subscriptions\")\n}","tryCatchPattern":"match exec_client.connect().await {\n    Err(e) if is_clean_subscription_failure(&e) => {\n        // rollback succeeded; safe to retry with backoff\n        retry_with_backoff(|| exec_client.connect()).await\n    }\n    other => other,\n}","preventionTips":["Use exponential backoff on connect retries for transient failures","Validate API keys, wallet, and subaccount configuration up front","Check Derive API status before trading sessions","Keep the WS client/protocol version current with the Derive API"],"tags":["websocket","derive","subscription","startup"],"backgroundTag":"websocket-connect-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}