Implementation:HKUDS AI Trader Get Daily Price A Stock
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, Financial_Data, Chinese_Markets |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
Concrete tool for fetching Chinese A-share daily stock and index data from the Tushare Pro API provided by the AI-Trader data pipeline.
Description
The get_daily_price_a_stock function resolves SSE-50 index constituents via Tushare, fetches daily OHLCV data for each constituent stock, converts data to the Alpha Vantage-compatible JSON schema, and saves individual JSON files. It also fetches index-level daily data for benchmark comparison. Includes batch processing, retry logic with exponential backoff, and fallback to CSV if API fails.
Usage
Import and call this function when populating the local A-share data directory prior to running the A-share JSONL merge step. Requires a valid Tushare Pro token set via the TUSHARE_TOKEN environment variable.
Code Reference
Source Location
- Repository: AI-Trader
- File: data/A_stock/get_daily_price_tushare.py
- Lines: L109-139
Signature
def get_daily_price_a_stock(
index_code: str = "000016.SH",
output_dir: Optional[Path] = None,
daily_start_date: str = "20250101",
fallback_csv: Optional[Path] = None,
) -> Optional[pd.DataFrame]:
"""
Fetches SSE-50 constituent daily data from Tushare.
Args:
index_code: Index code for constituent resolution (default SSE-50)
output_dir: Directory for output JSON files
daily_start_date: Start date in YYYYMMDD format
fallback_csv: Path to CSV fallback if API fails
Returns:
DataFrame of index daily data, or None on failure
"""
Import
from data.A_stock.get_daily_price_tushare import get_daily_price_a_stock
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| index_code | str | No | Index code for constituent lookup (default "000016.SH" = SSE-50) |
| output_dir | Optional[Path] | No | Output directory (default: data/A_stock/A_stock_data/) |
| daily_start_date | str | No | Start date YYYYMMDD (default "20250101") |
| fallback_csv | Optional[Path] | No | CSV fallback path if Tushare API fails |
| TUSHARE_TOKEN | str (env) | Yes | Tushare Pro API token from environment |
Outputs
| Name | Type | Description |
|---|---|---|
| daily_prices_{CODE}.json | File | One JSON file per SSE-50 constituent with OHLCV data |
| index_daily_sse_50.json | File | SSE-50 index-level daily data for benchmarking |
| return value | Optional[pd.DataFrame] | DataFrame of index daily data or None |
Usage Examples
Fetch SSE-50 Data
from data.A_stock.get_daily_price_tushare import get_daily_price_a_stock
# Fetch all SSE-50 constituents from Jan 2025
index_df = get_daily_price_a_stock(
index_code="000016.SH",
daily_start_date="20250101"
)
# Creates: data/A_stock/A_stock_data/daily_prices_600519.SHH.json, etc.