
How to Choose a Real-Time China A-Share API: Define the Data You Actually Need
Choose the right real-time A-share API by understanding quotes, Tick data, market depth, REST API, and WebSocket. Explore AllTick's data features and plans.
When a fintech team adds Chinese mainland stocks to a market-data dashboard, one of the first requirements is usually simple: stock prices must update in real time.
But that requirement needs to be defined before choosing a China A-share market data API. Does the application only need the latest traded price? Does it need every incoming trade update? Or must it display bid and ask prices with order-book quantities?
These are different data requirements, even though they are often described using the same word: real-time.
For example, a stock watchlist may only need to retrieve the latest price every few seconds. A market-monitoring application, on the other hand, may need to receive continuous trade updates for multiple Shanghai and Shenzhen stocks and refresh its displayed data as new events arrive. Using the same data retrieval method for both applications may introduce unnecessary requests or leave the application without the information it needs.
Choosing a real-time A-share API starts with identifying the data your application needs and how frequently that data must be updated—not simply comparing advertised latency figures.
What Types of Real-Time A-Share Data Do You Need?
One common mistake when evaluating a China stock market API is treating the latest quote, real-time Tick data, order-book depth, and historical candlesticks as interchangeable.
They serve different purposes.
| Data type | What it provides | Typical use case | Common access method |
|---|---|---|---|
| Latest quote | Latest traded price and related market fields | Stock lists, quote dashboards | REST API |
| Real-time Tick | Continuous individual trade updates | Market monitoring, trade information display | WebSocket |
| Order-book depth | Bid and ask prices with corresponding quantities | Order-book displays and depth analysis | REST API / WebSocket |
| Historical K-lines | Open, high, low, close, volume, and other periodic data | Charts and historical analysis | REST API |
Consider a stock watchlist that displays the latest price when a user opens the page and refreshes it periodically. A REST API request can be sufficient for this requirement. The application retrieves the latest available quote and updates the interface without maintaining a permanent connection for every page.
The situation changes when an application needs to receive ongoing trade updates. If it only polls the latest price through HTTP requests, multiple trades may occur between two requests. The next response may show the latest available state, but it does not necessarily provide every individual trade event that occurred in between.
This is where real-time Tick data becomes important. Tick data represents individual market updates rather than simply repeating a request for the current price.
Order-book depth is another separate requirement. The latest traded price tells the application the price of the most recent transaction, while the order book shows available bid and ask prices and their corresponding quantities. An application that needs to display bid and ask levels cannot rely on the latest trade price alone.
Before selecting an A-share data API, define whether the application needs quote snapshots, individual trade updates, or order-book information. This decision can prevent unnecessary integration changes later.
REST API vs. WebSocket: Which Should You Choose?
Once the required data types are clear, the next decision is how to retrieve them.
REST API and WebSocket are not direct replacements for each other. REST is designed for request-based access, while WebSocket is designed for continuous data delivery after a connection and subscription have been established.
For a stock list that only needs the latest prices, REST API is usually straightforward. The application sends an HTTP request when it needs an updated snapshot and refreshes the displayed values according to its requirements. If many stocks must be initialized at the same time, check whether the provider supports batch requests rather than sending a separate request for every symbol.
WebSocket is more suitable for applications that need continuous market updates. After the client connects and subscribes to selected instruments, the server pushes matching updates to the application. This avoids repeatedly sending HTTP requests just to check whether the price has changed.
The two approaches can also work together. A common architecture uses REST API to retrieve the initial quote state and WebSocket to receive subsequent updates.
There is one implementation detail worth considering: data may arrive out of order. For example, a REST response requested earlier may arrive after a newer WebSocket Tick. If the application blindly applies that older response, it could overwrite a more recent market state. Use timestamps or sequence information to manage updates correctly.
Another important limitation is that WebSocket support does not automatically mean every type of market data is available through streaming.
Historical K-lines, for example, are queried through HTTP APIs. Do not assume that a WebSocket connection can subscribe to historical or continuously updated minute candlesticks unless the provider explicitly supports that data type. AllTick distinguishes between its Tick, order-book, and K-line access methods.
Receiving China A-Share Trade Updates with AllTick
For an application that needs to receive continuous A-share trade updates, AllTick provides a dedicated Stock WebSocket API.
The stock and broad-market WebSocket endpoint is different from the endpoint used for forex, crypto, and commodity data. Before subscribing, the application should also verify that each instrument is included in the supported symbol list.
China A-shares use exchange-qualified symbols. Shanghai-listed stocks use the .SH suffix, while Shenzhen-listed stocks use .SZ. AllTick's onboarding documentation includes examples such as 600416.SH and 000627.SZ.
The following Python example demonstrates how to subscribe to real-time trade updates for one A-share.
First, install the WebSocket client library:
pip install websocket-clientThen establish the connection and send a trade subscription request:
import json
import os
import time
import uuid
import threading
import websocket
TOKEN = os.environ["ALLTICK_TOKEN"]
STOCK_CODE = "600416.SH"
WS_URL = (
"wss://quote.alltick.co/"
"quote-stock-b-ws-api?token=" + TOKEN
)
def send_heartbeat(ws):
while ws.sock and ws.sock.connected:
time.sleep(10)
try:
if ws.sock and ws.sock.connected:
heartbeat = {
"cmd_id": 22000,
"seq_id": 1,
"trace": "heartbeat",
"data": {}
}
ws.send(json.dumps(heartbeat))
except Exception as exc:
print("Heartbeat error:", exc)
break
def on_open(ws):
subscription = {
"cmd_id": 22004,
"seq_id": 1,
"trace": uuid.uuid4().hex,
"data": {
"symbol_list": [
{"code": STOCK_CODE}
]
}
}
ws.send(json.dumps(subscription))
threading.Thread(
target=send_heartbeat,
args=(ws,),
daemon=True
).start()
def on_message(ws, message):
result = json.loads(message)
if result.get("cmd_id") == 22005:
if result.get("ret") == 200:
print("Subscription confirmed")
else:
print("Subscription failed:", result.get("msg"))
elif result.get("cmd_id") == 22998:
tick = result.get("data", {})
print({
"code": tick.get("code"),
"time": tick.get("tick_time"),
"price": tick.get("price"),
"volume": tick.get("volume"),
"turnover": tick.get("turnover"),
"direction": tick.get("trade_direction")
})
def on_error(ws, error):
print("WebSocket error:", error)
def on_close(ws, status_code, message):
print("Connection closed:", status_code, message)
client = websocket.WebSocketApp(
WS_URL,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close
)
client.run_forever()The important part is not simply establishing the WebSocket connection. It is understanding the subscription protocol and handling the incoming messages correctly.
In this example, 22004 is the trade subscription request, 22005 is the subscription response, and 22998 is the server-side trade data push. The code checks whether the subscription response contains ret == 200 before treating it as successful. Once trade updates arrive, the application can identify the instrument and retrieve fields such as the latest price, volume, turnover, trade time, and trade direction.
The API Token is read from an environment variable rather than being hardcoded into the source file or a public repository. The WebSocket connection also requires a heartbeat every 10 seconds. For production deployment, the client should additionally implement error handling, automatic reconnection, and subscription recovery after reconnecting.
There is another important detail when monitoring multiple stocks: AllTick uses an overwrite rule for subscription requests. Sending a new subscription list replaces the previous list on that connection.
For example, suppose the application initially subscribes to 10 stocks and later needs to add another five. Sending only the five new symbols will replace the original subscription list. The application should resend the complete list of 15 symbols that it wants to keep subscribed.
If the application also needs to display bid and ask depth, it can use the order-book subscription protocol 22002 and handle the corresponding push protocol 22999. Trade updates and order-book updates should be processed as separate data streams rather than treating the latest traded price as a bid or ask quote.
What Else Should You Check When Choosing a China Stock Market API?
An API returning valid data does not automatically mean it is suitable for your application. Symbol coverage, subscription capacity, and market-session handling can all affect the integration design.
First, verify that the required stock symbols are supported.
Chinese A-shares use exchange-specific suffixes such as .SH and .SZ. Symbol formats may differ between providers, so do not assume that the same format used for US or Hong Kong stocks will work for mainland China instruments.
With AllTick, check the official instrument list before integration. Confirm the exact symbol, exchange suffix, and available trading information. ST stocks, suspended stocks, and recently listed instruments should also be checked individually rather than assumed to be available.
Next, estimate how many instruments must be monitored simultaneously.
Suppose a market-information dashboard needs to monitor 100 A-share symbols continuously. The relevant questions are not limited to how many products a plan allows you to select. You should also check the number of WebSocket connections and the applicable symbol subscription limits.
The ability to query an instrument does not necessarily mean that every selected instrument can be subscribed to simultaneously without restrictions.
Finally, distinguish market closures from connection failures.
The China A-share market has different trading periods, including the morning session, lunch break, and afternoon session. During the lunch break, the application may not receive new trade Tick updates. This does not necessarily mean that the WebSocket connection has failed.
The application should track market sessions, instrument trading status, connection state, and the timestamp of the last received update separately. When a connection is still active but no new trade message arrives, the system should consider whether the market is closed or the instrument is suspended before initiating a reconnect.
This helps avoid unnecessary reconnection attempts and prevents normal market inactivity from being mistaken for a network problem.
Can AllTick Plans Support Different A-Share Data Requirements?
For an initial integration test, the AllTick Free plan can be a starting point. However, its 10 demo products do not mean that a developer can select any 10 individual A-share stocks.
The Free plan includes demo instruments such as the Shanghai Composite Index and Shenzhen Component Index, allows up to 10 API calls per minute, and provides one WebSocket connection. Developers who need individual A-share symbols should check whether their required instruments are available under the selected plan.
For applications that monitor more products, the Basic, Premium, and Professional plans offer different capacities. According to the published plan information, they support 100, 200, and 3,000 selected products respectively, with different API request limits and WebSocket connection allowances.
For applications that require broad coverage of the Shanghai and Shenzhen markets, AllTick also offers an All A-Shares plan.
The published plan covers approximately 5,000 A-share symbols, excluding ST/*ST stocks. It includes the latest prices, historical data for the latest 500 K-lines, order-book data, and real-time Tick data.
One distinction matters here: approximately 5,000 covered symbols does not mean that 5,000 symbols can automatically be subscribed to simultaneously over WebSocket. The actual subscription limits and connection allowances must be checked against the account's current entitlement.
For a dashboard that starts with several dozen instruments and may expand later, it is usually more practical to choose a plan based on the current symbol count and data requirements rather than paying for market coverage that the application does not yet need.
Data usage rights are equally important. AllTick's published terms state that its data is provided for informational purposes only, is not intended for trading or investment purposes, and must not be redistributed. If an application is intended to provide market data to external users, confirm the applicable permissions before deployment. Technical access to an API should not be interpreted as permission for unrestricted commercial redistribution.
Choose an A-Share API Based on the Data Your Application Needs
A real-time China stock market API is not automatically the best choice simply because it advertises low latency or broad symbol coverage.
For a basic stock dashboard, the latest quote may be sufficient. For continuous trade-information updates, Tick data is more relevant. For an application that displays bid and ask levels, order-book depth must also be available.
If you are building a stock dashboard or financial information application that needs China A-share coverage, start by checking three things: whether the required symbols are supported, whether the API provides the necessary data types, and whether its subscription and request limits match the expected application scale.
AllTick provides Stock REST API access, WebSocket market-data streaming, and plans for different levels of instrument coverage. Start with the AllTick Stock API product page to review market coverage. Then consult the API documentation and API onboarding guide to verify request formats, response fields, and subscription protocols. Once the expected instrument count is clear, compare the available options on the AllTick pricing page.
The right China A-share API is not simply one that can return a stock price. It is one that provides the data types, update methods, and instrument coverage your application actually requires.