> ## Documentation Index
> Fetch the complete documentation index at: https://alltick.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket API Overview

> This documentation covers AllTick’s stock WebSocket interface, including realtime trade tick streaming, order book depth updates, subscription and cancel methods, heartbeat mechanism, and message format examples, enabling developers to build low-latency quote systems for US, HK, and China A-share markets.

The AllTick WebSocket API is used to receive real-time quote pushes. After a connection is established, the client sends a subscription request, and after the subscription succeeds, the server continuously pushes latest trade price and latest order book data. During the connection, heartbeats must be sent as required to avoid timeout disconnection.

## Connection Addresses

| Data Type                                                                         | WebSocket Address                                              |
| --------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| US stocks, Hong Kong stocks, A shares, and major index data                       | `wss://quote.alltick.co/quote-stock-b-ws-api?token=your_token` |
| Forex, precious metals, cryptocurrencies, crude oil, CFD indices, and commodities | `wss://quote.alltick.co/quote-b-ws-api?token=your_token`       |

Each time a connection is established, your authentication token must be appended to the URL. After the connection succeeds, send latest trade price or latest order book subscription requests as needed.

## Interface List

<CardGroup cols={2}>
  <Card title="Latest Trade Price (Real-time Tick Data, Current Price, Latest Price) Batch Subscription" href="/en/websocket/trade-subscription">
    Subscribe to the latest trade price of products. After the subscription succeeds, trade data is pushed through protocol number 22998.
  </Card>

  <Card title="Latest Order Book (Real-time Tick-by-Tick Depth, Order Book) Subscription" href="/en/websocket/depth-subscription">
    Subscribe to the latest order book depth of products. After the subscription succeeds, order book data is pushed through protocol number 22999.
  </Card>

  <Card title="Heartbeat" href="/en/websocket/heartbeat">
    Send a heartbeat every 10 seconds. If no heartbeat request is received within 30 seconds, the WebSocket connection will be disconnected.
  </Card>

  <Card title="Cancel Quote Subscription" href="/en/websocket/cancel-subscription">
    Cancel all quote subscriptions, or cancel order book, trade, or exchange-rate subscriptions by type.
  </Card>

  <Card title="K-Line Push (Not Supported)" href="/en/websocket/kline-push-not-supported">
    WebSocket does not support K-line push. K-lines can be polled or batch queried through HTTP interfaces.
  </Card>

  <Card title="WebSocket Request Example" href="/en/websocket/websocket-request-example">
    View WebSocket request examples for Go, Java, PHP, and Python.
  </Card>
</CardGroup>

## Protocol Number Overview

| Protocol Number | Description                                        |
| --------------- | -------------------------------------------------- |
| 22004 / 22005   | Latest trade price subscription request / response |
| 22998           | Latest trade price push                            |
| 22002 / 22003   | Latest order book subscription request / response  |
| 22999           | Latest order book push                             |
| 22000 / 22001   | Heartbeat request / response                       |
| 22006 / 22007   | Cancel quote subscription request / response       |

## Usage Flow

1. Select the stock or non-stock WebSocket address according to the product type.
2. Append the token to the connection URL and establish the WebSocket connection.
3. Send a latest trade price or latest order book subscription request.
4. Send a heartbeat request every 10 seconds to keep the connection valid.
5. Receive data pushed by the server and handle automatic reconnection according to business needs.
6. When pushes are no longer needed, send a cancel quote subscription request.

<Note>
  For each WebSocket connection, every time a subscription request is sent, the backend overwrites the previous subscription request by default. When adding products, you need to resend the complete product list.
</Note>

<script src="/seo-keywords.js" />
