# Astock Data Source

> A 股多源数据源统一管理 (v2.0 - 多源 fallback)。当用户需要获取股票行情/K线/财务数据/新闻/公告/资金流等任何 A 股数据,或需要稳定的 API 封装 (含自动重试/限流/降级/缓存) 时,Claude 应优先使用此 Skill。这是其他所有 Skill 的基础数据源。**v2.0 已修复住宅 IP 数据源问题**。

- **Type:** Skill
- **Install:** `agentstack add skill-zicxr-a-stock-skills-astock-data-source`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [ZICXR](https://agentstack.voostack.com/s/zicxr)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [ZICXR](https://github.com/ZICXR)
- **Source:** https://github.com/ZICXR/A-Stock-Skills/tree/main/skills/01-infra/astock-data-source
- **Website:** https://github.com/ZICXR/A-Stock-Skills#readme

## Install

```sh
agentstack add skill-zicxr-a-stock-skills-astock-data-source
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# A 股多源数据源管理 Skill (v2.0)

## 何时使用

- 用户需要获取股票数据
- 用户需要稳定的 API 封装
- 用户在住宅网络环境下使用
- 任何需要 A 股数据的 Skill

## ⚠️ 重要更新 (v2.0)

**修复了住宅 IP 数据源被封问题**:

| 优先级 | 数据源 | 实测可用 | 备注 |
|--------|--------|----------|------|
| 1️⃣ | **ifzq gtimg** (腾讯) | ✅ 90%+ | **住宅 IP 首选** |
| 2️⃣ | 新浪 hq.sinajs.cn | ✅ 80%+ | 全市场列表也用这个 |
| 3️⃣ | 东财 push2.eastmoney | ❌ 30% | 经常被封, 仅作备用 |
| 4️⃣ | akshare | ✅ 85% | 聚合源, fallback |

**自动 fallback 机制**:
- 每个数据源连续失败 3 次自动跳过
- 支持多源切换, 不再硬抛"所有数据源失败"
- 修复了 Windows GBK 编码问题
- 修复了 akshare 内部代理问题

## 🏃 快速验证 (网络环境测试)

```bash
# 测试你的网络环境
python main.py healthcheck

# 输出示例:
# === 数据源健康检查 ===
#   ✅ ifzq_gtimg
#   ✅ sina_hq
#   ❌ eastmoney_push2 (被风控, 已自动跳过)
#   ✅ sina 全市场: 5028 只
```

## 提供能力

### 行情
- `get-realtime --code X` - 单股实时 (多源)
- `get-realtime-all` - 全 A 股实时 (用新浪)
- `get-kline --code X --days N` - K 线 (用 ifzq)

### 指数
- `get-index-realtime` - 主要指数
- `get-index-kline --symbol X` - 指数 K 线

### 其他
- `get-stock-info --code X` - 股票信息
- `get-news --code X` - 个股新闻
- `healthcheck` - 数据源健康检查

## 使用方式

### 命令行 (新规范)

```bash
# ✅ 正确: 用 --code 命名参数
python main.py get-realtime --code 601991
python main.py get-kline --code 601991 --days 60

# ✅ 正确: --list 列出方法
python main.py --list

# ❌ 旧版 (已废弃): 位置参数
python main.py get-realtime 601991
```

### Python API

```python
from skills.01-infra.astock-data-source.main import (
    get_realtime, get_realtime_all, get_kline
)

# 单股 (自动多源 fallback)
quote = get_realtime("601991")

# 全 A 股
all_stocks = get_realtime_all()

# K 线
df = get_kline("601991", days=60)
```

## 故障速查

| 现象 | 原因 | 解决 |
|------|------|------|
| `ProxyError: 7890` | 代理挡住外网 | 切到 ifzq/sina |
| `RemoteDisconnected` | 东财被封 | 等待 3 次后自动切 |
| `UnicodeEncodeError` (Win) | GBK 编码 | 已自动修复 |
| `所有数据源失败` | 网络隔离 | 运行 healthcheck 检查 |

## 依赖

```
requests>=2.28.0
akshare>=1.12.0
pandas>=1.5.0
```

## 实测状态

- **2026-06-21**: 住宅 IP 验证通过, ifzq + sina 稳定可用
- **2026-05-03**: 旧版在住宅 IP 100% 失败 (已修复)

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [ZICXR](https://github.com/ZICXR)
- **Source:** [ZICXR/A-Stock-Skills](https://github.com/ZICXR/A-Stock-Skills)
- **License:** MIT
- **Homepage:** https://github.com/ZICXR/A-Stock-Skills#readme

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-zicxr-a-stock-skills-astock-data-source
- Seller: https://agentstack.voostack.com/s/zicxr
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
