| name | akshare |
| description | Comprehensive free financial data API library — supports A-shares, Hong Kong stocks, US stocks, futures, options, funds, bonds, forex, and macro data, no API key required. |
| homepage | https://github.com/akfamily/akshare |
AKShare (Open-Source Financial Data API Library)
AKShare is a comprehensive, free Python financial data API library covering A-shares, Hong Kong stocks, US stocks, futures, options, funds, bonds, forex, and macroeconomic data. No registration or API key is required, and all functions return pandas.DataFrame.
Documentation: https://akshare.akfamily.xyz/
Installation
pip install akshare --upgrade
Requires Python 3.9+ (64-bit).
Basic Usage
import akshare as ak
df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20240101", end_date="20240630")
print(df)
Function Naming Convention
{asset_type}_{market}_{data_type}_{data_source}
- Asset type:
stock (stocks), futures (futures), fund (funds), bond (bonds), forex (foreign exchange), option (options), macro (macroeconomics), index (indices)
- Market:
zh (China), us (United States), hk (Hong Kong), or exchange codes
- Data type:
spot (real-time), hist (historical), daily (daily bars), minute (minute bars)
- Data source:
em (East Money), sina (Sina Finance), exchange abbreviations
Stock Data (A-Shares)
Real-Time Quotes — All A-Shares
import akshare as ak
df = ak.stock_zh_a_spot_em()
Historical Candlestick Data
df = ak.stock_zh_a_hist(
symbol="000001",
period="daily",
start_date="20240101",
end_date="20240630",
adjust=""
)
Minute-Level Candlestick Data
df = ak.stock_zh_a_hist_min_em(
symbol="000001",
period="5",
start_date="2024-01-02 09:30:00",
end_date="2024-01-02 15:00:00",
adjust=""
)
Individual Stock Basic Info
df = ak.stock_individual_info_em(symbol="000001")
Hong Kong Stock Data
df = ak.stock_hk_spot_em()
df = ak.stock_hk_hist(
symbol="00700",
period="daily",
start_date="20240101",
end_date="20240630",
adjust="qfq"
)
US Stock Data
df = ak.stock_us_daily(symbol="AAPL", adjust="qfq")
df = ak.stock_us_spot_em()
Index Data
df = ak.stock_zh_index_daily_em(symbol="sh000001")
df = ak.index_stock_cons_csindex(symbol="000300")
Fund Data
df = ak.fund_etf_spot_em()
df = ak.fund_etf_hist_em(
symbol="510300",
period="daily",
start_date="20240101",
end_date="20240630",
adjust="qfq"
)
df = ak.fund_open_fund_daily_em(symbol="000001")
df = ak.fund_rating_all()
Futures Data
from akshare import get_futures_daily
df = get_futures_daily(start_date="20240101", end_date="20240102", market="CFFEX")
df = ak.futures_zh_spot()
df = ak.futures_inventory_99(symbol="豆一")
Options Data
df = ak.option_hist_dce(symbol="豆粕期权")
df = ak.option_sse_spot_price(symbol="510050")
Bond Data
df = ak.bond_zh_cov()
df = ak.bond_zh_hs_cov_daily(symbol="sz123456")
df = ak.bond_spot_quote()
Forex Data
df = ak.forex_spot_em()
df = ak.fx_spot_quote()
df = ak.fx_swap_quote()
Macroeconomic Data
df = ak.macro_china_cpi_yearly()
df = ak.macro_china_gdp_yearly()
df = ak.macro_china_pmi()
df = ak.macro_usa_non_farm()
df = ak.macro_usa_cpi_monthly()
News and Sentiment
df = ak.stock_news_em(symbol="000001")
df = ak.news_cctv(date="20240101")
Complete Example: Download Data and Plot a Candlestick Chart
import akshare as ak
import pandas as pd
import mplfinance as mpf
df = ak.stock_zh_a_hist(
symbol="600519",
period="daily",
start_date="20240101",
end_date="20240630",
adjust="qfq"
)
df.index = pd.to_datetime(df["日期"])
df.rename(columns={
"开盘": "Open",
"收盘": "Close",
"最高": "High",
"最低": "Low",
"成交量": "Volume"
}, inplace=True)
mpf.plot(df, type="candle", mav=(5, 10, 20), volume=True)
Usage Tips
- No API key or registration required — works out of the box.
- All functions return pandas DataFrame — ready for analysis, export, and visualization.
- A-share data columns are in Chinese; US/HK stock data columns are in English.
- Use
--upgrade to keep akshare up to date — interfaces update frequently due to upstream data source changes.
- Non-Python users can use the AKTools HTTP API wrapper.
- Data is for academic research only — not investment advice.
- Full API reference: https://akshare.akfamily.xyz/data/index.html
Advanced Examples
Batch Download Multiple Stocks
import akshare as ak
import pandas as pd
stock_list = ["000001", "600519", "300750", "601318", "000858"]
all_data = {}
for symbol in stock_list:
df = ak.stock_zh_a_hist(
symbol=symbol,
period="daily",
start_date="20240101",
end_date="20240630",
adjust="qfq"
)
df["股票代码"] = symbol
all_data[symbol] = df
print(f"Downloaded {symbol}, {len(df)} records")
combined = pd.concat(all_data.values(), ignore_index=True)
combined.to_csv("multi_stock_data.csv", index=False)
print(f"Combined total: {len(combined)} records")
Calculate Technical Indicators (Moving Averages, MACD, RSI)
import akshare as ak
import pandas as pd
import numpy as np
df = ak.stock_zh_a_hist(symbol="600519", period="daily",
start_date="20240101", end_date="20241231", adjust="qfq")
df["收盘"] = df["收盘"].astype(float)
df["MA5"] = df["收盘"].rolling(window=5).mean()
df["MA10"] = df["收盘"].rolling(window=10).mean()
df["MA20"] = df["收盘"].rolling(window=20).mean()
df["MA60"] = df["收盘"].rolling(window=60).mean()
ema12 = df["收盘"].ewm(span=12, adjust=False).mean()
ema26 = df["收盘"].ewm(span=26, adjust=False).mean()
df["DIF"] = ema12 - ema26
df["DEA"] = df["DIF"].ewm(span=, adjust=).mean()
df[] = * (df[] - df[])
delta = df[].diff()
gain = delta.where(delta > , )
loss = -delta.where(delta < , )
avg_gain = gain.rolling(window=).mean()
avg_loss = loss.rolling(window=).mean()
rs = avg_gain / avg_loss
df[] = - ( / ( + rs))
df[] = df[].rolling(window=).mean()
df[] = df[] + * df[].rolling(window=).std()
df[] = df[] - * df[].rolling(window=).std()
(df[[, , , , , , , ]].tail())
Filter Limit-Up Stocks
import akshare as ak
df = ak.stock_zh_a_spot_em()
df["涨跌幅"] = df["涨跌幅"].astype(float)
limit_up = df[df["涨跌幅"] >= 9.5].sort_values("涨跌幅", ascending=False)
print(f"Today's limit-up / near limit-up stocks: {len(limit_up)} total")
print(limit_up[["代码", "名称", "最新价", "涨跌幅", "成交额", "换手率"]].head(20))
Get Dragon-Tiger List Data
import akshare as ak
df = ak.stock_lhb_detail_em(start_date="20240101", end_date="20240131")
print(df.head())
df_dept = ak.stock_lhb_hyyyb_em(start_date="20240101", end_date="20240131")
print(df_dept.head())
Get Margin Trading Data
import akshare as ak
df = ak.stock_margin_sse(start_date="20240101", end_date="20240630")
print(df.head())
df_detail = ak.stock_margin_detail_sse(date="20240102")
print(df_detail.head())
Get Northbound Capital (Stock Connect) Data
import akshare as ak
df = ak.stock_hsgt_hist_em(symbol="北向资金")
print(df.tail(10))
df_hold = ak.stock_hsgt_hold_stock_em(market="北向", indicator="今日排行")
print(df_hold.head(20))
Get Shareholder Data
import akshare as ak
df = ak.stock_gdfx_top_10_em(symbol="600519", date="20231231")
print(df)
df_float = ak.stock_gdfx_free_top_10_em(symbol="600519", date="20231231")
print(df_float)
Get Sector Quotes Data
import akshare as ak
df_industry = ak.stock_board_industry_name_em()
print(df_industry.head(20))
df_concept = ak.stock_board_concept_name_em()
print(df_concept.head(20))
df_stocks = ak.stock_board_industry_cons_em(symbol="银行")
print(df_stocks)
Get Lock-Up Share Release Data
import akshare as ak
df = ak.stock_restricted_release_queue_em(symbol="全部A股")
print(df.head(20))
Get Market Capital Flow
import akshare as ak
df = ak.stock_market_fund_flow()
print(df.tail(10))
df_stock = ak.stock_individual_fund_flow(stock="000001", market="sz")
print(df_stock.tail(10))
Complete Example: Multi-Factor Stock Screening
import akshare as ak
import pandas as pd
df = ak.stock_zh_a_spot_em()
for col in ["市盈率-动态", "市净率", "换手率", "涨跌幅", "成交额"]:
df[col] = pd.to_numeric(df[col], errors="coerce")
filtered = df[
(df["市盈率-动态"] > 5) & (df["市盈率-动态"] < 30) &
(df["市净率"] > 0.5) & (df["市净率"] < 5) &
(df["换手率"] > 1) &
(df["涨跌幅"] > -3) & (df["涨跌幅"] < 3)
].copy()
result = filtered.sort_values("市盈率-动态").head(20)
print(f"Selected {len(result)} stocks:")
print(result[["代码", "名称", "最新价", "市盈率-动态", "市净率", "换手率", "涨跌幅"]])
社区与支持
由 大佬量化 (Boss Quant) 维护 — 量化交易教学与策略研发团队。
微信客服: bossquant1 · Bilibili · 搜索 大佬量化 on 微信公众号 / Bilibili / 抖音