Simple, Pythonic access to Chinese market data
Query A-shares, ETFs, indices, financial statements, capital flows, real-time
quotes, news, and reference data from Python. Every endpoint returns a familiar
pandas.DataFrame.
Website · Documentation · API Reference · Get an API Key · Report an Issue
AShareHub is the official open-source Python client for the hosted AShareHub market data API. It gives analysts, researchers, and developers one consistent interface for working with Chinese market data without maintaining their own collection and normalization pipeline.
- Why AShareHub
- Quick start
- Data coverage
- Common workflows
- Data conventions
- Client configuration
- Error handling
- Documentation and ecosystem
- Development
- Contributing
- DataFrame first — every public method returns a
pandas.DataFrame, and an empty result returns an empty DataFrame. - One code convention — stocks, indices, sectors, ETFs, and other
instruments use the public
symbolfield consistently. - Broad market coverage — use one client for prices, fundamentals, financial statements, flows, holdings, ETFs, real-time quotes, and news.
- Discoverable contracts — inspect request parameters and response fields locally through the packaged machine-readable public contract.
- Small, familiar API — install from PyPI, authenticate with one API key, and receive analysis-ready tabular results.
pip install asharehubAShareHub requires Python 3.10 or newer.
Create an account in the AShareHub console and generate an API key. Keep the key outside source control, for example in an environment variable:
export ASHAREHUB_API_KEY="ash_your_key_here"import os
from asharehub import AShareHub
with AShareHub(api_key=os.environ["ASHAREHUB_API_KEY"]) as client:
daily = client.market_daily(
symbol="000001.SZ",
start_date="20240101",
end_date="20241231",
)
print(daily[["trade_date", "open", "high", "low", "close", "vol"]].head())daily is a regular DataFrame, so it works directly with pandas, notebooks,
visualization libraries, and research pipelines.
| Area | Examples | Selected SDK methods |
|---|---|---|
| Market and valuation | Daily OHLC, valuation ratios, adjustment factors, technical factors, price limits | market_daily, fundamentals, adj_factor, technical_factors, limit_list |
| Capital flows and holdings | Stock Connect flows, individual-stock money flow, northbound and southbound holdings | moneyflow_hsgt, moneyflow, northbound_holdings, southbound_holdings |
| Financials and corporate data | Statements, indicators, forecasts, dividends, audits, main business | income, balance_sheet, cash_flow, financial_indicators, forecast, dividend |
| Indices and concepts | Index prices and weights, concept sectors and constituents | index_daily, index_weight, concepts, concept_members |
| ETFs | Directory, prices, adjustment factors, NAV, shares, portfolios, baskets | etf_basic, etf_daily, etf_nav, etf_portfolio, etf_sh_basket, etf_sz_basket |
| Market activity | Margin data, block trades, top lists, institutional seats, shareholder activity | margin, block_trade, top_list, top_inst, shareholders, holder_trade |
| Reference and alternative data | Security lists, industries, calendars, chip distribution, FX | stock_list, industry_list, trade_calendar, chip_distribution, fx_daily |
| Live and research feeds | Real-time quotes, flash news, analyst reports | realtime, news_flash, analyst_reports |
See the API documentation for endpoint-specific parameters, response schemas, and examples.
with AShareHub(api_key=os.environ["ASHAREHUB_API_KEY"]) as client:
etf = client.etf_daily(symbol="510300.SH", start_date="20240101")
index = client.index_daily(symbol="000300.SH", start_date="20240101")with AShareHub(api_key=os.environ["ASHAREHUB_API_KEY"]) as client:
income = client.income(symbol="600519.SH", period="20241231")
balance_sheet = client.balance_sheet(symbol="600519.SH", period="20241231")
cash_flow = client.cash_flow(symbol="600519.SH", period="20241231")with AShareHub(api_key=os.environ["ASHAREHUB_API_KEY"]) as client:
sectors = client.concepts(name="AI")
members = client.concept_members(
symbol="BK0425.DC",
con_symbol="000001.SZ",
)with AShareHub(api_key=os.environ["ASHAREHUB_API_KEY"]) as client:
quotes = client.realtime(symbol="000001.SZ,600519.SH,510300.SH")Public instrument fields use one stable naming contract:
- Use
symbolfor the primary stock, index, Eastmoney sector, ETF, or other instrument code. - Use
con_symbolwhen a request or record contains a second constituent security. - Use suffixed codes such as
000001.SZ,600519.SH,000300.SH,510300.SH, orBK0425.DC.
This convention is shared by the REST API, Python SDK, MCP server, public documentation, and packaged contract.
- Dates use
YYYYMMDD, for example20240819. - The default
v2client returns public fields such assymboland native JSON numbers. - Every method returns a DataFrame; no rows means
df.empty == True. - Method signatures vary intentionally. Use the contract or endpoint docs for the exact filters supported by each method.
The package includes the authoritative SDK/MCP method signatures, request parameters, and response fields:
from asharehub import PUBLIC_CONTRACT, get_contract
daily_contract = get_contract("market_daily")
print(daily_contract["request_parameters"])
print(daily_contract["response_fields"])
print(PUBLIC_CONTRACT["version"])Use the client as a context manager when possible so the underlying HTTP connection is closed automatically:
with AShareHub(
api_key=os.environ["ASHAREHUB_API_KEY"],
timeout=60.0,
) as client:
data = client.market_daily(symbol="000001.SZ")For development or a compatible deployment, provide a custom base URL:
client = AShareHub(
api_key=os.environ["ASHAREHUB_API_KEY"],
base_url="https://your-api.example.com",
)The client targets API v2 by default. Existing integrations can explicitly
select the legacy response surface with version="v1"; public SDK method
parameters continue to use symbol.
HTTP errors are raised as httpx.HTTPStatusError, so standard httpx handling
works without an SDK-specific exception hierarchy:
import httpx
try:
data = client.market_daily(symbol="000001.SZ")
except httpx.HTTPStatusError as exc:
if exc.response.status_code == 401:
print("Check your API key")
elif exc.response.status_code == 429:
print("Rate limit reached")
else:
raiseRequests authenticate through the X-API-Key header, which the SDK configures
from the api_key argument. A free tier is available; current quotas and paid
plans are maintained on the pricing page.
Never commit API keys to a repository, notebook, image, or issue report.
| Resource | Use it for |
|---|---|
| Python SDK guide | Installation and the first authenticated request |
| REST API documentation | Endpoint reference, schemas, authentication, and limits |
| A-share market data | Prices, volume, adjustment factors, and trading data |
| ETF data | ETF reference data, prices, NAV, shares, portfolios, and baskets |
| Financial data | Statements, indicators, forecasts, and dividends |
| MCP server | Connecting MCP-compatible clients and AI agents |
| Agent Skill | Guided AShareHub workflows for coding agents |
Clone the repository and install the package in editable mode:
git clone https://github.com/ChuYiCui1/AshareHub.git
cd AShareHub
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
pytest -qTests that require a live API are skipped unless both environment variables are set. When an API server is available, run the integration suite with:
ASHAREHUB_API_KEY="ash_your_key_here" \
ASHAREHUB_BASE_URL="http://localhost:8000" \
pytest -vIssues and pull requests are welcome. Before opening a change:
- Search existing issues for related work.
- Keep the public
symbol/con_symbolcompatibility contract intact. - Add or update tests for behavior changes.
- Run
pytest -qand describe the user-visible impact in the pull request.
For questions, bug reports, or endpoint requests, open a GitHub issue.
- Install releases from PyPI.
- Review version history on GitHub Releases.
- Read the documentation.
- Contact
support@asharehub.comfor account or service support.
The SDK is available under the MIT License.
AShareHub provides data access tooling, not investment advice. Verify data, licensing requirements, and applicable terms before using it in research, production systems, or trading decisions.
Built for the global investment community