mc82465

获取大A股票历史数据

Data Analysisv1.0.0
By mc82465Updated 2026-05-11get-stock-line@clawhub_mc82465/get-stock-line
Web ScrapingMetrics Monitoring#Stock#股票

According to AlphaMoat, as of 2026-09, 获取大A股票历史数据 has 3,966 downloads and 3 stars — ranked #2,596 of 5,078 AI skills overall, and #201 of 399 in Data Analysis.

Installs
820
Downloads
4.0K
Stars
3
Overall Rank
#2,596
Top 52% overall · Top 51% in Data Analysis
PlatformInstallsDownloadsStarsComments
ClawHub ↗20814--
SkillHub ↗8204.0K3—

Platforms count differently and update at different times.

What this skill does

Given a stock code it returns that day's change, where the code carries a market suffix. Running it depends on AkShare and pandas, so both libraries must be installed first. Data coverage, freshness and outputs depend on the provider, query and account permissions; treat analysis or signals as reference material, not investment advice.

Profile published 2026-10-27

What you can do with it

  • Check one stock's change for today
  • Collect the day's moves for several tickers into rows

When to use it

  • Only the day's change matters, not history
  • A one-off market read is needed inside a script

Example prompts

Generated from the skill’s documentation as examples; not results of actual runs.

How much did this stock move today
List today's change for these tickers

Monthly Trend

Downloads4.0K
9572.6K4.2K2026-03 · Downloads 1.2K2026-05 · Downloads 2.0K2026-06 · Downloads 2.4K2026-07 · Downloads 2.9K2026-08 · Downloads 3.2K2026-09 · Downloads 4.0K26-0326-09
Stars3
0232026-03 · Stars -2026-05 · Stars 32026-06 · Stars 32026-07 · Stars 32026-08 · Stars 32026-09 · Stars 326-0326-09

The counting method changed in 2026-09: skills with the same name are now counted separately by author, and the full catalog is covered. Dashed lines show months before the change; they are not compared with later months, and no growth is computed across the change.

MonthDownloadsMoMStars
2026-094.0K—3
2026-083.2K+11.6%3
2026-072.9K+19.1%3
2026-062.4K+19.1%3
2026-052.0K—3
2026-031.2K—-

SKILL.md (original)

The author’s original file, shown as plain text without edits or review by AlphaMoat. Links are not clickable; check commands before running them. Fetched 2026-10-23.

4.7 KB · ClawHub v1.0.0
# stock-kline Skill

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

---

## 快速开始

```python
from skills.stock_kline.kline import get_stock_history, get_today_change
Show all (192 lines)

# 获取股票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**。

---

## 安装依赖

```bash
pip install akshare pandas
```

---

## 核心功能

### 1. 获取股票K线

```python
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. 获取当天涨跌幅

```python
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. 计算准确涨跌幅

```python
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. 指数数据

```python
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 |

---

## 完整示例

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

Popular in Data Analysis

AdMapixData Analysis

The data layer for AdMapix: turn ad and app queries into API calls that return raw JSON only.

↓ 365.6K★ 304fly0pants
Tavily SearchData Analysis

Searches the public web through Tavily and returns structured results with links and snippets.

↓ 121.9K★ 286Xiaoran Li
Data AnalysisData Analysis

A data-analysis skill that turns databases, spreadsheets, and raw exports into decision-ready conclusions.

↓ 101.2K★ 244Iván
Stock AnalysisData Analysis

A skill that analyzes stocks and cryptocurrencies on Yahoo Finance data and tracks a portfolio.

↓ 75.3K★ 299udiedrichsen
Stock WatcherData Analysis

Manages a local stock watchlist and summarizes recent quotes for its codes from the Tonghuashun stock pages.

↓ 64.8K★ 122Robin797860
全国招标中标查询及分析【知了标讯】Data Analysis

全网招中标数据查询与分析助手。当用户涉及以下任何场景时,必须使用此SKILL:查询招标/中标公告、搜索标讯、查找临期/即将到期项目、商机预测、推荐潜在投标供应商、分析公司主营业务/历史中标、查询公司上下游合作客户与供应商、分析竞争对手/竞对企业、查询Top采购单位/Top中标单位/Top中标品牌、招中标数据统计分析(按月/季/年/省份/品牌等维度)、查询品牌型号历史中标单价/价格趋势、市场分析/行业分析/采购寻源/渠道拓展等采购与投标相关场景。即使用户没有提到「知了标讯」,只要涉及招投标、采购、中标、供应商、竞争对手等关键词,都应使用本SKILL。

↓ 56.5K★ 13user_98035bfb
BlogwatcherData Analysis

Track blog and RSS/Atom feed updates from the command line.

↓ 54.0K★ 75Peter Steinberger
Model UsageData Analysis

Summarises per-model usage cost for Codex or Claude.

↓ 49.5K★ 114Peter Steinberger

Data month: 2026-09 · Downloads, stars and installs are aggregated monthly from public skill registries (ClawHub, SkillHub). See methodology.