WebSocket Close Code Lookup
Explain WebSocket close codes from 1000 to 4999 with meanings, causes, and recovery actions for exchange streams.
WebSocket close codes tell you why a connection terminated. In trading bots, codes 1006 (abnormal closure) and 1013 (try again later) are the most common during high volatility or rate limiting. Understanding the code helps you choose the right recovery action.
Showing 15 of 15 codes
Normal closure
The connection closed normally. Both sides agreed to close.
Recovery: No action needed. This is a clean close.
Going away
Server or client is going away (e.g., server shutdown, browser navigating away).
Recovery: Reconnect with exponential backoff. Check if the server is undergoing maintenance.
Protocol error
The endpoint received malformed data that violates the WebSocket protocol.
Recovery: Verify message framing and data format. Check for binary/text frame mismatches.
Unsupported data
The endpoint received data type it cannot handle (e.g., binary on a text-only endpoint).
Recovery: Ensure your messages match the expected data type (binary vs text).
No status received
Connection closed without sending a close frame.
Recovery: Treat as unexpected disconnection. Reconnect with backoff. Log the event.
Abnormal closure
Connection closed abnormally without a close frame. Common in trading bot WebSocket drops.
Recovery: This is the most common WebSocket error in trading bots. Reconnect with backoff and check for rate limiting on the endpoint.
Invalid frame payload data
The message payload is invalid (e.g., invalid UTF-8).
Recovery: Validate message encoding before sending. Ensure JSON is well-formed.
Policy violation
Connection rejected due to policy violation (e.g., rate limit exceeded).
Recovery: Check exchange rate limits. Reduce request frequency. Implement proper throttling.
Message too big
The message exceeds the maximum allowed frame size.
Recovery: Reduce message size or split large payloads into smaller chunks.
Internal server error
Server encountered an unexpected condition.
Recovery: Wait and retry with backoff. Check exchange status page for ongoing incidents.
Service restart
Server is restarting. Common during exchange maintenance windows.
Recovery: Reconnect after a delay. Check exchange maintenance schedule.
Try again later
Server is temporarily overloaded. Common during high volatility.
Recovery: Wait and retry with exponential backoff. Reduce connection frequency.
Application reserved
Exchange-specific close code. Refer to exchange WebSocket documentation.
Recovery: Check the exchange-specific WebSocket documentation for the exact meaning.
Rate limited
Connection rejected due to rate limiting on the WebSocket endpoint.
Recovery: Reduce reconnection frequency. Implement exponential backoff with jitter.
Invalid auth
Authentication failed for private WebSocket channels.
Recovery: Verify API key and signature. Regenerate credentials if needed.
Related tools
Exchange Error Code Lookup
LiveLook up exchange API error codes for Binance, Bybit, Kraken, and Coinbase.
Exchange Config Generator
LiveGenerate YAML config snippets for Binance, Bybit, Kraken, KuCoin, and OKX.
Timestamp Drift Checker
LiveDiagnose exchange clock drift and recvWindow errors with an interactive checklist.
Related articles
WebSocket Reconnection
WebSocket Disconnects in Trading Bots
Why WebSockets disconnect during high volatility, what close codes mean, and how to implement proper reconnection strategies with exponential backoff for trading bots.
Rate Limit Storms
Trading Bot 429 After Deploy
How rate limiting causes WebSocket drops, why close code 1013 means try again later, and how to configure reconnection timing to avoid cascading failures.
Exchange API Bans
How to Prevent Getting Banned by Exchanges
How aggressive WebSocket reconnection can trigger IP bans, and how to implement rate-limit-aware reconnection that respects exchange policies.
Bot Building
Why Most Crypto Trading Bots Fail
Why WebSocket reliability is one of the top reasons bots fail in production, and how connection management separates reliable bots from failing ones.
Resources and kits
Kit
WebSocket Reconnection Kit
Production-ready WebSocket reconnection patterns with exponential backoff, close code handling, and rate-limit-aware reconnection for exchange streams.
Runbook
Exchange API Ban Prevention
Fast triage for rate limit and WebSocket connection failures across exchanges with reconnection best practices.
Kit
Crash Recovery and Reconciliation
Code template for handling WebSocket disconnections and recovering state after connection drops during trading operations.
Product
AlgoTrak Production Trading Bot
Production-grade crypto trading bot with robust WebSocket connection management, automatic reconnection, and rate-limit-aware stream handling. 14 strategies, full source code, and deployment guide.
Frequently asked questions
What is the most common WebSocket close code in trading bots?
How should I handle WebSocket reconnection?
What causes WebSocket rate limiting?
Newsletter
Weekly engineering insights
Get practical tips on AI, .NET, trading bot reliability, and building scalable systems. No spam, unsubscribe anytime.
What engineers say
“The retry policy generator alone saved us from a production incident. We had exponential backoff configured wrong for months — the timeline visualization made it obvious instantly.”
Alex R.
Senior Backend Engineer, Fintech Startup
WebSocket keeps dropping?
I help teams build reliable WebSocket connections for trading bots with proper reconnection strategies, rate limit handling, and monitoring.