chstockdata
Free China A-share market data toolkit — direct HTTP/TCP access to public quote vendors, no API keys, no third-party data SDKs (akshare-free by design), battle-tested in production by TradingAgents-astock.
pip install chstockdata # core (pandas/requests only)
pip install "chstockdata[mootdx]" # + mootdx TCP K-line source (optional)
pip install "chstockdata[baostock]" # + historical turnover for CYQ chips (optional)
from chstockdata import get_stock_data, get_realtime_snapshot, resolve_ticker
resolve_ticker("贵州茅台") # -> "600519" (Chinese name -> 6-digit code)
df = get_stock_data("600519", 365) # daily OHLCV, vipdoc/mootdx/Sina chain
get_realtime_snapshot("600519") # realtime quote, Tencent -> mootdx -> Sina
53 public functions: K-lines, realtime quotes, fundamentals / three financial
statements, valuation history, margin trading, dragon-tiger board (per-stock
seats and whole-market daily), lockup expiry, northbound flow, fund flow, board
fund flow, industry comparison, concept blocks, block trades, market breadth,
limit-up / failed-board / limit-down / previous-day limit-up pools, CYQ chip
distribution, ETF option chains (T-quote + greeks + IV), investor Q&A (互动易),
hot rank / popularity rank / concept hits, insider transactions, shareholder
pledge / buyback, corporate actions, earnings forecast, research reports, news
wires, policy news, macro indicators, trading calendar, delisting / suspension
info, and more. See chstockdata/__init__.py for the full export list.
Data sources
| Source | Protocol | Data |
|---|---|---|
| mootdx | TCP 7709 | OHLCV K-lines, realtime snapshots, financial snapshots, F10 text |
| TDX official after-market archive | HTTP (data.tdx.com.cn/vipdoc) |
Full SH/SZ/BJ daily-bar archive → local vipdoc tree (primary history source) |
| Tencent Finance | HTTP (qt.gtimg.cn) |
Realtime quotes (primary), PE/PB/market cap/turnover |
| easy-tdx (isolated process) | TCP 7709 | L1 fund-flow reconstruction, TDX industry/concept board rankings |
| Eastmoney datacenter / F10 / emappdata / bkzj | HTTP | Dragon-tiger (per-stock + market-wide), lockup, holders, concept blocks, news, announcements, limit-up pools (push2ex), board fund flow, popularity rank, concept hits |
| Sina Finance | HTTP | Realtime fallback, K-line fallback, daily fund flow, financial statements, ETF option contracts / T-quote / greeks + IV |
| baostock (optional extra) | TCP | Historical daily turnover + ST/suspension flags for CYQ chip distribution (no Beijing exchange) |
| 同花顺 10jqka | HTTP | Consensus EPS, hot stocks, limit-up reasons, hot rank |
| 财联社 cls.cn | HTTP | Global news wire |
| SSE / SZSE official | HTTP | Northbound daily turnover (trusted), delisting list |
| 巨潮 cninfo | HTTP | Investor Q&A (互动易) |
All Eastmoney requests go through a module-level serial throttle
(EM_MIN_INTERVAL, default 1.0s) with jitter and a shared keep-alive session
— do not bypass it, do not fan out concurrent full-market scans. push2 /
push2his are deliberately not used (see tests/test_astock_push2_source_scan.py).
Hardening carried over from production
This package is not a scraper starter kit; it is an extraction of a data layer that survived months of live A-share analysis runs:
- Realtime fallback chain Tencent → mootdx → Sina, with zombie-quote detection (zero-amount + price == prev-close) so suspended/legacy tickers cannot silently poison valuations.
- mootdx canary server selection: TCP reachability is not enough — every candidate must serve one real K-line bar before adoption; dead pools get an exponential-backoff negative cache (5min → 6h, immediate 6h outside trading hours).
- Local vipdoc history layer: after the official TDX archive is refreshed
(via
chstockdata-refresh-vipdoc), historical daily bars are read from disk with zero network and never trigger full server-pool probing. - Point-in-time filtering for historical analyses (financial records are clipped to the analysis date).
- Known pitfall fixes verified against live data: Tencent total/float
market-cap fields swapped, static-PE wrong slot, BJ-exchange 920-prefix
routing, Eastmoney lockup column renames, block-trade premium-ratio unit
(decimal → percent), northbound SSE holiday
result:[null]handling, and more — each guarded by regression tests ported from the incidents.
Configuration
Zero-config works out of the box. Optional overrides, in priority order:
from chstockdata import configure
configure(cache_dir="...", vipdoc_dir="...", vipdoc_enabled=True,
vipdoc_max_staleness_days=5, northbound_store_path="...")
Environment variables (both prefixes accepted): CHSTOCKDATA_CACHE_DIR,
CHSTOCKDATA_VIPDOC_HISTORY_DIR, ... or the legacy
TRADINGAGENTS_VIPDOC_HISTORY_* / TRADINGAGENTS_DATA_CACHE_DIR names.
Tuning knobs: EM_MIN_INTERVAL (Eastmoney throttle seconds),
TDX_MIN_INTERVAL, TDX_TOOL_PROBE_BUDGET_SECONDS,
EASY_TDX_PYTHON (path to an isolated venv python with easy-tdx==1.20.6).
MCP server (for AI agents)
pip install "chstockdata[mcp]"
chstockdata-mcp
Then register in any MCP client (Claude Code, etc.):
{ "mcpServers": { "chstockdata": { "command": "chstockdata-mcp" } } }
Risk & usage notes
- All endpoints are public, unofficial interfaces of the respective vendors. Rate-limit thresholds cited anywhere in the docs are community observations, not vendor guarantees; endpoints can break or change at any time without notice.
- Built-in throttling must be kept as-is. For heavy or commercial workloads use official paid feeds (Eastmoney Choice, exchange data services).
- Data is provided for research/educational purposes, as-is, with no warranty of accuracy or fitness for trading decisions.
Relationship to upstream projects
Extracted from TradingAgents-astock
(Apache-2.0, itself a fork of TauricResearch/TradingAgents).
Starting with 0.2.0, selected upstream-unique endpoints of
a-stock-data (Apache-2.0) were
reverse-ported: ETF options (contracts / T-quote / greeks + IV), limit-up pools
(including the previous-day pool and THS limit-up reasons), CYQ chip
distribution, market-wide dragon-tiger board, board fund flow, investor Q&A
(互动易), hot rank / popularity rank / concept hits, and the upstream ticker
routing fix (market identifier conflicts fail loud; 5x ETFs route to
Shanghai).
This package is still not a full superset of a-stock-data. Deliberately not
included: intraday anomaly pools (product hard boundary in the source project),
Shenwan industry history, minute/tick order flow, and any push2/push2his
dependency (board fund flow uses the non-push2 bkzj endpoint with a reduced
field set — no four-tier breakdown). See MIGRATION.md and
docs/planned-upstream-ports.md.
License
Release files for chstockdata 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chstockdata-0.2.0.tar.gz | 297.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chstockdata-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 524.8 kB
Release files / chstockdata-0.2.0.tar.gz
| Download URL | chstockdata-0.2.0.tar.gz |
|---|---|
| Size | 297.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
782485328aa1d42ad5d5ed75aeded469ce8f418a7a96ee0d3572db7776bd4c88
|
|
BLAKE2b-256 checksum How to use checksums |
5ef9f07587d16b739cb9322ddb97da6c93e3172fa8ceee943f86893e626c3f03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.
Transparency logRelease files / chstockdata-0.2.0-py3-none-any.whl
| Download URL | chstockdata-0.2.0-py3-none-any.whl |
|---|---|
| Size | 227.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cbe67a4a6ffbae50364f91c72d701ede551f0c5f1828594409a430ac19c0b32
|
|
BLAKE2b-256 checksum How to use checksums |
60e06952670dd4225afd51bbbb61a7f3fcf01b620971f5d5fa5bf41960bec9b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.
Transparency log