nautechsystems/nautilus_trader · error · anyhow::Error
{e}
Error message
{e} What it means
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.
Source
Thrown at crates/adapters/kraken/src/data/futures.rs:676
let instrument_id = cmd.instrument_id;
let depth = cmd.depth;
if cmd.book_type != BookType::L2_MBP {
log::warn!(
"Book type {:?} not supported by Kraken, skipping subscription",
cmd.book_type
);
return Ok(());
}
self.book_instruments.insert(instrument_id);
let ws = self.ws.clone();
self.spawn_ws(
async move {
ws.subscribe_book(instrument_id, depth.map(|d| d.get() as u32))
.await
.map_err(|e| anyhow::anyhow!("{e}"))
},
"subscribe book",
);
Ok(())
}
fn subscribe_quotes(&mut self, cmd: SubscribeQuotes) -> anyhow::Result<()> {
let instrument_id = cmd.instrument_id;
let ws = self.ws.clone();
self.quote_instruments.insert(instrument_id);
self.spawn_ws(
async move {
ws.subscribe_quotes(instrument_id)
.await
.map_err(|e| anyhow::anyhow!("{e}"))View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
provider.subscribe_book_deltas(instrument_id, Some(depth))?; // panics/fails if ws not ready
// after
provider.connect().await?;
for attempt in 0..3 {
match provider.subscribe_book_deltas(instrument_id, Some(depth)) {
Ok(()) => break,
Err(e) if attempt < 2 => { tokio::time::sleep(Duration::from_secs(1 << attempt)).await; }
Err(e) => return Err(e),
}
} Defensive patterns
Strategy: retry
Validate before calling
// Check readiness before subscribing (pseudo-API)
if !provider.ws_connected() {
return Err(anyhow::anyhow!("cannot subscribe book: websocket not connected"));
} Try / catch
match provider.subscribe_book_deltas(instrument_id, depth).await {
Ok(()) => (),
Err(e) => { tracing::warn!("book subscribe failed, retrying: {e}"); retry_with_backoff(|| provider.subscribe_book_deltas(instrument_id, depth), 3).await?; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Subscribing immediately after connect() before the socket is ready; network drop during reconnect; subscribing to an instrument symbol the futures feed does not recognize.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- subscription confirmation failed: {e}
- {e}
- failed to subscribe to user orders: {e}
- failed to subscribe to user trades: {e}
- failed to subscribe to user portfolio: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/9e7f71c3c2f4c530.
Report an issue: GitHub.