{"record":{"id":"779fba19f6964433","repo":"nautechsystems/nautilus_trader","slug":"timeout-waiting-for-account-account-id-to-be-reg-779fba","errorCode":null,"errorMessage":"Timeout waiting for account {account_id} to be registered after {timeout_secs}s","messagePattern":"Timeout waiting for account (.+?) to be registered after (.+?)s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/execution.rs","lineNumber":1289,"sourceCode":"        if self.core.cache().account(&account_id).is_some() {\n            log::info!(\"Account {account_id} registered\");\n            return Ok(());\n        }\n\n        let start = Instant::now();\n        let timeout = Duration::from_secs_f64(timeout_secs);\n        let interval = Duration::from_millis(10);\n\n        loop {\n            tokio::time::sleep(interval).await;\n\n            if self.core.cache().account(&account_id).is_some() {\n                log::info!(\"Account {account_id} registered\");\n                return Ok(());\n            }\n\n            if start.elapsed() >= timeout {\n                anyhow::bail!(\n                    \"Timeout waiting for account {account_id} to be registered after {timeout_secs}s\"\n                );\n            }\n        }\n    }\n\n    /// Establishes instrument context, both WebSocket transports, private\n    /// subscriptions, and initial account state.\n    ///\n    /// Any failure leaves partially started transports for\n    /// [`Self::teardown_session`].\n    async fn establish_session(&mut self) -> anyhow::Result<()> {\n        // Reset leaves the old generation canceled until this async boundary can drain it\n        if !self.pending_tasks.is_empty()\n            || !self.session_tasks.is_empty()\n            || !self.pending_tasks.is_open()\n            || !self.session_tasks.is_open()\n            || self.ws_private.is_active()","sourceCodeStart":1271,"sourceCodeEnd":1307,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/execution.rs#L1271-L1307","documentation":"`await_account_registered` polls the cache after the private WebSocket session is established, waiting for the OKX account-state event to register the account. If the account is still absent from the cache after `timeout_secs`, the client bails. This indicates the private channel never delivered (or the adapter never processed) the account/balance update needed to build the account state.","triggerScenarios":"Calling `connect`/`establish_session` where after login the private WS stream yields no account registration within the timeout — e.g. invalid API keys with insufficient permissions, account-id mismatch between config and the keys' account, network stalls, or events filtered out before reaching the cache.","commonSituations":"API key created without the required read/trade scopes; configuring an `account_id` that does not correspond to the API key's account; slow network or OKX incident delaying the initial balance snapshot; very small timeout configured.","solutions":["Increase the account-registration timeout in the client config (e.g. from 10s to 30–60s).","Verify API key/secret/passphrase are correct and have the required permissions (account read + trade).","Confirm the configured `account_id` matches the account behind the API keys.","Check connectivity/proxy stability and OKX status; inspect logs for private WS login or subscription failures preceding the timeout."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-flight: verify credentials and account before connect\n// ensure API key has read+trade scopes and account_id matches the key's account","typeGuard":null,"tryCatchPattern":"match client.connect() {\n    Err(e) if e.to_string().contains(\"Timeout waiting for account\") => {\n        log::warn!(\"account registration timed out; retrying with backoff\");\n        tokio::time::sleep(Duration::from_secs(5)).await;\n        client.connect()?;\n    }\n    r => r?,\n}","preventionTips":["Verify API key permissions (account read + trade) before deployment.","Ensure the configured account_id matches the keys' OKX account.","Set a generous registration timeout (>= 30s) in production configs.","Monitor private WS login errors in logs — they precede this timeout."],"tags":["okx","timeout","account-registration","websocket"],"backgroundTag":"request-timeout","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"}