← 返回 Skills 市场
coderwpf

AKShare

作者 coderwpf · GitHub ↗ · v1.0.3 · MIT-0
cross-platform ✓ 安全检测通过
1430
总下载
7
收藏
9
当前安装
4
版本数
在 OpenClaw 中安装
/install aakshare
功能描述
AKShare 开源金融数据接口库 - 支持A股、港股、美股、期货、期权、基金、债券、外汇、宏观数据,免费无需API Key。
使用说明 (SKILL.md)

AKShare(开源金融数据API库)

AKShare 是一个全面的免费Python金融数据API库,覆盖A股、港股、美股、期货、期权、基金、债券、外汇和宏观经济数据。无需注册或API Key,所有函数返回 pandas.DataFrame

文档:https://akshare.akfamily.xyz/

安装

pip install akshare --upgrade

需要 Python 3.9+(64位)。

基本用法

import akshare as ak

# 获取平安银行日K线数据
df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20240101", end_date="20240630")
print(df)

函数命名规则

{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

股票数据(A股)

实时行情 — 全部A股

import akshare as ak

# 获取全部A股实时行情
df = ak.stock_zh_a_spot_em()
# 返回字段: 序号、代码、名称、最新价、涨跌幅、涨跌额、成交量、成交额、振幅、最高、最低、今开、昨收、量比、换手率、市盈率、市净率 ...

历史K线数据

# 获取指定股票历史日K线数据
df = ak.stock_zh_a_hist(
    symbol="000001",       # 股票代码(不带前缀)
    period="daily",        # 周期: "daily"(日), "weekly"(周), "monthly"(月)
    start_date="20240101", # 开始日期,格式YYYYMMDD
    end_date="20240630",   # 结束日期
    adjust=""              # 复权: ""(不复权), "qfq"(前复权), "hfq"(后复权)
)
# 返回字段: 日期、开盘、收盘、最高、最低、成交量、成交额、振幅、涨跌幅、涨跌额、换手率

分钟级K线数据

# 获取分钟级K线数据
df = ak.stock_zh_a_hist_min_em(
    symbol="000001",
    period="5",            # 分钟间隔: "1", "5", "15", "30", "60"
    start_date="2024-01-02 09:30:00",
    end_date="2024-01-02 15:00:00",
    adjust=""              # 复权类型
)

个股基本信息

# 获取个股基本信息
df = ak.stock_individual_info_em(symbol="000001")
# 返回字段: 总市值、流通市值、行业、上市时间、股票代码、股票简称、总股本、流通股 ...

港股数据

# 港股实时行情
df = ak.stock_hk_spot_em()

# 港股历史K线数据
df = ak.stock_hk_hist(
    symbol="00700",        # 腾讯控股
    period="daily",        # 日线
    start_date="20240101",
    end_date="20240630",
    adjust="qfq"           # 前复权
)

美股数据

# 美股日线数据
df = ak.stock_us_daily(symbol="AAPL", adjust="qfq")

# 美股实时行情
df = ak.stock_us_spot_em()

指数数据

# A股指数历史数据 (e.g., Shanghai Composite Index 000001)
df = ak.stock_zh_index_daily_em(symbol="sh000001")

# 指数成分股 (e.g., CSI 300)
df = ak.index_stock_cons_csindex(symbol="000300")

基金数据

# ETF实时行情
df = ak.fund_etf_spot_em()

# ETF历史K线数据
df = ak.fund_etf_hist_em(
    symbol="510300",       # 沪深300ETF
    period="daily",
    start_date="20240101",
    end_date="20240630",
    adjust="qfq"
)

# 开放式基金每日净值
df = ak.fund_open_fund_daily_em(symbol="000001")

# 基金评级
df = ak.fund_rating_all()

期货数据

# 期货日线数据(按交易所汇总)
from akshare import get_futures_daily
df = get_futures_daily(start_date="20240101", end_date="20240102", market="CFFEX")
# 交易所选项: "CFFEX"(中金所), "SHFE"(上期所), "DCE"(大商所), "CZCE"(郑商所), "INE"(上海国际能源交易中心), "GFEX"(广期所)

# 期货实时行情
df = ak.futures_zh_spot()

# 期货库存数据
df = ak.futures_inventory_99(symbol="豆一")

期权数据

# 交易所期权历史数据
df = ak.option_hist_dce(symbol="豆粕期权")

# 上证50ETF期权
df = ak.option_sse_spot_price(symbol="510050")

债券数据

# 可转债列表
df = ak.bond_zh_cov()

# 可转债历史K线数据
df = ak.bond_zh_hs_cov_daily(symbol="sz123456")

# 中国债券现货报价
df = ak.bond_spot_quote()

外汇数据

# 外汇实时行情(东方财富)
df = ak.forex_spot_em()

# 外汇即期报价(中国外汇交易中心)
df = ak.fx_spot_quote()

# 外汇掉期报价
df = ak.fx_swap_quote()

宏观经济数据

# 中国CPI年度数据
df = ak.macro_china_cpi_yearly()

# 中国GDP年度数据
df = ak.macro_china_gdp_yearly()

# 中国PMI数据
df = ak.macro_china_pmi()

# 美国非农就业数据
df = ak.macro_usa_non_farm()

# 美国CPI月度数据
df = ak.macro_usa_cpi_monthly()

新闻与舆情

# 个股财经新闻(东方财富)
df = ak.stock_news_em(symbol="000001")

# 央视新闻
df = ak.news_cctv(date="20240101")

完整示例:下载数据并绘制K线图

import akshare as ak
import pandas as pd
import mplfinance as mpf  # pip install mplfinance

# 获取贵州茅台前复权日K线数据
df = ak.stock_zh_a_hist(
    symbol="600519",
    period="daily",
    start_date="20240101",
    end_date="20240630",
    adjust="qfq"
)

# 设置日期索引并重命名列为英文(mplfinance要求)
df.index = pd.to_datetime(df["日期"])  # 设置日期为索引
df.rename(columns={
    "开盘": "Open",    # 开盘价
    "收盘": "Close",   # 收盘价
    "最高": "High",    # 最高价
    "最低": "Low",     # 最低价
    "成交量": "Volume" # 成交量
}, inplace=True)

# 绘制K线图(含5/10/20日均线和成交量)
mpf.plot(df, type="candle", mav=(5, 10, 20), volume=True)

使用技巧

  • 无需API Key或注册 — 开箱即用。
  • 所有函数返回 pandas DataFrame — 可直接用于分析、导出和可视化。
  • A股数据列名为中文;美股/港股数据列名为英文。
  • 使用 --upgrade 保持akshare最新版 — 由于上游数据源变化,接口更新频繁。
  • 非Python用户可使用 AKTools HTTP API封装。
  • 数据仅供学术研究使用 — 不构成投资建议。
  • 完整API参考:https://akshare.akfamily.xyz/data/index.html

进阶示例

批量下载多只股票

import akshare as ak
import pandas as pd

# 定义要下载的股票列表
stock_list = ["000001", "600519", "300750", "601318", "000858"]

all_data = {}
for symbol in stock_list:
    # 下载每只股票的前复权日K线数据
    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"已下载 {symbol},共 {len(df)} 条记录")

# 合并所有股票数据为一个大的DataFrame
combined = pd.concat(all_data.values(), ignore_index=True)
combined.to_csv("multi_stock_data.csv", index=False)
print(f"合并总计: {len(combined)} 条记录")

计算技术指标(均线、MACD、RSI)

import akshare as ak
import pandas as pd
import numpy as np

# 获取贵州茅台前复权日K线数据
df = ak.stock_zh_a_hist(symbol="600519", period="daily",
                         start_date="20240101", end_date="20241231", adjust="qfq")

# 将收盘价转换为浮点数 (收盘 = close price)
df["收盘"] = df["收盘"].astype(float)

# 计算均线
df["MA5"] = df["收盘"].rolling(window=5).mean()    # 5日均线
df["MA10"] = df["收盘"].rolling(window=10).mean()   # 10日均线
df["MA20"] = df["收盘"].rolling(window=20).mean()   # 20日均线
df["MA60"] = df["收盘"].rolling(window=60).mean()   # 60日均线

# 计算MACD指标
ema12 = df["收盘"].ewm(span=12, adjust=False).mean()  # 12日指数移动平均
ema26 = df["收盘"].ewm(span=26, adjust=False).mean()  # 26日指数移动平均
df["DIF"] = ema12 - ema26                              # 快线(DIF)
df["DEA"] = df["DIF"].ewm(span=9, adjust=False).mean() # 慢线(DEA)
df["MACD"] = 2 * (df["DIF"] - df["DEA"])               # MACD柱

# 计算RSI指标(14日)
delta = df["收盘"].diff()
gain = delta.where(delta > 0, 0)       # 上涨幅度
loss = -delta.where(delta \x3C 0, 0)      # 下跌幅度
avg_gain = gain.rolling(window=14).mean()
avg_loss = loss.rolling(window=14).mean()
rs = avg_gain / avg_loss
df["RSI14"] = 100 - (100 / (1 + rs))   # RSI值

# 计算布林带(20日)
df["BOLL_MID"] = df["收盘"].rolling(window=20).mean()           # 中轨
df["BOLL_UP"] = df["BOLL_MID"] + 2 * df["收盘"].rolling(window=20).std()  # 上轨
df["BOLL_DN"] = df["BOLL_MID"] - 2 * df["收盘"].rolling(window=20).std()  # 下轨

# 展示:日期、收盘价及各技术指标
print(df[["日期", "收盘", "MA5", "MA20", "DIF", "DEA", "MACD", "RSI14"]].tail(10))

筛选涨停股

import akshare as ak

# 获取全部A股实时行情
df = ak.stock_zh_a_spot_em()

# 筛选涨幅>9.5%的股票(接近涨停)
df["涨跌幅"] = df["涨跌幅"].astype(float)  # 涨跌幅 = change percentage
limit_up = df[df["涨跌幅"] >= 9.5].sort_values("涨跌幅", ascending=False)
print(f"今日涨停/接近涨停股票: 共 {len(limit_up)} 只")
# 展示:代码、名称、最新价、涨跌幅、成交额、换手率
print(limit_up[["代码", "名称", "最新价", "涨跌幅", "成交额", "换手率"]].head(20))

获取龙虎榜数据

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())

获取融资融券数据

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())

获取北向资金(陆港通)数据

import akshare as ak

# 获取北向资金历史数据
df = ak.stock_hsgt_hist_em(symbol="北向资金")  # 北向资金 = Northbound capital
print(df.tail(10))

# 获取北向资金持股明细
df_hold = ak.stock_hsgt_hold_stock_em(market="北向", indicator="今日排行")  # 北向 = Northbound, 今日排行 = Today's ranking
print(df_hold.head(20))

获取股东数据

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)

获取板块行情数据

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="银行")  # 银行 = Banking
print(df_stocks)

获取限售解禁数据

import akshare as ak

# 获取限售解禁数据
df = ak.stock_restricted_release_queue_em(symbol="全部A股")  # 全部A股 = All A-shares
print(df.head(20))

获取市场资金流向

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))

完整示例:多因子选股

import akshare as ak
import pandas as pd

# 步骤1:获取全部A股实时行情
df = ak.stock_zh_a_spot_em()

# 步骤2:转换数据类型
for col in ["市盈率-动态", "市净率", "换手率", "涨跌幅", "成交额"]:
    df[col] = pd.to_numeric(df[col], errors="coerce")

# 步骤3:多因子筛选
# 条件1:PE 在5-30之间(排除亏损和高估值)
# 条件2:PB 在0.5-5之间
# 条件3:换手率 > 1%(合理流动性)
# 条件4:涨跌幅在-3%到3%之间(排除异常波动)
filtered = df[
    (df["市盈率-动态"] > 5) & (df["市盈率-动态"] \x3C 30) &
    (df["市净率"] > 0.5) & (df["市净率"] \x3C 5) &
    (df["换手率"] > 1) &
    (df["涨跌幅"] > -3) & (df["涨跌幅"] \x3C 3)
].copy()

# 步骤4:按PE排序,选取最低PE的前20只股票
result = filtered.sort_values("市盈率-动态").head(20)
print(f"筛选出 {len(result)} 只股票:")
print(result[["代码", "名称", "最新价", "市盈率-动态", "市净率", "换手率", "涨跌幅"]])

🤖 AI Agent 高阶使用指南

对于 AI Agent,在使用 AKShare 时应遵循以下高阶策略和最佳实践,以确保数据的准确性和任务的高效完成:

1. 数据校验与错误处理

在获取数据后,AI 应当主动检查数据格式是否符合预期,以及是否存在缺失值(NaN)。

import akshare as ak
import pandas as pd

def safe_get_stock_data(symbol="600519"):
    try:
        df = ak.stock_zh_a_hist(symbol=symbol, period="daily", start_date="20230101", adjust="qfq")
        if df.empty:
            return "获取的数据为空,请检查股票代码或日期范围。"
        # 填充或丢弃缺失值
        df = df.dropna()
        return df.head()
    except Exception as e:
        return f"获取数据时发生错误: {str(e)}"

print(safe_get_stock_data())

2. 跨市场数据聚合分析

AI 经常需要进行宏观经济分析或跨市场对比。以下演示如何组合多接口数据进行分析:

import akshare as ak
import pandas as pd

# 1. 获取 A股 指数数据(上证指数)
df_sh = ak.stock_zh_index_daily_em(symbol="sh000001")
df_sh = df_sh[['date', 'close']].rename(columns={'close': 'SH_Close', 'date': 'Date'})

# 2. 获取 美股 指数数据(标普500)
df_spx = ak.index_us_stock_sina(symbol=".INX")
df_spx = df_spx[['date', 'close']].rename(columns={'close': 'SPX_Close', 'date': 'Date'})

# 3. 合并数据进行趋势对比
df_merged = pd.merge(df_sh, df_spx, on='Date', how='inner')
print("中美股市指数对比:")
print(df_merged.tail())

3. 构建动态监控指标

AI 可以定期调用以下代码来获取实时的异动信息(如涨跌停板),从而做出及时的策略响应:

import akshare as ak

# 获取当日涨停板数据
df_limit_up = ak.stock_zt_pool_em(date="20231010")  # 可替换为当日日期,如 "20240101"
if not df_limit_up.empty:
    print(f"发现 {len(df_limit_up)} 只涨停股票!")
    # 筛选连板数大于等于3的强势股
    strong_stocks = df_limit_up[df_limit_up['连板数'] >= 3]
    print("强势连板股:")
    print(strong_stocks[['代码', '名称', '最新价', '连板数']])
else:
    print("未获取到涨停板数据,可能是非交易日。")

社区与支持

大佬量化 维护 — 量化交易教学与策略研发团队。

微信客服: bossquant1 · Bilibili · 搜索 大佬量化 — 微信公众号 / Bilibili / 抖音

安全使用建议
This skill appears to be an instruction-only wrapper around the public AKShare Python library and is coherent with its stated purpose. Before installing: (1) verify which akshare version you'll install and prefer pinning the version (e.g., akshare==1.x.y) instead of --upgrade; (2) inspect the PyPI package and the upstream GitHub repo (confirm maintainers, release artifacts, and recent activity); (3) consider installing and running it in an isolated environment (virtualenv/container) because pip install executes package code during installation; (4) be aware akshare fetches data from many third-party websites (network activity) and may be affected by upstream scraping behavior; and (5) note the package metadata shows inconsistent version/owner fields — it's likely packaging sloppiness but you may want to confirm the canonical source before trusting it.
功能分析
Type: OpenClaw Skill Name: aakshare Version: 1.0.3 The skill bundle provides a comprehensive interface for the AKShare financial data library. It includes standard installation instructions, API references, and well-documented Python examples for fetching stock, fund, and macro data. No malicious code, data exfiltration, or harmful prompt injection attempts were found across the SKILL.md, README.md, or demo scripts.
能力评估
Purpose & Capability
The name, description, examples, and included files all describe using the AKShare Python library to fetch financial market data. Required binaries (python3) and the provided examples align with that purpose. Minor metadata inconsistencies exist: multiple version strings appear (1.0.3 in registry metadata vs SKILL.md 1.2.0 vs metadata/_meta 1.3.0) and ownerId differs between registry and _meta.json; repository field is empty. These suggest sloppy packaging but do not contradict the stated purpose.
Instruction Scope
SKILL.md only instructs how to install and use the akshare library and shows code examples that import akshare and call its data functions. The instructions do not ask the agent to read unrelated local files, collect extraneous environment variables, or transmit data to unknown endpoints beyond what akshare itself does (web requests to upstream data sources).
Install Mechanism
There is no automated install spec; SKILL.md tells users to run `pip install akshare --upgrade`. That is standard for Python packages, but pip installs run arbitrary package code at install time (setup/installation scripts), and will fetch packages from PyPI or configured indices. Recommend verifying the exact package version, repository/source, and PyPI package integrity (checksums/signature) before installing.
Credentials
The skill declares no required environment variables, no secrets, and no config paths. That is appropriate for a data-fetching library that uses public web sources and does not require API keys.
Persistence & Privilege
The skill does not request always:true and does not modify other skills or system-wide settings. It is user-invocable and allows normal autonomous invocation (platform default), which is expected for a functional skill.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install aakshare
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /aakshare 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.3
- Added a demo directory with sample code and documentation (demo_project/README.md, demo_project/demo.py). - Updated documentation files (README.md, SKILL.md) with minor improvements. - Metadata files were updated (metadata.json, _meta.json).
v1.0.2
- Documentation and code examples updated from Chinese/English mix to full Simplified Chinese. - Skill description and usage instructions are now in Chinese for improved localization. - No code/API change (documentation and language localization only). - Version incremented to 1.2.0.
v1.0.1
**Expanded documentation and quick reference added.** - Added QUICK_REFERENCE.md and improved README with usage tips and advanced examples. - Expanded SKILL.md examples, clarified parameter and return value descriptions in code snippets. - Improved documentation on naming conventions, usage patterns, and plotting. - No breaking changes to API or functionality—updates focus on user guidance and clarity.
v1.0.0
Initial release with major documentation update and streamlining: - Removed reference API documentation and all sample scripts from the skill package. - Rewrote SKILL.md to provide a concise, up-to-date usage guide with organized code examples. - SKILL.md now includes comprehensive function patterns, sample API calls, and covers asset classes (stocks, funds, futures, options, bonds, forex, macro, news). - Simplified installation and usage instructions. - All old script references and code pointers to individual scripts (like get_market_overview.py, get_stock_history.py) have been removed.
元数据
Slug aakshare
版本 1.0.3
许可证 MIT-0
累计安装 9
当前安装数 9
历史版本数 4
常见问题

AKShare 是什么?

AKShare 开源金融数据接口库 - 支持A股、港股、美股、期货、期权、基金、债券、外汇、宏观数据,免费无需API Key。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1430 次。

如何安装 AKShare?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install aakshare」即可一键安装,无需额外配置。

AKShare 是免费的吗?

是的,AKShare 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

AKShare 支持哪些平台?

AKShare 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 AKShare?

由 coderwpf(@coderwpf)开发并维护,当前版本 v1.0.3。

💬 留言讨论