
Abstract
For cross‑market quantitative research and financial tech prototyping, developers often need to monitor real‑time order‑book data from A‑Share, Hong Kong and US equity markets. Manually switching among multiple market clients brings human‑induced observation latency, and raw market data cannot be directly fed into programs or research models for downstream computation. This article covers practical evaluation criteria for multi‑market stock APIs, together with a runnable Python WebSocket code sample. A single persistent connection is used to subscribe quotes across three markets, providing data foundation for further data processing and prototype research.
Background
When conducting cross‑market financial research and validating quantitative‑strategy prototypes, researchers usually track tickers listed on A‑Share, Hong Kong and US markets. The traditional workflow relies on multiple separate market terminals to view quotes.
Trading‑hour overlap scenarios, such as Hong Kong pre‑auction session coinciding with US pre‑market hours, introduce unavoidable delays during manual cross‑UI price checking. Two practical pain points emerge from this workflow. First, manually observed data cannot interface programmatically; market feeds cannot flow into downstream computation modules. Second, human‑caused lag distorts signal observation and interferes with model validation and logic testing.
To resolve this, I integrated an external market API to converge multi‑market real‑time quotes within one Python program. Based on the basic receiving logic, developers can extend functions for data persistence and technical‑indicator calculation.
Engineering Evaluation Criteria for Multi‑Market Stock APIs
Many services claim global stock‑market coverage. For research‑oriented prototyping, reliability‑focused evaluation is essential, ordered by priority below:
- Native multi‑market coverage The API should natively support A‑Share, Hong Kong and US equities. Some providers only focus on a single overseas market, requiring additional third‑party data sources for remaining regions. Multiple data vendors introduce extra engineering overhead: divergent schemas, timestamp alignment, multi‑source validation and maintenance complexity increase significantly.
- Long‑connection stability and transmission latency Market opening and pre‑auction periods generate massive quote traffic, acting as real‑world stress tests for WebSocket links. Lag or unexpected disconnection breaks real‑time data ingestion. Event‑driven research prototypes stop functioning, and corrupted samples may compromise testing outcomes.
- Cross‑market data‑schema standardization Schema consistency directly impacts code complexity and simulation reliability. Inconsistent field naming, price precision and timestamp formats across markets force heavy parsing and conversion logic in application code. Divergent processing branches raise debugging costs. Prioritize services adopting one unified protocol and field specification for all supported markets.
- Rate limits and billing models Evaluate quota and commercial terms only after data quality and connection stability satisfy research requirements. Low‑cost or even free services are unsuitable for data acquisition work if reliability and standardization cannot be guaranteed.
After benchmarking several vendors, I adopted AllTick API for this implementation. It encapsulates A‑Share, Hong Kong stocks, US equities, forex and other instruments under one unified WebSocket protocol. Identical subscription logic applies for every market. There is no requirement to implement separate parsing modules per venue, simplifying the construction of a unified data‑ingestion layer and lowering cross‑market adaptation overhead.
Python Implementation: Single WebSocket persistent connection for multi‑market real‑time quotes
The demo below is built upon the websocket‑client library. One long‑lived connection subscribes simultaneously to A‑Share, Hong Kong and US market data. The code can run locally or on cloud instances and references official documentation.
import json
import websocket
# Replace with your personal access token
TOKEN = "YOUR_TOKEN"
WS_URL = (
"wss://quote.alltick.co/quote-stock..."
f"?token={TOKEN}"
)
# Sample tickers for A‑Share, US and Hong Kong markets
symbols = [
{"code": "688036.SH"},
{"code": "AAPL.US"},
{"code": "700.HK"},
]
def on_open(ws):
"""Triggered after WebSocket handshake, send market‑data subscription request"""
print("WebSocket connected")
subscribe_req = {
"cmd_id": 22002,
"seq_id": 1,
"trace": "followme_demo",
"data": {
"symbol_list": [
{"code": item["code"], "depth_level": 1}
for item in symbols
]
}
}
ws.send(json.dumps(subscribe_req))
def on_message(ws, message):
"""Quote push callback; extend for persistence or indicator computation"""
try:
payload = json.loads(message)
# Extension points: write to database, message queue, real‑time metric calculation
print(payload)
except json.JSONDecodeError:
print("Invalid JSON message")
def on_error(ws, error):
print(f"WebSocket error: {error}")
def on_close(ws, code, msg):
print(f"WebSocket closed, code:{code}, msg:{msg}")
if __name__ == "__main__":
ws_app = websocket.WebSocketApp(
WS_URL,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close
)
ws_app.run_forever()
Once executed, real‑time streaming output prints to terminal. Millisecond timestamps and unified quote fields are shared across markets, eliminating large sets of conditional branches for market differentiation.
📌 Practical development notes
- This is a minimal demonstration implementation. Auto‑reconnection, exception alerting and data persistence are not included. For long‑running acquisition tasks, implement retry‑with‑backoff logic to mitigate public‑network instability.
- Extend business logic inside the
on_messagecallback. Raw quotes can be written into message queues or time‑series databases for downstream consumers. - Respect API rate limits; avoid subscribing to excessive tickers in one batch.
Implementation Outcomes & Applicable Scenarios
After startup, A‑Share, Hong Kong and US quotes converge within a single program process. Manual switching among multiple terminals is no longer required. Even during high‑traffic Hong‑Kong pre‑auction windows, data delivery maintains low latency, and returned prices align closely with public web‑based market dashboards.
This acquisition solution fits multiple use‑cases: fintech prototyping, real‑time data collection for quantitative research, and market‑sample dataset building. Standardized streaming data reduces logic discrepancies introduced by multi‑source adaptation and improves overall research efficiency.
Conclusion
Building cross‑market quote‑ingestion services requires more than simply retrieving price values. Market coverage, long‑connection robustness and cross‑market schema consistency collectively determine the reliability of upstream research and prototype systems. Using WebSocket persistent connections, A‑Share, Hong‑Kong and US market data can be ingested uniformly to reduce cross‑market processing overhead.
AllTick API used in this work simplifies multi‑market integration through its unified protocol, making it suitable for technical validation tasks including fintech prototyping and market‑sample data collection.
⚠️ Disclaimer: This article shares technical implementation experience. Sample code and third‑party APIs are for educational and prototyping purposes only and do not constitute investment advice. Complete functional and stability testing is mandatory before any production deployment.
تم التحرير 15 Sep 2026, 14:14
إخلاء المسؤولية: الآراء الواردة هنا تعبر فقط عن رأي الكاتب، ولا تمثل الموقف الرسمي لـ Followme. لا تتحمل Followme مسؤولية دقة أو اكتمال أو موثوقية المعلومات المُقدمة، ولا تتحمل مسؤولية أي إجراءات تُتخذ بناءً على المحتوى، ما لم يُنص على ذلك صراحةً كتابيًا.
