{"record":{"id":"9e7f71c3c2f4c530","repo":"nautechsystems/nautilus_trader","slug":"e-9e7f71","errorCode":null,"errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/kraken/src/data/futures.rs","lineNumber":676,"sourceCode":"        let instrument_id = cmd.instrument_id;\n        let depth = cmd.depth;\n\n        if cmd.book_type != BookType::L2_MBP {\n            log::warn!(\n                \"Book type {:?} not supported by Kraken, skipping subscription\",\n                cmd.book_type\n            );\n            return Ok(());\n        }\n\n        self.book_instruments.insert(instrument_id);\n\n        let ws = self.ws.clone();\n        self.spawn_ws(\n            async move {\n                ws.subscribe_book(instrument_id, depth.map(|d| d.get() as u32))\n                    .await\n                    .map_err(|e| anyhow::anyhow!(\"{e}\"))\n            },\n            \"subscribe book\",\n        );\n\n        Ok(())\n    }\n\n    fn subscribe_quotes(&mut self, cmd: SubscribeQuotes) -> anyhow::Result<()> {\n        let instrument_id = cmd.instrument_id;\n        let ws = self.ws.clone();\n\n        self.quote_instruments.insert(instrument_id);\n\n        self.spawn_ws(\n            async move {\n                ws.subscribe_quotes(instrument_id)\n                    .await\n                    .map_err(|e| anyhow::anyhow!(\"{e}\"))","sourceCodeStart":658,"sourceCodeEnd":694,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/kraken/src/data/futures.rs#L658-L694","documentation":"subscribe_book_deltas sends a book subscription over the Kraken Futures WebSocket and re-wraps any subscription error from ws.subscribe_book verbatim via anyhow. The error originates in the WS client layer — send failure, not-yet-connected socket, invalid instrument, or rejection by the exchange.","triggerScenarios":"Calling subscribe_book_deltas when the WebSocket is not connected, the send fails (connection dropped mid-subscribe), or the instrument_id/depth are rejected by the Kraken Futures WS subscribe handler.","commonSituations":"Subscribing immediately after connect() before the socket is ready; network drop during reconnect; subscribing to an instrument symbol the futures feed does not recognize.","solutions":["Ensure connect/await-ready completed before calling subscribe_book_deltas; retry after the connection is established.","Verify the instrument_id matches a valid Kraken Futures ticker symbol.","Retry the subscription with backoff; the adapter's spawn_ws context ('subscribe book') logs the failure point.","Check network/proxy stability if sends fail intermittently."],"exampleFix":"// before\nprovider.subscribe_book_deltas(instrument_id, Some(depth))?; // panics/fails if ws not ready\n// after\nprovider.connect().await?;\nfor attempt in 0..3 {\n    match provider.subscribe_book_deltas(instrument_id, Some(depth)) {\n        Ok(()) => break,\n        Err(e) if attempt < 2 => { tokio::time::sleep(Duration::from_secs(1 << attempt)).await; }\n        Err(e) => return Err(e),\n    }\n}","handlingStrategy":"retry","validationCode":"// Check readiness before subscribing (pseudo-API)\nif !provider.ws_connected() {\n    return Err(anyhow::anyhow!(\"cannot subscribe book: websocket not connected\"));\n}","typeGuard":null,"tryCatchPattern":"match provider.subscribe_book_deltas(instrument_id, depth).await {\n    Ok(()) => (),\n    Err(e) => { tracing::warn!(\"book subscribe failed, retrying: {e}\"); retry_with_backoff(|| provider.subscribe_book_deltas(instrument_id, depth), 3).await?; }\n}","preventionTips":["Await full connection before issuing subscriptions.","Retry subscriptions with exponential backoff after reconnect.","Validate instrument symbols against the exchange catalog.","Monitor the 'subscribe book' error context in logs."],"tags":["websocket","subscription","kraken","futures","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"}