Initial commit: Hermes Agent skills collection
- Trading skills (OKX, dividend, lottery, quantitative) - Creative skills (ASCII art, diagrams, video) - Development skills (GitHub, debugging, TDD) - Research skills (arXiv, blog monitoring) - Productivity skills (email, documents, notes) - MCP integration skills - Custom user skills
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
---
|
||||
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()` 返回正常
|
||||
@@ -0,0 +1,190 @@
|
||||
# A股买点分析框架
|
||||
|
||||
综合技术面 + 估值 + 财务 + 盈利预测的完整分析模板。
|
||||
|
||||
## 分析步骤
|
||||
|
||||
### 1. 获取数据
|
||||
|
||||
```python
|
||||
import akshare as ak
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
symbol = '000333' # 股票代码
|
||||
today = datetime.now().strftime('%Y%m%d')
|
||||
start_1y = (datetime.now() - timedelta(days=365)).strftime('%Y%m%d')
|
||||
|
||||
# K线(近1年)
|
||||
df = ak.stock_zh_a_hist(symbol=symbol, period='daily',
|
||||
start_date=start_1y, end_date=today, adjust='qfq')
|
||||
```
|
||||
|
||||
**⚠️ 代理问题**:如果系统有全局代理,AKShare 会报 `ProxyError`。
|
||||
先清除代理:
|
||||
```bash
|
||||
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
|
||||
```
|
||||
或 Python 内:
|
||||
```python
|
||||
for k in ['http_proxy','https_proxy','HTTP_PROXY','HTTPS_PROXY']:
|
||||
os.environ.pop(k, None)
|
||||
```
|
||||
|
||||
### 2. 技术面分析
|
||||
|
||||
#### 价格位置
|
||||
```python
|
||||
current = df.iloc[-1]
|
||||
year_high = df['最高'].max()
|
||||
year_low = df['最低'].min()
|
||||
position = (current['收盘'] - year_low) / (year_high - year_low) * 100
|
||||
```
|
||||
|
||||
#### 均线系统
|
||||
```python
|
||||
for m in [5, 10, 20, 60, 120]:
|
||||
ma = pd.Series(df['收盘']).rolling(m).mean().iloc[-1]
|
||||
dist = (current['收盘'] - ma) / ma * 100 # 偏离度
|
||||
```
|
||||
|
||||
均线多头排列 = 短期在长期之上。偏离度 >5% 警惕回调,<-5% 可能超跌。
|
||||
|
||||
#### ATR 波动率
|
||||
```python
|
||||
tr_list = []
|
||||
for i in range(1, len(df.tail(20))):
|
||||
h_l = df.tail(20).iloc[i]['最高'] - df.tail(20).iloc[i]['最低']
|
||||
h_pc = abs(df.tail(20).iloc[i]['最高'] - df.tail(20).iloc[i-1]['收盘'])
|
||||
l_pc = abs(df.tail(20).iloc[i]['最低'] - df.tail(20).iloc[i-1]['收盘'])
|
||||
tr_list.append(max(h_l, h_pc, l_pc))
|
||||
atr14 = sum(tr_list[-14:]) / min(14, len(tr_list))
|
||||
```
|
||||
|
||||
#### 支撑阻力
|
||||
```python
|
||||
support20 = df.tail(20)['最低'].min()
|
||||
resist20 = df.tail(20)['最高'].max()
|
||||
support60 = df.tail(60)['最低'].min()
|
||||
resist60 = df.tail(60)['最高'].max()
|
||||
```
|
||||
|
||||
#### 量能分析
|
||||
```python
|
||||
avg_vol_20 = df.tail(20)['成交量'].mean()
|
||||
latest_vol_ratio = df.iloc[-1]['成交量'] / avg_vol_20
|
||||
```
|
||||
量比 > 1.5 = 显著放量,< 0.5 = 缩量。
|
||||
|
||||
#### MACD
|
||||
```python
|
||||
closes = df['收盘'].values
|
||||
ema12 = pd.Series(closes).ewm(span=12).mean().iloc[-1]
|
||||
ema26 = pd.Series(closes).ewm(span=26).mean().iloc[-1]
|
||||
dif = ema12 - ema26
|
||||
dea = pd.Series(pd.Series(closes).ewm(span=12).mean() - pd.Series(closes).ewm(span=26).mean()).ewm(span=9).mean().iloc[-1]
|
||||
```
|
||||
|
||||
#### 近期趋势强度
|
||||
```python
|
||||
up_days = len(df.tail(20)[df.tail(20)['涨跌幅'] > 0])
|
||||
down_days = 20 - up_days
|
||||
recent_10_return = df.tail(10)['涨跌幅'].sum()
|
||||
recent_5_return = df.tail(5)['涨跌幅'].sum()
|
||||
```
|
||||
|
||||
### 3. 估值分析
|
||||
|
||||
```python
|
||||
# 东方财富实时行情含PE/PB/市值
|
||||
df_spot = ak.stock_zh_a_spot_em()
|
||||
row = df_spot[df_spot['代码'] == symbol].iloc[0]
|
||||
pe_dynamic = row['市盈率-动态']
|
||||
pb = row['市净率']
|
||||
market_cap = row['总市值']
|
||||
```
|
||||
|
||||
### 4. 盈利预测
|
||||
|
||||
```python
|
||||
df_fc = ak.stock_profit_forecast_ths(symbol=symbol)
|
||||
# 返回: 年度, 预测机构数, 最小值, 均值, 最大值, 行业平均数
|
||||
|
||||
# 计算远期PE
|
||||
current_price = df.iloc[-1]['收盘']
|
||||
for _, r in df_fc.iterrows():
|
||||
pe_fwd = current_price / r['均值']
|
||||
print(f"{r['年度']}E PE: {pe_fwd:.1f}x")
|
||||
```
|
||||
|
||||
### 5. 财务基本面
|
||||
|
||||
**new API (长格式)**:
|
||||
```python
|
||||
df_f = ak.stock_financial_abstract_new_ths(symbol=symbol)
|
||||
profit = df_f[df_f['metric_name'] == 'parent_holder_net_profit'].iloc[0]
|
||||
yoy = profit['yoy'] # 同比增长率
|
||||
```
|
||||
|
||||
**旧API (宽格式)**:
|
||||
```python
|
||||
df_f = ak.stock_financial_abstract_ths(symbol=symbol)
|
||||
```
|
||||
|
||||
**现金流**:
|
||||
```python
|
||||
df_cf = ak.stock_financial_cash_ths(symbol=symbol)
|
||||
```
|
||||
|
||||
**资产负债**:
|
||||
```python
|
||||
df_d = ak.stock_financial_debt_ths(symbol=symbol)
|
||||
```
|
||||
|
||||
### 6. 买点策略模板
|
||||
|
||||
#### 策略A:回踩均线建仓(稳健)
|
||||
```
|
||||
第一买点: MA20 ± 0.5
|
||||
止损: S60 - 1 (略低于中期支撑)
|
||||
目标: R20 (近20日高点)
|
||||
```
|
||||
|
||||
#### 策略B:突破确认加仓(激进)
|
||||
```
|
||||
第一买点: 现价轻仓
|
||||
第二买点: 突破MA20后回踩确认
|
||||
止损: MA10下方
|
||||
目标: 前高
|
||||
```
|
||||
|
||||
#### 策略C:等回调(最稳健)
|
||||
```
|
||||
买点: S20 ~ (S20 + 0.5 * ATR)
|
||||
止损: S60 - ATR
|
||||
目标: R20
|
||||
```
|
||||
|
||||
### 输出格式
|
||||
|
||||
简洁卡片式,用 emoji + 表格,避免大段文字。包含:
|
||||
- 📊 盘面概览(今日涨跌、量比、ATR)
|
||||
- 📈 均线位置(表格式)
|
||||
- 🎯 支撑阻力
|
||||
- 💰 估值(PE/PB + 远期PE)
|
||||
- ⚡ 催化剂 + ⚠️ 风险
|
||||
- 具体买点/止损/目标位
|
||||
|
||||
### 数据源选择
|
||||
|
||||
| 数据 | 推荐函数 | 速度 |
|
||||
|------|----------|------|
|
||||
| K线/行情 | `stock_zh_a_hist()` 东方财富 | 1-2s |
|
||||
| 实时行情含PE | `stock_zh_a_spot_em()` 东方财富 | ~70s(首) / 快(缓存) |
|
||||
| 财务摘要(新) | `stock_financial_abstract_new_ths()` | 2-3s |
|
||||
| 财务摘要(旧/宽) | `stock_financial_abstract_ths()` | 2-3s |
|
||||
| 盈利预测 | `stock_profit_forecast_ths()` | 2-3s |
|
||||
| 现金流 | `stock_financial_cash_ths()` | 2-3s |
|
||||
| 资产负债 | `stock_financial_debt_ths()` | 2-3s |
|
||||
| 主营业务 | `stock_zyjs_ths()` | 1-2s |
|
||||
Reference in New Issue
Block a user