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)
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
39 public functions: K-lines, realtime quotes, fundamentals / three financial
statements, valuation history, margin trading, dragon-tiger board, lockup
expiry, northbound flow, fund flow, industry comparison, concept blocks,
block trades, market breadth, insider transactions, shareholder pledge /
buyback, corporate actions, earnings forecast, research reports, news wires,
policy news, trading calendar, delisting / suspension info, macro indicators,
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 | HTTP | Dragon-tiger, lockup, holders, concept blocks, news, announcements |
| Sina Finance | HTTP | Realtime fallback, K-line fallback, daily fund flow, financial statements |
| 同花顺 10jqka | HTTP | Consensus EPS, hot stocks |
| 财联社 cls.cn | HTTP | Global news wire |
| SSE / SZSE official | HTTP | Northbound daily turnover (trusted), delisting list |
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.
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), with selected correctness fixes ported from a-stock-data (Apache-2.0). This package is not a superset of a-stock-data: it does not include ETF option greeks/IV, limit-up/down pools, or CYQ chip distribution. See MIGRATION.md.
License
Release files for chstockdata 0.1.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.1.0.tar.gz | 261.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chstockdata-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 461.4 kB
Release files / chstockdata-0.1.0.tar.gz
| Download URL | chstockdata-0.1.0.tar.gz |
|---|---|
| Size | 261.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c63a0e7e1fb1d81a7c9c034470d5f94424b7d65d276df38e49ae26daaa9d344
|
|
BLAKE2b-256 checksum How to use checksums |
be03a6d80923f6408aad02cccb92d8a4379dadd7abf9213abfe434a5e1f02a03
|
| 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.1.0-py3-none-any.whl
| Download URL | chstockdata-0.1.0-py3-none-any.whl |
|---|---|
| Size | 199.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da8b2aae0102f73c2d1e55989b2af1c015f923b146e64a776e19168d9639472c
|
|
BLAKE2b-256 checksum How to use checksums |
aa03702edb2a736491d773a404826787c21e86a1cfc588cba74b150d93967eda
|
| 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