{"record":{"id":"6ba00587598f11a1","repo":"nautechsystems/nautilus_trader","slug":"failed-to-subscribe-to-user-trades-e","errorCode":null,"errorMessage":"failed to subscribe to user trades: {e}","messagePattern":"failed to subscribe to user trades: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/execution.rs","lineNumber":567,"sourceCode":"                .await\n                .context(\"failed to connect WebSocket client for execution\")?;\n\n            self.ws_client\n                .authenticate_session(DERIBIT_EXECUTION_SESSION_NAME)\n                .await\n                .map_err(|e| anyhow::anyhow!(\"failed to authenticate WebSocket session: {e}\"))?;\n\n            log::debug!(\"WebSocket client authenticated for execution\");\n\n            // Subscribe to user order and trade updates for all instruments\n            self.ws_client\n                .subscribe_user_orders()\n                .await\n                .map_err(|e| anyhow::anyhow!(\"failed to subscribe to user orders: {e}\"))?;\n            self.ws_client\n                .subscribe_user_trades()\n                .await\n                .map_err(|e| anyhow::anyhow!(\"failed to subscribe to user trades: {e}\"))?;\n            self.ws_client\n                .subscribe_user_portfolio()\n                .await\n                .map_err(|e| anyhow::anyhow!(\"failed to subscribe to user portfolio: {e}\"))?;\n\n            if let Err(e) = self.ws_client.wait_for_subscriptions_confirmed(30.0).await {\n                // Roll back subscription state so a retry re-sends subscribe requests\n                let _ = self.ws_client.unsubscribe_user_orders().await;\n                let _ = self.ws_client.unsubscribe_user_trades().await;\n                let _ = self.ws_client.unsubscribe_user_portfolio().await;\n                anyhow::bail!(\"subscription confirmation failed: {e}\");\n            }\n\n            log::debug!(\"Subscribed to user order, trade, and portfolio updates\");\n\n            // Spawn stream handler to dispatch WebSocket messages to the execution engine\n            let stream = self.ws_client.stream()?;\n            self.spawn_stream_handler(stream)?;","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/execution.rs#L549-L585","documentation":"Raised in `DeribitExecutionClient::connect` when the private-channel subscription for user trades (`subscribe_user_trades`) fails, after user-orders subscription succeeded. The connect sequence aborts because trade/fill updates are required for accurate position and execution reporting. The inner ws-client error is embedded in the message via `{e}`.","triggerScenarios":"Calling `connect()` where `subscribe_user_orders()` succeeds but `ws_client.subscribe_user_orders().await` for trades returns Err — e.g. connection drops between the two subscribe RPCs, the trades channel `private/subscribe` request is rejected, or the session token became invalid mid-connect.","commonSituations":"Flaky connections where the first subscribe succeeds and the second fails; auth token expiry/refresh failure between RPCs; Deribit rejecting the channel name or quota; proxies that kill the socket during the multi-request handshake.","solutions":["Inspect the wrapped `{e}` for the concrete JSON-RPC or transport error.","Retry connect; the client's rollback path unsubscribes all user channels so a retry re-sends the full subscription set.","Re-validate credentials/session — an invalid or expired session can pass one RPC and fail the next.","Stabilize the network path (keepalive, disable aggressive proxy idle timeouts) so the handshake completes atomically.","If quota-related, reduce concurrent private subscriptions or clients per API key."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Retry the whole connect sequence so all three user subscriptions are re-sent atomically\nif let Err(e) = client.connect().await {\n    tracing::warn!(\"connect failed: {e:#}; retrying with backoff\");\n    backoff_retry(|| client.connect()).await?;\n}","preventionTips":["Treat the orders/trades/portfolio subscriptions as one atomic handshake; always retry connect as a whole.","Ensure session tokens are refreshed before the connect window.","Avoid aggressive proxy/idle timeouts that kill sockets mid-handshake.","Watch Deribit subscription quotas per API key."],"tags":["websocket","subscription","deribit","execution-client","network"],"backgroundTag":"api-request-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"}