Receive liquidation, trade and market data pushed by CoinGlass in real time over WebSocket. This page explains the connection URL, subscribing and unsubscribing, heartbeats and the message format, and applies to all channels.
Connection URL
When connecting, append your API Key to the base URL:
wss://open-ws.coinglass.com/ws-api?cg-api-key={your_api_key}wss://open-ws.coinglass.com/ws-apiConnecting and Subscribing
- Connect: Open a WebSocket connection using the URL with your API Key shown above
- Subscribe to channels: After connecting, send a subscribe message;
channelscan contain one or more channels - Keep the heartbeat going: We recommend sending
pingevery 20 seconds; receivingpongmeans the connection is working - Unsubscribe: When you no longer need a channel, send an unsubscribe message
{
"method": "subscribe",
"channels": ["liquidation_orders"]
}{
"method": "unsubscribe",
"channels": ["liquidation_orders"]
}
Connection managementWhen a network problem occurs, the system automatically closes the connection. Handle reconnection in your code, and resend your subscribe messages after reconnecting. The connection URL contains your API Key, so open the connection on your server, not directly from a web page.
Available Channels
| Channel | Name | Description |
|---|---|---|
| liquidation_orders | Liquidation Order Stream | Real-time liquidation orders for futures across the whole market |
| spot_trades | Spot Trades | Tick-by-tick spot trades for a specified exchange and trading pair |
| futures_trades | Futures Trades | Tick-by-tick futures trades for a specified exchange and trading pair |
| futures_ticker | Futures Ticker Snapshot | Market snapshots of price, open interest, funding rate and more |
WebSocket channels require an API plan of Standard and above; for details, see API Plans and Permissions.
Response Example
When data arrives, the message contains the channel name channel and the data array data. Taking liquidation orders as an example:
{
"channel": "liquidation_orders",
"data": [
{
"base_asset": "BTC",
"exchange": "Binance",
"price": 56738.00,
"side": 2,
"symbol": "BTCUSDT",
"time": 1725416318379,
"volume_usd": 3858.18400
}
]
}For the fields in each channel's data, see the corresponding channel page.
Subscription Permission Rejections
An insufficient plan may produce a text message in the following format; do not assume every message is JSON:
<full subscription argument> need upgrade planThe prefix is the full subscription argument and may include conditions after @. Match it to the original subscription rather than only the bare channel name. This rejection affects that subscription only and does not itself close the connection. Keep other successful subscriptions and avoid retrying the same unauthorized subscription indefinitely. Handle authentication failures, network interruptions and connection closure separately.
FAQ
How do I recover after a disconnection?
Reconnect with gradually increasing intervals of 1, 2 and 4 seconds, and resend your subscribe messages once connected; if a corresponding REST endpoint is available, use it to query data from the disconnection period within its queryable range. For liquidation orders, this range is the last 7 days.
How many channels can one connection subscribe to?
channels is an array, so you can include multiple channels in one subscribe message. There is no limit on the number of WebSocket connections.
What is the difference between WebSocket push and REST polling?
Polling requires repeated requests that use up your quota, and can miss data between two requests; with WebSocket, the server pushes data as soon as an event happens, with lower latency and fewer requests.
Related Docs
- Authentication: API Key and WebSocket authentication
- API Plans and Permissions: endpoints and channels available on each API plan
- Error Codes and Rate Limits: return codes and rate limiting
