Getting Started

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-api

Connecting and Subscribing

  1. Connect: Open a WebSocket connection using the URL with your API Key shown above
  2. Subscribe to channels: After connecting, send a subscribe message; channels can contain one or more channels
  3. Keep the heartbeat going: We recommend sending ping every 20 seconds; receiving pong means the connection is working
  4. Unsubscribe: When you no longer need a channel, send an unsubscribe message
{
    "method": "subscribe",
    "channels": ["liquidation_orders"]
}
{
    "method": "unsubscribe",
    "channels": ["liquidation_orders"]
}
⚠️

Connection management

When 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

ChannelNameDescription
liquidation_ordersLiquidation Order StreamReal-time liquidation orders for futures across the whole market
spot_tradesSpot TradesTick-by-tick spot trades for a specified exchange and trading pair
futures_tradesFutures TradesTick-by-tick futures trades for a specified exchange and trading pair
futures_tickerFutures Ticker SnapshotMarket 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 plan

The 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