| name | akshare |
| description | Fetch Chinese stock market data (A-shares, Hong Kong stocks, futures, funds, macroeconomic indicators) using AKShare library. Use when you need to get real-time or historical financial data from Chinese markets, including stock prices, trading volumes, financial statements, fund data, futures data, or macroeconomic statistics. Supports daily/weekly/monthly K-line data, stock fundamentals, market indices, and more. No API key required - completely free. |
AKShare - Chinese Financial Data
AKShare is a free, open-source Python library for accessing Chinese financial market data.
Quick Start
import akshare as ak
stock_spot = ak.stock_zh_a_spot_em()
df = ak.stock_zh_a_hist(symbol="000001", period="daily",
start_date="20200101", end_date="20231231",
adjust="qfq")
Core Functions
Stock Data
Real-time quotes:
ak.stock_zh_a_spot_em()
ak.stock_individual_info_em(symbol="000001")
Historical data:
ak.stock_zh_a_hist(
symbol="000001",
period="daily",
start_date="20200101",
end_date="20231231",
adjust="qfq"
)
Index data:
ak.stock_zh_index_daily(symbol="sh000001")
ak.stock_zh_index_daily(symbol="sz399001")
Fund Data
ak.fund_open_fund_rank_em(symbol="全部")
ak.fund_open_fund_info_em(fund="000001", indicator="单位净值走势")
ak.fund_etf_spot_em()
Futures Data
ak.futures_zh_spot(symbol="主力合约")
ak.futures_zh_daily_sina(symbol="CU0", start_date="20230101", end_date="20231231")
Macroeconomic Data
ak.macro_china_gdp()
ak.macro_china_cpi()
ak.macro_china_pmi()
ak.macro_china_money_supply()
Important Notes
Rate Limiting
- AKShare scrapes public websites - add delays between requests
- Recommended:
time.sleep(1) between calls
- Batch downloads may trigger rate limits
Data Quality
- Free data may have occasional gaps or errors
- For production use, consider Tushare Pro (paid)
- Always validate critical data
Stock Code Format
- Use 6-digit code without exchange prefix:
"000001" not "sz000001"
- Index codes need prefix:
"sh000001", "sz399001"
Common Patterns
Get multiple stocks:
import time
stocks = ["000001", "600519", "000858"]
data = {}
for code in stocks:
data[code] = ak.stock_zh_a_hist(symbol=code, period="daily", adjust="qfq")
time.sleep(1)
Calculate returns:
df = ak.stock_zh_a_hist(symbol="000001", period="daily", adjust="qfq")
df['日收益率'] = df['收盘'].pct_change() * 100
total_return = ((df['收盘'].iloc[-1] / df['收盘'].iloc[0]) - 1) * 100
Resources
When to Use
Use AKShare when:
- Getting Chinese market data (A-shares, Hong Kong, futures)
- No budget for paid data services
- Prototyping or learning quantitative strategies
- Need macroeconomic indicators
Consider alternatives when:
- Need guaranteed data stability (use Tushare Pro)
- High-frequency trading (use professional data feeds)
- Need real-time tick data (use broker APIs)