WebSocket
Last Updated: November 19, 2026
What Is WebSocket?
WebSocket is a communication protocol that keeps one connection open between a client, such as a browser or trading app, and a server, so both sides can send data at any time. The IETF standardized it as RFC 6455 in December 2011.
A WebSocket connection starts as a normal HTTP request. The client asks the server to upgrade the connection, and if the server agrees, both keep the same TCP connection open. From then on, messages flow in both directions without a new request each time.
How It Works
With ordinary HTTP, a client has to ask again every time it wants fresh data, a pattern called polling. WebSocket removes that step. The server pushes each update the moment it happens, which cuts delay and saves bandwidth when data changes often, as it does in markets.
WebSocket powers many live services, including multiplayer games, stock tickers, poker games and chat rooms. Gaming is a typical case: the User Interface (UI) keeps one open link to the server, so it can show new data without reloading the page.
Why Crypto Platforms Use WebSocket
Crypto markets trade around the clock, and prices can change many times a second. Exchanges therefore offer WebSocket streams for trades, order book changes and tickers. Trading apps, bots and price sites subscribe to these streams instead of asking an API for new data over and over.
Binance’s WebSocket documentation sets the rules for its public streams. Connections go to wss://stream.binance.com on port 9443 or 443, a single connection lasts at most 24 hours, the server sends a ping every 20 seconds, and one connection can follow up to 1,024 streams. Clients may send at most 5 messages per second.
Coinbase runs a similar service for Advanced Trade at wss://advanced-trade-ws.coinbase.com, with channels such as ticker, level2, market_trades and heartbeats. According to its developer docs, most market data channels no longer need authentication, but a client must send a subscribe message within 5 seconds or the server closes the connection.
Example: A Live Bitcoin Trade Stream
On November 16, 2026, a test connection to Binance’s public BTC/USDT trade stream received 91 trade messages in about 10 seconds, starting at 19:47 UTC. The first showed a trade of 0.00008 BTC at 64,776.53 USDT. Each message carries the symbol, trade ID, price, quantity, trade time and whether the buyer was the market maker.
Depth streams work the same way and send each change to the order book as it happens, which lets an app keep a live copy of bids and asks.
Limits and Risks
A WebSocket feed is only as good as its connection. Streams can drop, lag or arrive out of order, so apps must reconnect, resubscribe and sometimes rebuild their order book from a fresh snapshot. Exchanges also stamp trades with their own times, one reason live prices differ between sites, as the 24h change entry explains.
Chat apps are another classic use: the app opens one WebSocket connection and reuses it to send messages to many users. For a step-by-step explanation, see this complete guide to WebSocket.
WebSocket vs Polling vs Webhooks
There are three common ways to get fresh data. With polling, the app asks the server again and again, which wastes requests when nothing has changed. With WebSocket, one connection stays open and the server pushes each update. With webhooks, the server sends an HTTP request to an address the app has set up whenever an event happens, such as a deposit arriving in an account.
Each suits a different job. Trading screens need the steady flow of WebSocket. Payment systems often use webhooks, because they only care about single events. A simple script that checks a price once a minute can poll a REST endpoint without much cost.
ws:// and wss://
WebSocket addresses start with ws:// or wss://. The plain ws:// form sends data unencrypted, usually on port 80. The secure wss:// form wraps the connection in TLS, the same encryption used by HTTPS, usually on port 443. Binance and Coinbase publish wss:// addresses for their streams, so price and account data are protected while they travel.
Frequently Asked Questions
What is the difference between WebSocket and a REST API?
A REST API answers one request at a time: the app asks, the server replies, and the exchange is over. WebSocket keeps one connection open so the server can push updates as they happen. Crypto apps often use both, REST for account data and one-off requests, and WebSocket for live prices, trades and order book changes.
Do I need an API key to use exchange WebSocket streams?
Usually not for public market data. Binance’s public trade and ticker streams and most Coinbase Advanced Trade market data channels can be read without a key. Private streams, such as your own orders and balances, need authentication, often with signed tokens. Any key used for these streams should be protected like a password.
Why does a WebSocket price feed sometimes stop?
Exchanges close connections on purpose. Binance ends every connection after 24 hours and drops clients that do not answer its regular ping, and Coinbase disconnects clients that fail to subscribe within 5 seconds. Networks also fail. Well-built apps notice the drop, reconnect, resubscribe and reload a snapshot so they do not show stale prices.
Is WebSocket faster than a REST API?
For live data, usually yes. A REST call needs a new request each time, and every request adds delay. A WebSocket connection is set up once, so each update arrives as soon as the server sends it. For a single request, such as checking a balance once, the difference is small, and REST is often simpler to build and test.
Data sources: IETF RFC 6455 (December 2011); Binance WebSocket Streams documentation and Coinbase Advanced Trade WebSocket overview (read November 16, 2026); live Binance BTC/USDT trade stream test (19:47 UTC, November 16, 2026).