{"record":{"id":"ad7fcbfb1bf77ef8","repo":"nautechsystems/nautilus_trader","slug":"failed-to-subscribe-to-user-portfolio-e","errorCode":null,"errorMessage":"failed to subscribe to user portfolio: {e}","messagePattern":"failed to subscribe to user portfolio: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/execution.rs","lineNumber":571,"sourceCode":"                .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)?;\n\n            Ok::<(), anyhow::Error>(())\n        }\n        .await;","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/execution.rs#L553-L589","documentation":"Raised in `DeribitExecutionClient::connect` when the private-channel subscription for user portfolio (`subscribe_user_portfolio`) fails, as the last of the three execution subscriptions. Connect aborts since portfolio/margin updates are needed for account-state tracking. On the subsequent subscription-confirmation timeout the client rolls back by unsubscribing all three channels.","triggerScenarios":"Calling `connect()` where orders and trades subscriptions succeed but `ws_client.subscribe_user_portfolio().await` returns Err — connection failure on the third RPC, rejected `user.portfolio.*` channel subscribe, or session invalidation before this call.","commonSituations":"Same family as the other subscribe failures: credential scope problems, mid-handshake network drops, channel/quota rejection, environment (testnet/prod) mismatch, or an already-closed ws client.","solutions":["Read the embedded inner error for the actual cause (transport vs JSON-RPC rejection).","Retry connect; the rollback/unsubscribe logic ensures a clean re-subscription attempt.","Verify the account has permission for portfolio channels and credentials are correctly configured for the target environment.","Check network stability and proxy timeouts around the connect window.","Reduce subscription load or stagger clients if hitting Deribit subscription limits."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// connect() already rolls back subscriptions on failure; simply retry\nmatch client.connect().await {\n    Err(e) if format!(\"{e:#}\").contains(\"failed to subscribe to user portfolio\") => {\n        tokio::time::sleep(BACKOFF).await;\n        client.connect().await?;\n    }\n    other => other?,\n}","preventionTips":["Confirm account-level permission for portfolio channels.","Check credentials/environment (testnet vs mainnet) match the intended account.","Retry connect after failures — the client unsubscribes all user channels first for a clean re-subscribe.","Limit concurrent private subscriptions to stay within venue limits."],"tags":["websocket","subscription","deribit","portfolio","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-14T05:17:10.506Z"}