Files
Hermes-Skills/tonghuashun/SKILL.md
T
mike 657dc41c46 Initial commit: Trading skills collection
- OKX交易自动化 (okx-auto-position, okx-crypto, okx-exchange)
- 交易信号处理 (signal-confirmation-templates, trading-signal-aggregator)
- 量化因子挖掘 (quant-factor-mining)
- 长桥集成 (longbridge-cli, longbridge-python-sdk)
- 六合彩分析 (lottery-hk)
- 股息投资 (dividend-investing, dividend-scanner)
- 日内交易 (intraday-trading)
- 同花顺 (tonghuashun)
2026-07-05 02:39:41 -04:00

246 lines
9.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: tonghuashun
description: "Use when user mentions '同花顺', 'THS', 'A股行情', 'A股财务', 'A股板块', 'A股排名', 'a股数据', or wants A-share stock market data (real-time quotes, K-lines, financials, board/concept analysis, market rankings). Provides A-share data via AKShare (同花顺/东方财富 sources). Cannot execute trades (同花顺无Linux API)."
version: 1.0.0
author: Hermes Agent
license: MIT
platforms: [linux, macos]
metadata:
hermes:
tags: [trading, a-shares, stocks, data, china-market]
related_skills: [stock-analysis, longbridge-python-sdk]
scripts:
- ths_query.py: "python3 ~/.hermes/scripts/ths_query.py {quote|kline|financial|board|rank|scan} [args]"
requires:
- python3 + akshare (pip install akshare)
- pandas
---
# 同花顺 A股数据 Skill
基于 **AKShare**(同花顺/东方财富数据源)的 A 股行情数据查询工具。**只做数据查询,不做交易执行**(同花顺无官方 Linux API)。
## 数据源说明
AKShare 是一个免费开源的 Python 金融数据接口库,底层数据源包括:
- **同花顺 (THS)** — 财务数据、板块概念、排名、IPO、股东变动等
- **东方财富 (EM)** — 实时行情、K线、个股信息
- **新浪/腾讯** — 辅助行情源
所有数据**免费**、**无需API Key**,直接从网页公开接口爬取。
## 何时使用
- 用户问 A 股行情:"看看茅台多少钱"、"A股今天涨跌"
- 用户问财务基本面:"五粮液PE多少"、"宁德时代净利润"
- 用户问板块:"今天什么板块涨得好"、"AI概念股有哪些"
- 用户要排名:"连续下跌的股票"、"创新高的股票"
- 用户要 A 股数据补充长桥 LongBridge 的覆盖
## 核心函数速查
### 1️⃣ 实时行情
```python
import akshare as ak
# 方式A: 全市场行情(第一次调用慢~70s,后续有缓存)
df = ak.stock_zh_a_spot_em()
# 筛选特定股票
df[df['代码'].isin(['600519','000858','000333'])][['代码','名称','最新价','涨跌幅','成交额','换手率']]
# 方式B: 单只股票日K(快速 1-2s)
df = ak.stock_zh_a_hist(symbol='600519', period='daily',
start_date='20260601', end_date='20260629', adjust='qfq')
# 最新价=收盘价最后一列,涨跌幅也在里面
```
### 2️⃣ 同花顺财务数据
```python
# 财务摘要(利润表核心指标)
df = ak.stock_financial_abstract_ths(symbol='600519') # 旧版
df = ak.stock_financial_abstract_new_ths(symbol='600519') # 新版
# 盈利能力
df = ak.stock_financial_benefit_ths(symbol='600519')
# 现金流
df = ak.stock_financial_cash_ths(symbol='600519')
# 资产负债
df = ak.stock_financial_debt_ths(symbol='600519')
```
### 3️⃣ 主营业务
```python
df = ak.stock_zyjs_ths(symbol='600519')
# 返回: 股票代码, 主营业务, 产品类型, 产品名称, 经营范围
```
### 4️⃣ 板块/概念
```python
# 行业板块名称列表
df = ak.stock_board_industry_name_ths() # 56个行业
# 概念板块名称列表
df = ak.stock_board_concept_name_ths() # 373+个概念
# 行业板块行情(含涨跌幅)
df = ak.stock_board_industry_summary_ths()
# 概念板块行情
df = ak.stock_board_concept_summary_ths()
# 板块历史K线
df = ak.stock_board_industry_index_ths(symbol='白酒概念')
df = ak.stock_board_concept_index_ths(symbol='AI手机')
```
### 5️⃣ 市场排名
```python
# 连续下跌
df = ak.stock_rank_cxd_ths() # 连续下跌
df = ak.stock_rank_cxfl_ths() # 连续下跌分类
df = ak.stock_rank_cxg_ths() # 连续上涨
df = ak.stock_rank_cxsl_ths() # 连续上涨分类
# 量价
df = ak.stock_rank_ljqd_ths() # 量价齐跌
df = ak.stock_rank_ljqs_ths() # 量价齐升
df = ak.stock_rank_lxsz_ths() # 连续上涨(另一种)
df = ak.stock_rank_lxxd_ths() # 连续下跌(另一种)
# 形态
df = ak.stock_rank_xstp_ths() # 向上突破
df = ak.stock_rank_xxtp_ths() # 向下突破
df = ak.stock_rank_xzjp_ths() # 向中间靠
```
### 6️⃣ 股东/管理层变动
```python
df = ak.stock_shareholder_change_ths(symbol='600519') # 股东变动
df = ak.stock_management_change_ths(symbol='600519') # 高管变动
```
### 7️⃣ IPO
```python
df = ak.stock_ipo_ths() # A股IPO一览
df = ak.stock_ipo_benefit_ths() # IPO受益股
df = ak.stock_ipo_hk_ths() # 港股IPO
```
### 8️⃣ 利润预测
```python
df = ak.stock_profit_forecast_ths(symbol='600519') # 盈利预测
```
## 快速 CLI 工具
项目已包含一个速查脚本 `~/.hermes/scripts/ths_query.py`,可直接在终端使用:
```bash
python3 ~/.hermes/scripts/ths_query.py quote 600519 # 实时行情
python3 ~/.hermes/scripts/ths_query.py kline 600519 5 # 最近5天K线
python3 ~/.hermes/scripts/ths_query.py financial 600519 # 财务摘要
python3 ~/.hermes/scripts/ths_query.py board industry # 行业板块排行
python3 ~/.hermes/scripts/ths_query.py board concept # 概念板块排行
python3 ~/.hermes/scripts/ths_query.py rank cxd # 连续下跌
python3 ~/.hermes/scripts/ths_query.py scan # 全市场速览
```
## 快速查询模板
### 查单只股票行情
```python
import akshare as ak
from datetime import datetime, timedelta
code = '600519' # 用户输入的股票代码
today = datetime.now().strftime('%Y%m%d')
# 往前取5天确保有数据
start = (datetime.now() - timedelta(days=5)).strftime('%Y%m%d')
df = ak.stock_zh_a_hist(symbol=code, period='daily',
start_date=start, end_date=today, adjust='qfq')
latest = df.iloc[-1]
print(f"{latest['日期']} | {code} | 收盘: {latest['收盘']} | 涨跌: {latest['涨跌幅']}% | 成交额: {latest['成交额']/1e8:.2f}亿")
```
### 查板块涨跌排行
```python
import akshare as ak
df = ak.stock_board_industry_summary_ths()
top5 = df.head(5) # 涨幅前5
bot5 = df.tail(5) # 跌幅前5
```
### 查财务数据(同比)
```python
df = ak.stock_financial_abstract_new_ths(symbol='600519')
# 取最近一期
latest = df.iloc[0]
print(f"营收: {latest['营业总收入']} | 净利润: {latest['净利润']} | 净利同比: {latest.get('净利润同比增长率','N/A')}")
```
## 注意事项
⚠️ 以下函数**下载全市场数据**,第一次调用较慢(30-70秒),但后续调用有缓存:
- `stock_zh_a_spot_em()` — 全市场实时行情(5000+只)
- `stock_board_industry_summary_ths()` — 行业板块行情
- `stock_board_concept_summary_ths()` — 概念板块行情
- `stock_rank_*_ths()` — 各种排名
⚠️ 推荐策略:优先用 `stock_zh_a_hist()` 单只查询(1-2秒),全市场扫描用 `stock_zh_a_spot_em()` 一次性拉取。
⚠️ 同花顺数据源偶尔会因反爬机制暂时不可用,建议备选东方财富数据源:
- `ak.stock_zh_a_hist()` — 东方财富K线(稳定)
- `ak.stock_zh_a_spot_em()` — 东方财富实时行情(稳定)
## Common Pitfalls
1. **代码格式**:A股代码直接传字符串(如 '600519'),不要加后缀
2. **实时行情慢**full_spot = `stock_zh_a_spot_em()` 第一次跑很慢,但Hermes会话中变量保持,可以复用
3. **同花顺 vs 东方财富**:同花顺的财务/板块数据更全,东方财富的K线/行情更稳定,按需选择
4. **无法交易**:同花顺没有Linux API,本skill只做数据查询
5. **数字货币/期货**AKShare也支持,但不是本skill重点
6. **板块列名是'板块'不是'板块名称'**`stock_board_industry_summary_ths()` 返回的列名是中文'板块',不是'板块名称'。直接用 `df['板块']` 取,`ths_query.py` 已处理此问题
7. **全市场扫描只跑一次**`stock_zh_a_spot_em()` 拉全市场约70秒,跑完后 DataFrame 可重复筛选多只股票,不要每查一只就重新拉一次
8. **🔴 系统全局代理会阻断AKShare请求**:如果系统设置了 `HTTP_PROXY`/`HTTPS_PROXY` 环境变量,`requests` 库会自动走代理,但代理(如 mihomo clash)可能不支持 HTTPS CONNECT 到东方财富/同花顺的 API 域名,导致 `ProxyError`
**症状**`requests.exceptions.ProxyError: HTTPSConnectionPool(host='push2his.eastmoney.com')`
**诊断**`env | grep -i proxy`
**修复**:在 Python 中调用 AKShare 前清除代理变量:
```python
import os
for k in ['http_proxy','https_proxy','HTTP_PROXY','HTTPS_PROXY']:
os.environ.pop(k, None)
```
或在终端中 `unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY`。
或使用 Session 关闭代理:`s.trust_env = False`
9. **`stock_financial_abstract_new_ths()` 返回长格式**:该函数返回长格式 DataFrame,列名为 `['report_date','report_name','report_period','quarter_name','metric_name','value','single','yoy','mom','single_yoy']``metric_name` 字段包含指标名称(如 `parent_holder_net_profit`),`value` 为数值。需筛选 `metric_name` 提取具体指标:
```python
df = ak.stock_financial_abstract_new_ths(symbol='000333')
profit = df[df['metric_name'] == 'parent_holder_net_profit']
print(f"净利润: {profit.iloc[0]['value']}")
```
如需宽格式,用旧版 `stock_financial_abstract_ths()`。
## Reference Documents
See `references/buy-point-analysis.md` for a complete A-share buy-point analysis framework (technical + valuation + financials + profit forecast + entry/stop/target strategy templates).
## Verification Checklist
- [ ] `pip show akshare` 确认已安装
- [ ] 单只行情: `stock_zh_a_hist(symbol='600519')` 返回正常
- [ ] THS财务: `stock_financial_abstract_ths(symbol='600519')` 返回正常
- [ ] 板块: `stock_board_industry_name_ths()` 返回正常