How to Access and Apply Level-2 Data APIs for Shanghai and Shenzhen Stocks
This guide explains the compliance requirements, access methods, API options, and cloud-based architecture for obtaining and using Level-2 data from the Shanghai and Shenzhen stock markets. It compares raw exchange feeds with parsed APIs and discusses applications such as order book reconstruction, microstructure analysis, event-driven strategies, and scalable data pipelines.
How to Access and Apply Level-2 Data APIs for Shanghai and Shenzhen Stocks
In quantitative trading and market microstructure research, Level-2 data is widely regarded as one of the most valuable sources of real-time information in the secondary market. Unlike conventional three-second tick snapshots, Level-2 feeds provide detailed transaction-by-transaction and order-by-order data, generating millions of records each trading day.
This high-frequency, high-density data makes it possible to study market intent in greater depth. At the same time, it creates significant challenges related to data access, regulatory compliance, and technical modeling. This guide examines the practical considerations of connecting to Shanghai and Shenzhen stock Level-2 data from four perspectives: licensing and compliance, access technology, API selection, and application architecture.
1. Compliance Requirements and Access Paths
The first issues to consider when obtaining Shanghai and Shenzhen Level-2 data are compliance and cost. Exchanges generally apply strict licensing requirements, which can be divided into two main categories.
1. Display licenses
These licenses are typically issued to major market-data terminal providers. They allow providers to display deep market data—such as ten levels of quotes and trade-by-trade transactions—on desktop or mobile applications.
However, display licenses generally restrict data storage and redistribution through secondary APIs. Developers therefore cannot legally build an independent data interface by scraping a market-data terminal.
2. Datafeed licenses
A datafeed license is the type of authorization most relevant to quantitative trading and system development. Organizations holding this type of license are generally not permitted to display market data externally, but they can obtain the original data stream through an authorized interface.
Historically, datafeed licenses were mainly available to authorized information providers, public funds, brokerages, and other exchange members. The annual fee for a single exchange could reach RMB 300,000, while the total cost of connecting directly to official dedicated lines could easily exceed RMB 600,000. This made direct access difficult for many smaller organizations.
3. Policy changes and data-center forwarding
As exchange policies have evolved, information providers or member institutions with datafeed licenses may forward market data to downstream customers from designated data centers. This model has substantially lowered the entry barrier for ordinary enterprises. Forwarding costs have fallen from several hundred thousand yuan to tens of thousands of yuan per year in some cases.
Exchanges have also made historical Level-2 data available for purchase. For small institutions and individual developers with limited budgets, compliant forwarding services provided through authorized data centers can offer a relatively affordable way to obtain real-time Level-2 data.
2. Comparing Raw Dedicated-Line Feeds with Parsed Data APIs
After selecting a compliant data channel, a technical team must choose an appropriate access and processing model based on its engineering capabilities.
1. Raw protocol access and order book reconstruction
Data delivered through an exchange-dedicated line is typically an unprocessed binary protocol stream. This approach offers the lowest possible latency, but it also has a high technical barrier.
Developers must decode the underlying messages and reconstruct the local order book. This process involves handling order submissions, executions, cancellations, and other events while accurately maintaining real-time changes across the ten-level order book—or even the full order book where available.
This approach requires substantial expertise in low-level network programming and financial data structures.
2. Accessing parsed data APIs
Teams that do not want to build a decoder from scratch can use a standardized API provided by a market-data vendor. These services encapsulate complex decoding and order book reconstruction logic, exposing structured data through formats such as JSON or Protobuf.
Developers can then access market data through RESTful APIs or WebSocket connections. This significantly reduces development effort and allows the team to focus on strategy research and modeling rather than low-level feed processing.
3. Common API Types and Their Technical Characteristics
The market offers a wide range of data-access options. Developers should select tools according to their specific business and research requirements. Common solutions fall into three categories.
1. Open-source and free financial databases
These services often cover major global markets and provide Python-friendly interfaces without registration fees. Their main limitation is weak real-time performance. Data may be delayed by 15 to 20 minutes, and the available frequency is usually limited to daily or minute-level bars.
Such services are suitable for historical backtesting, educational demonstrations, and lightweight macro analysis. They are not suitable for accessing real-time Level-2 market data.
2. Professional real-time data provider APIs
Professional data providers serving the A-share market offer real-time Level-2 APIs. These services commonly use a free basic tier combined with paid advanced features. They typically provide specialized A-share coverage, strong real-time performance, and built-in interfaces for calculating technical indicators.
For teams conducting A-share quantitative trading, real-time monitoring, or detailed market microstructure analysis, this type of service is often the most practical option. Data is commonly delivered through WebSocket streams with millisecond-level latency, offering significantly better responsiveness than three-second snapshots.
3. Broker-integrated client APIs
Some quantitative trading clients include built-in Level-2 market-data modules. However, the data is often tightly integrated into the client and difficult to expose to external systems through a standard interface.
These solutions may be appropriate for strategy development within a specific brokerage ecosystem, but they are generally unsuitable for building an independent market-data platform.
4. Level-2 Applications and Modeling Practices
The value of Level-2 data depends on how effectively it is analyzed. With millions of transactions generated each day—far beyond the limits of manual observation—effective use requires robust data-processing and modeling capabilities.
1. Trade-by-trade and market microstructure analysis
Trade-by-trade data can be used to build factors and models such as large-order impact indicators and comparisons between aggressive buying and selling pressure.
For example, a model can analyze a continuous stream of aggressive buy orders to identify possible accumulation behavior by large market participants. This type of analysis requires high-throughput stream processing and places demanding requirements on system performance.
2. Price triggers and event-driven strategies
Level-2 data is also valuable for strategies that are not classified as high-frequency trading. Developers can define trigger conditions based on order book changes, such as:
- A sudden increase in the quantity posted at the best bid
- A transaction-average price that deviates from the average price implied by the order book
When a condition is met, the system can immediately generate a trading signal. Compared with periodic polling based on snapshot data, this event-driven architecture responds more quickly to short-lived market changes.
5. Building a Data Pipeline on a Cloud Infrastructure
When processing large volumes of Level-2 data, the performance of a single machine can quickly become a bottleneck. A scalable data pipeline built on cloud infrastructure can provide a more flexible foundation.
For example, general-purpose cloud products from Baidu AI Cloud can be used to support a quantitative infrastructure with the following components:
- Message queues: Receive high-concurrency Level-2 market-data streams and provide buffering, load smoothing, and broadcast distribution. This helps prevent downstream strategy services from failing during data bursts.
- Object storage: Combined with a big-data processing engine, object storage can persist large volumes of historical trade-by-trade data at relatively low cost for offline backtesting and model training.
- Container platforms: Provide elastic execution environments for quantitative strategies. Computing capacity can be expanded during periods of high market activity and reduced after the market closes to improve resource efficiency.
- Logging, monitoring, and alerting: Track pipeline latency, packet loss, and strategy execution status in real time, helping maintain the stability of the trading system.
Conclusion
Access to Shanghai and Shenzhen stock Level-2 data has gradually shifted from a high-cost, high-barrier model toward more compliant and accessible distribution channels. When selecting an access solution, developers must balance compliance costs, network latency, and internal engineering capabilities.
Whether a team chooses to reconstruct the order book from a raw exchange feed or use a parsed professional API, the central objective is the same: transform high-density market data into trading signals with predictive value.
Combined with a modern cloud-native architecture, a stable and low-latency data-processing pipeline can become an important source of competitive advantage for quantitative teams operating in the secondary market.
