{"record":{"id":"71236dace257242a","repo":"nautechsystems/nautilus_trader","slug":"subaccount-query-response-does-not-contain-subacco","errorCode":null,"errorMessage":"Subaccount query response does not contain subaccount","messagePattern":"Subaccount query response does not contain subaccount","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/grpc/client.rs","lineNumber":448,"sourceCode":"    ///\n    /// Returns an error if the query fails.\n    pub async fn get_subaccount(\n        &mut self,\n        address: &str,\n        number: u32,\n    ) -> Result<SubaccountInfo, anyhow::Error> {\n        let req = QueryGetSubaccountRequest {\n            owner: address.to_string(),\n            number,\n        };\n        let subaccount = self\n            .subaccounts\n            .subaccount(req)\n            .await?\n            .into_inner()\n            .subaccount\n            .ok_or_else(|| {\n                anyhow::anyhow!(\"Subaccount query response does not contain subaccount\")\n            })?;\n        Ok(subaccount)\n    }\n\n    /// Simulate a transaction to estimate gas usage.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if simulation fails.\n    pub async fn simulate_tx(&mut self, tx_bytes: Vec<u8>) -> Result<u64, anyhow::Error> {\n        let req = SimulateRequest {\n            tx_bytes,\n            ..Default::default()\n        };\n        let gas_used = self\n            .tx\n            .simulate(req)\n            .await?","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/grpc/client.rs#L430-L466","documentation":"get_subaccount queries the dYdX subaccounts module; `subaccount` is optional and None when no subaccount exists for the given owner/number pair. The library raises instead of returning an empty subaccount.","triggerScenarios":"Calling get_subaccount with (address, subaccount_number) that has never been created on chain — e.g. subaccount 0 for an address that never opened a position or deposit.","commonSituations":"Configuring a bot with an owner address whose subaccounts were never initialized; querying a different network than where the subaccount was created; using a subaccount number other than the default 0 that doesn't exist.","solutions":["Deposit funds or perform any subaccount action first to create it on chain.","Confirm the owner address and subaccount number (usually 0) are correct.","Ensure the gRPC endpoint targets the network where the subaccount exists (mainnet vs testnet).","Handle the not-found case explicitly in caller logic instead of treating it as a transient failure."],"exampleFix":"// before\nlet sub = client.get_subaccount(owner, 0).await?;\n// after: validate existence expectations\nlet sub = client.get_subaccount(owner, subaccount_id.number).await\n    .map_err(|e| anyhow::anyhow!(\"Subaccount {owner}/{n} not found — has it been funded? ({e})\"))\n    .map_err(...); // or create/init subaccount before querying","handlingStrategy":"validation","validationCode":"anyhow::ensure!(subaccount_number >= 0, \"subaccount number must be non-negative\");\n// optionally pre-check existence at startup:\n// client.get_subaccount(owner, 0).await.expect(\"subaccount must exist\");","typeGuard":null,"tryCatchPattern":"let sub = client.get_subaccount(owner, number).await\n    .map_err(|e| if e.to_string().contains(\"does not contain subaccount\") {\n        anyhow::anyhow!(\"subaccount {owner}/{number} not initialized; deposit first\")\n    } else { e })?;","preventionTips":["Initialize and fund subaccounts before deploying bots","Verify owner address and subaccount number in config against chain","Check network (mainnet/testnet) matches where subaccounts were created"],"tags":["grpc","dydx","subaccount","not-found"],"backgroundTag":"entity-not-found","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"}