SKILL.md
HK+US 数据能力
目标
以 Python 脚本直接拉数,不依赖 MCP。默认免密可运行,并提供多渠道兜底策略。
目录
scripts/fetchrealtimehkus.pyscripts/fetchhistoryhkus.pyscripts/fetchtechnicalhkus.pyscripts/fetchfundamentalhkus.pyscripts/fetchsectorhkus.pyscripts/fetchmacrous.pyscripts/fetchuniversehkus.pyscripts/fetchmarketrealtime_hkus.pyscripts/healthcheck_sources.py
安装依赖
pip3 install yfinance pandas numpy requests pandas_datareader yahooquery pytest
代码规范
- US 代码统一输出为
EXCHANGE:TICKER,如NASDAQ:AAPL - HK 代码统一输出为
NNNN.HK,如0700.HK - 结果统一包含:
- sourceprimary - sourceactual - fallbackused - fallbackchain
渠道优先级
US / HK(行情与K线)
- 实时:
tencentquote -> sinaquote -> yahooqueryrealtime -> yfinance -> yahoochart - 历史/技术:
tencenthistory -> sinahistory -> yfinance -> yahooqueryhistory -> yahoochart
腾讯、新浪均区分港/美代码。实时用 usAAPL / hk00700;K 线用 fqkline/get,美股需带交易所后缀(如 usAAPL.OQ、usJPM.N、usSPY.AM,由 qt 行情自动解析)。分钟 K 港股走 minute/query;美股盘中仅返回当前分钟快照,历史分钟由 Yahoo 兜底。实时结果含 market_state 与 premarket;盘中若主源未带盘前,会用 Yahoo 补齐。
其他
- 基本面(US):
yfinance -> yahooquery - 宏观:
fredreader -> fredcsv
快速命令
# 实时
python3 scripts/fetch_realtime_hkus.py --symbol AAPL --json
python3 scripts/fetch_realtime_hkus.py --batch AAPL,TSLA,0700.HK --json
# 历史
python3 scripts/fetch_history_hkus.py --symbol AAPL --interval 1d --days 180 --json
python3 scripts/fetch_history_hkus.py --batch AAPL,MSFT,0700.HK --workers 8 --json
# 技术
python3 scripts/fetch_technical_hkus.py AAPL --days 180 --interval 1d --json
# 基本面
python3 scripts/fetch_fundamental_hkus.py --symbol AAPL --json
# 行业与ETF
python3 scripts/fetch_sector_hkus.py --sector-name 半导体 --days 60 --json
python3 scripts/fetch_sector_hkus.py --symbol 0700.HK --json
# 美国宏观
python3 scripts/fetch_macro_us.py --interest-rates --days 365 --json
python3 scripts/fetch_macro_us.py --inflation-employment --months 36 --json
python3 scripts/fetch_macro_us.py --economic-growth --quarters 24 --json
# 渠道健康检查
python3 scripts/healthcheck_sources.py --us-symbol AAPL --hk-symbol 0700.HK
# 拉全市场股票清单
python3 scripts/fetch_universe_hkus.py --market all --json
python3 scripts/fetch_universe_hkus.py --market us --json
python3 scripts/fetch_universe_hkus.py --market hk --json
# 拉市场当前交易数据(可全市场)
python3 scripts/fetch_market_realtime_hkus.py --market all --universe-limit 800 --top 200 --json
python3 scripts/fetch_market_realtime_hkus.py --market us --universe-limit 1000 --top 100 --sort volume_desc --json
python3 scripts/fetch_market_realtime_hkus.py --symbols NASDAQ:AAPL,NYSE:MSFT,0700.HK --json
输出规则
- 默认输出简版摘要
- 带
--json时输出完整结构 - 若主备源都失败,返回错误标识
source_unavailable