WebSocket connections will disconnect — during maintenance windows, network hiccups, or load balancer recycling. A resilient client handles this transparently. This page covers the patterns you need.Documentation Index
Fetch the complete documentation index at: https://kraken-sandbox.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Connection lifecycle
A WebSocket connection to Kraken goes through these phases:- Connect — TCP + TLS handshake to
wss://ws.kraken.com/v2 - Authenticate (private channels) — obtain a token via
GetWebSocketsTokenand send it in the subscription - Subscribe — send subscription messages for each channel you need
- Receive snapshot — Kraken sends the current state for stateful channels (book, open orders, balances)
- Stream updates — incremental updates from there on
- Disconnect — connection closes (server or network)
- Reconnect — repeat from step 1
Detecting disconnects
Kraken sends periodicheartbeat messages. If you stop receiving them, the connection is likely dead.
Subscribe to the heartbeat channel after connecting:
Reconnection with backoff
Use exponential backoff with jitter to avoid thundering-herd reconnection storms:Re-subscribing after reconnect
After reconnecting you must re-subscribe to all channels. Kraken does not automatically restore subscriptions. Keep a local registry of your active subscriptions and replay them on every connect:State reconciliation after reconnect
On subscribe, Kraken sends a snapshot of the current state for stateful channels. Use this to rebuild your local state rather than trying to merge with your pre-disconnect state — the snapshot is authoritative.Order book
When you subscribe tobook, you receive a full snapshot first:
Open orders
Subscribe toexecutions to receive live order state. On reconnect, the snapshot contains all currently open orders.
After reconnecting, call QueryOrders via REST to cross-check against the snapshot for any orders that transitioned during the reconnect window:
Balances
Thebalances channel snapshot on reconnect reflects current state. No additional REST call needed unless you need sub-second precision during the gap.
Token refresh for private channels
WebSocket tokens expire after 15 minutes. If your connection lives longer than that, you need to refresh the token and re-authenticate. Recommended: fetch a new token just before subscribing (not when the connection opens), so the token is fresh. For long-running connections, fetch a new token proactively before each reconnect:Using cancelAllOrdersAfter as a safety net
Enable the Dead Man’s Switch before going live. It ensures that if your client fails to reconnect and stops refreshing, all open orders will be canceled automatically:
System status
Subscribe to thestatus channel to receive notifications about planned maintenance and trading mode changes:
system values: online, maintenance, cancel_only, post_only, limit_only. When maintenance is received, stop sending orders and prepare to reconnect.
Sequence numbers (WebSocket v1)
WebSocket v1 private feeds (openOrders, ownTrades) include sequence numbers. On reconnect, compare the first sequence number in the new snapshot against your last received sequence number to detect gaps.
If a gap is detected, fall back to REST (OpenOrders, ClosedOrders) to reconstruct the missed state before resuming from the new WebSocket feed.
Maintenance windows
FIX sessions have a logical session rollover every day at 22:00 UTC. This lasts approximately 30 seconds. Sequence numbers reset to 0. Reconnect and re-establish the session after the rollover. WebSocket connections during maintenance receive astatus: maintenance message. Reconnect attempts during the window will fail — implement your backoff so you retry automatically once the window ends.
Related guides
WebSocket authentication
How to obtain and refresh WebSocket tokens
Order lifecycle
Order states and how to reconcile them after a disconnect
API key permissions
Access WebSocket API permission required for private channels
Book checksum (v2)
Validate your order book state after reconnect