获取大A股票历史数据

获取大A股股票和指数历史K线数据(默认前复权),支持自动切换数据源并获取当天涨跌幅。

MIT-0 · Free to use, modify, and redistribute. No attribution required.
0 · 20 · 0 current installs · 0 all-time installs
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
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.
Assessment
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.

Like a lobster shell, security has layers — review code before you run it.

Current versionv1.0.0
Download zip
latestvk970935ggekffbzgf6983xa9jh831hdd

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

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}%")

Files

2 total
Select a file
Select a file to preview.

Comments

Loading comments…