← 返回 Skills 市场
mc82465

获取大A股票历史数据

作者 mc82465 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
180
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install get-stock-line
功能描述
获取大A股股票和指数历史K线数据(默认前复权),支持自动切换数据源并获取当天涨跌幅。
使用说明 (SKILL.md)

stock-kline Skill

获取A股股票和指数历史K线数据。支持自动切换数据源,默认使用前复权数据


快速开始

from skills.stock_kline.kline import get_stock_history, get_today_change

# 获取股票K线 (前复权,自动切换数据源)
data = get_stock_history("600519.SH", days=100)

# 获取当天涨跌幅
result = get_today_change("600519.SH")
# 返回: {open, close, high, low, change, change_pct, volume}

数据源 (自动切换)

优先级 数据源 复权支持 说明
1️⃣ AKShare ✅ 前复权/后复权 首选,数据准确
2️⃣ 新浪财经API ❌ 不支持 降级备用,仅未复权

自动切换逻辑

get_stock_history(code, adjust="qfq")
    │
    ├─→ AKShare (前复权) ✅
    │       成功 → 返回复权数据
    │       失败 → 继续
    │
    └─→ 新浪API (未复权) ⚠️
            成功 → 返回未复权数据
            失败 → 返回空列表

⚠️ 重要: 新浪API不支持复权,除权日会有跳空。强烈建议安装AKShare


安装依赖

pip install akshare pandas

核心功能

1. 获取股票K线

from skills.stock_kline.kline import get_stock_history

# 前复权数据 (默认,解决除权问题)
data = get_stock_history("600519.SH", days=100)

# 后复权
data = get_stock_history("600519.SH", days=100, adjust="hfq")

# 不复权 (原始价格)
data = get_stock_history("600519.SH", days=100, adjust="")

2. 获取当天涨跌幅

from skills.stock_kline.kline import get_today_change

result = get_today_change("600519.SH")
# 返回:
# {
#     "open": 1440.0,      # 开盘价
#     "close": 1453.1,     # 当前价格
#     "high": 1460.0,      # 最高
#     "low": 1430.0,       # 最低
#     "change": 13.1,      # 涨跌额
#     "change_pct": 0.91,  # 涨跌幅%
#     "volume": 1000000    # 成交量
# }

3. 计算准确涨跌幅

from skills.stock_kline.kline import get_accurate_change

# 计算2026-03-13相比2026-03-12的涨幅
result = get_accurate_change("600519.SH", "2026-03-13", "2026-03-12")
# 返回: {target_price: 1413.64, prev_price: 1392.0, change_pct: 1.55}

4. 指数数据

from skills.stock_kline.kline import get_index_history

# 上证指数
data = get_index_history("000001.SH", 100)

# 深证成指
data = get_index_history("399001.SZ")

# 创业板指
data = get_index_history("399006.SZ")

# 沪深300
data = get_index_history("000300.SH")

股票/指数代码

类型 格式 示例
上证股票 600519.SH 贵州茅台
深证股票 300750.SZ 宁德时代
创业板 300001.SZ 创业板股票
上证指数 000001.SH 上证指数
深证指数 399001.SZ 深证成指

复权说明

什么是复权?

股票除权除息后,股价会下跌。如果不复权 Historical 价格会出现跳空。

复权类型 说明 适用场景
前复权 (qfq) 历史价格按最新价格调整 推荐用于计算涨幅
后复权 (hfq) 最新价格按历史价格调整 长期持有收益计算
不复权 原始价格 不推荐,有跳空

⚠️ 使用前复权数据计算涨幅可以消除除权除息导致的跳空,得到真实收益率。


函数列表

函数 说明 返回格式
get_stock_history(code, days, adjust) 获取股票K线 List[Dict]
get_today_change(code) 获取当天涨跌幅 Dict
get_accurate_change(code, date1, date2, adjust) 计算两日间涨幅 Dict
get_index_history(code, days) 获取指数K线 List[Dict]
calc_change_rate(old, new) 计算涨跌幅% Float
build_price_map(kline_data) 构建价格映射 Dict

完整示例

from skills.stock_kline.kline import (
    get_stock_history,
    get_today_change,
    get_accurate_change,
    calc_change_rate
)

# 示例:贵州茅台

# 1. 获取实时行情
quote = get_today_change("600519.SH")
print(f"当前价格: {quote['close']}, 涨跌幅: {quote['change_pct']}%")

# 2. 获取历史K线 (前复权)
kline = get_stock_history("600519.SH", days=20)
print(f"最近20天数据: {len(kline)}条")

# 3. 计算指定日期涨幅
result = get_accurate_change("600519.SH", "2026-03-13", "2026-03-12")
print(f"涨幅: {result['change_pct']}%")

# 4. 手动计算涨幅
if len(kline) >= 2:
    today = float(kline[0]['close'])
    yesterday = float(kline[1]['close'])
    change = calc_change_rate(yesterday, today)
    print(f"今日涨幅: {change}%")
安全使用建议
This skill appears to do what it claims: fetch A‑share historical and intraday data using AKShare (preferred) and Sina as fallback. Before installing/using it: - Be aware it makes outbound network requests to public finance APIs (Sina) and will import/execute code from the akshare PyPI package if you install it. If you run this in a sensitive environment, install and run in an isolated virtualenv/container. - Verify and pin akshare/pandas package versions (pip install akshare==<version> pandas==<version>) to avoid unexpected upstream changes. - Note a correctness bug: get_today_change's AKShare branch uses hardcoded dates (20260301–20260316) which will not return current realtime data — consider editing that function to use dynamic dates or rely on the Sina fallback. - If you need strong guarantees about data provenance or safety, review AKShare's code and consider limiting network access or running the skill in a sandbox. Otherwise, the skill is coherent and does not request secrets or elevated privileges.
功能分析
Type: OpenClaw Skill Name: get-stock-line Version: 1.0.0 The skill bundle provides legitimate functionality for fetching Chinese stock and index historical data using the AKShare library and Sina Finance APIs. The code in `kline.py` implements standard data retrieval patterns, including error handling and fallback mechanisms, without any signs of data exfiltration, unauthorized execution, or persistence. While there are hardcoded future dates (March 2026) in the `_get_today_change_akshare` function, these appear to be development artifacts or specific test cases rather than malicious logic.
能力评估
Purpose & Capability
The name/description match the code and SKILL.md: the implementation fetches historical K‑line and today's change, preferring AKShare (supports adjusted data) and falling back to Sina (unadjusted). No unrelated credentials, binaries, or config paths are requested.
Instruction Scope
SKILL.md and the code stay within the stated purpose and only perform network calls to public finance endpoints (AKShare/PyPI and Sina). They do not read environment variables or local config. Two practical issues to be aware of: (1) SKILL.md recommends 'pip install akshare pandas' but does not pin versions; (2) the code has an odd hardcoded date range in _get_today_change_akshare (start_date="20260301", end_date="20260316"), which is inconsistent with the intended real‑time behavior and looks like a leftover test/hardcode — this is a correctness bug, not evidence of malicious intent.
Install Mechanism
There is no formal install spec in the skill bundle (instruction-only). The README advises installing akshare and pandas via pip (PyPI). Installing PyPI packages is normal but can execute arbitrary code at install/runtime — consider verifying package provenance and pinning versions before installation.
Credentials
The skill requests no environment variables, no credentials, and no config paths. All network calls go to public finance APIs (sina endpoints) or rely on AKShare, which is proportionate to the stated functionality.
Persistence & Privilege
always:false and no installation-time modifications are requested. The skill can be invoked autonomously by agents per default platform rules; there is nothing in the code that attempts to persistently modify other skills or system configuration.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install get-stock-line
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /get-stock-line 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of the stock-kline skill. - 支持获取A股股票和指数历史K线数据,自动切换数据源(优先AKShare,降级为新浪财经API)。 - 提供前复权、后复权、未复权三种历史价格选择,默认前复权。 - 可获取当天涨跌幅、涨跌额及成交量。 - 新增精准计算任意两个日期之间的涨幅方法。 - 同时支持主要指数(上证、深证、创业板、沪深300)的K线数据获取。 - 简洁API设计,详细示例及用法文档。
元数据
Slug get-stock-line
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

获取大A股票历史数据 是什么?

获取大A股股票和指数历史K线数据(默认前复权),支持自动切换数据源并获取当天涨跌幅。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 180 次。

如何安装 获取大A股票历史数据?

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

获取大A股票历史数据 是免费的吗?

是的,获取大A股票历史数据 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

获取大A股票历史数据 支持哪些平台?

获取大A股票历史数据 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 获取大A股票历史数据?

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

💬 留言讨论