stock-analysis-plugin 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +34 -8
  2. package/package.json +1 -1
  3. package/pi/index.ts +27 -27
  4. package/skills/bottom-volume/SKILL.md +1 -4
  5. package/skills/bottom-volume/scripts/gather.py +1 -1
  6. package/skills/box-oscillation/SKILL.md +1 -4
  7. package/skills/box-oscillation/scripts/gather.py +1 -1
  8. package/skills/bull-trend/SKILL.md +1 -4
  9. package/skills/bull-trend/scripts/gather.py +1 -1
  10. package/skills/chan-theory/SKILL.md +1 -4
  11. package/skills/chan-theory/scripts/gather.py +1 -1
  12. package/skills/dragon-head/SKILL.md +22 -28
  13. package/skills/dragon-head/scripts/gather.py +1 -1
  14. package/skills/emotion-cycle/SKILL.md +17 -33
  15. package/skills/emotion-cycle/scripts/gather.py +4 -3
  16. package/skills/event-driven/SKILL.md +42 -26
  17. package/skills/event-driven/scripts/gather.py +1 -1
  18. package/skills/expectation-repricing/SKILL.md +11 -6
  19. package/skills/expectation-repricing/scripts/gather.py +1 -1
  20. package/skills/growth-quality/SKILL.md +11 -6
  21. package/skills/growth-quality/scripts/gather.py +1 -1
  22. package/skills/hot-theme/SKILL.md +25 -22
  23. package/skills/hot-theme/scripts/gather.py +1 -1
  24. package/skills/ma-crossover/SKILL.md +1 -4
  25. package/skills/ma-crossover/scripts/gather.py +1 -1
  26. package/skills/market-review/SKILL.md +11 -8
  27. package/skills/market-review/scripts/gather.py +1 -1
  28. package/skills/one-yang-three-yin/SKILL.md +1 -4
  29. package/skills/one-yang-three-yin/scripts/gather.py +1 -1
  30. package/skills/shrink-pullback/SKILL.md +1 -4
  31. package/skills/shrink-pullback/scripts/gather.py +1 -1
  32. package/skills/stock-analysis/SKILL.md +12 -79
  33. package/skills/stock-analysis/references/short-term-trading.md +78 -0
  34. package/skills/stock-analysis/scripts/gather.py +1 -1
  35. package/skills/stock-screener/SKILL.md +7 -6
  36. package/skills/stock-screener/scripts/gather.py +1 -1
  37. package/skills/strategy-backtest/SKILL.md +24 -20
  38. package/skills/strategy-backtest/scripts/gather.py +1 -1
  39. package/skills/volume-breakout/SKILL.md +21 -23
  40. package/skills/volume-breakout/scripts/gather.py +1 -1
  41. package/skills/wave-theory/SKILL.md +1 -4
  42. package/skills/wave-theory/scripts/gather.py +1 -1
  43. package/skills/wisburg-research/SKILL.md +2 -2
  44. package/tools/_subproc.py +18 -5
  45. package/tools/alert_rules.py +1 -20
  46. package/tools/capabilities.py +3 -4
  47. package/tools/diagnostics.py +13 -2
  48. package/tools/gather.py +7 -21
  49. package/tools/market_regime.py +4 -1
  50. package/tools/position_context.py +1 -19
  51. package/tools/stock_data.py +317 -75
  52. package/tools/watchlist_context.py +1 -19
@@ -1,22 +1,21 @@
1
1
  ---
2
2
  name: stock-screener
3
- description: 全市场股票筛选 — AlphaSift L1硬筛 + LLM智能排序。当用户要求选股或筛选时使用。
4
- allowed-tools: Bash(python3:*) Read
3
+ description: 全市场股票筛选:按市场、估值、成长、趋势或自定义条件生成候选列表并排序。已知个股的深度分析用 stock-analysis。
5
4
  ---
6
5
 
7
6
  # 全市场股票筛选
8
7
 
9
- 你是一位量化选股分析师。帮助用户从全市场中筛选出符合条件的股票。
10
-
11
8
  ## 执行流程
12
9
 
13
- ### 第一步:确认筛选条件
10
+ ### 第一步:确定筛选条件
14
11
 
15
- 向用户确认:
12
+ 优先从用户请求提取:
16
13
  - **市场**:A股 / 港股 / 美股(默认A股)
17
14
  - **筛选偏好**:价值型、成长型、趋势型、还是自定义条件
18
15
  - **返回数量**:默认 Top 20
19
16
 
17
+ 未指定的项直接使用默认值并在结果中说明;只有自定义条件彼此冲突时才请用户补充。
18
+
20
19
  ### 第二步:运行筛选
21
20
 
22
21
  运行数据采集脚本进行 L1 量化筛选:
@@ -65,6 +64,8 @@ python3 scripts/gather.py --market A --top 20
65
64
  - 建议结合个股深度分析后再做决策
66
65
  ```
67
66
 
67
+ 完成标准:列出实际生效的市场、过滤条件、排序口径和候选数量,且推荐理由只使用返回数据。
68
+
68
69
  ## 策略模板
69
70
 
70
71
  如果用户没有明确条件,提供预设策略:
@@ -11,7 +11,7 @@ for _s in (sys.stdout, sys.stderr):
11
11
  if hasattr(_s, "reconfigure"):
12
12
  _s.reconfigure(encoding="utf-8")
13
13
 
14
- tools = Path(__file__).resolve().parents[2] / "tools"
14
+ tools = Path(__file__).resolve().parents[3] / "tools"
15
15
  result = subprocess.run(
16
16
  [sys.executable, str(tools / "gather.py"), "screen"] + sys.argv[1:],
17
17
  capture_output=True,
@@ -1,12 +1,11 @@
1
1
  ---
2
2
  name: strategy-backtest
3
- description: 策略回测与优化 — AlphaEvo YAML策略定义、回测、诊断、进化。当用户要求回测交易策略时使用。
4
- allowed-tools: Bash(python3:*) Read
3
+ description: 策略回测:定义或读取 AlphaEvo YAML 策略,回测收益、回撤和交易统计。仅在用户明确要求时进行参数优化。
5
4
  ---
6
5
 
7
6
  # 策略回测与优化
8
7
 
9
- 你是一位量化策略研究员。帮助用户定义、回测、诊断和优化交易策略。
8
+ 开始前读取[短线交易决策框架](../stock-analysis/references/short-term-trading.md)的风险单位和回测约束。回测用于反证策略,不把样本内收益包装成预测。
10
9
 
11
10
  ## 工作流程
12
11
 
@@ -65,19 +64,18 @@ python3 scripts/gather.py --strategy <path.yaml> --symbol <symbol> --start <date
65
64
 
66
65
  ### 第三步:分析结果
67
66
 
68
- 回测完成后,详细分析各项指标:
67
+ 回测完成后,按共享框架的风险单位和回测约束解释原始结果。针对本工具:
69
68
 
70
- | 指标 | 优秀 | 良好 | 需改进 |
71
- |------|------|------|--------|
72
- | 总收益率 | >20% | 5-20% | <5% |
73
- | 最大回撤 | <10% | 10-20% | >20% |
74
- | 胜率 | >60% | 40-60% | <40% |
75
- | 盈亏比 | >2:1 | 1-2:1 | <1:1 |
76
- | 夏普比率 | >1.5 | 0.5-1.5 | <0.5 |
69
+ - 从 `metrics` 和 `trades` 计算期望值并与盈亏比一起报告。
70
+ - 报告最大回撤、连续亏损、交易次数和平均持有期;结果未携带初始风险时,将 1R 分布标为不可计算。
71
+ - 使用用户指定的互斥日期区间分别运行样本内和样本外回测。
72
+ - 只陈述策略配置或结果中可确认的手续费、滑点与成交约束,其余列入限制。
77
73
 
78
- ### 第四步:诊断与优化
74
+ 未模拟的结算、涨跌停、复权或特定市场费用列入限制,结论限定为该模拟条件下的历史表现。
79
75
 
80
- 根据回测结果诊断问题并提出变异方案:
76
+ ### 第四步:诊断
77
+
78
+ 根据回测结果诊断问题并提出可选调整。诊断提示只是待检验假设,不自动接受参数建议:
81
79
 
82
80
  **常见问题 → 优化方向**:
83
81
  - 胜率低 → 收紧入场条件、增加过滤因子
@@ -86,12 +84,15 @@ python3 scripts/gather.py --strategy <path.yaml> --symbol <symbol> --start <date
86
84
  - 交易次数少 → 放宽条件、缩短信号周期
87
85
  - 交易次数多 → 增加冷却期、提高信号门槛
88
86
 
89
- ### 第五步:进化迭代
87
+ ### 第五步:可选优化
88
+
89
+ 仅当用户明确要求优化时:
90
90
 
91
- 1. 根据诊断修改策略 YAML 参数
92
- 2. 重新运行回测
93
- 3. 对比前后结果
94
- 4. 重复直到满意
91
+ 1. 每轮只修改一类参数或条件
92
+ 2. 重新回测并与基线对比
93
+ 3. 按共享框架保留独立样本外区间
94
+ 4. 最多迭代 3 轮;期望值、回撤或样本量没有实质改善时停止
95
+ 5. 保留基线结果,并把样本内改善标记为待样本外验证
95
96
 
96
97
  ## 输出格式
97
98
 
@@ -105,9 +106,10 @@ python3 scripts/gather.py --strategy <path.yaml> --symbol <symbol> --start <date
105
106
  - 止损/止盈:...
106
107
 
107
108
  ### 核心指标
108
- | 指标 | 值 | 评级 |
109
+ | 指标 | 值 | 解释 |
109
110
  |------|----|------|
110
- | 总收益率 | ... | ⭐⭐⭐ |
111
+ | 总收益率 | ... | 相对基准与回测区间解释 |
112
+ | 期望值 | ... | 结合胜率、盈亏比和样本量解释 |
111
113
  | ... | ... | ... |
112
114
 
113
115
  ### 交易明细
@@ -122,6 +124,8 @@ python3 scripts/gather.py --strategy <path.yaml> --symbol <symbol> --start <date
122
124
  建议的参数调整方案
123
125
  ```
124
126
 
127
+ 完成标准:报告包含回测区间、样本内/外边界、初始资金、交易次数、持有期、期望值、收益/回撤指标、成本假设及未模拟的市场约束;优化分支还需提供基线对比。
128
+
125
129
  ## 示例策略
126
130
 
127
131
  参考 `{baseDir}/strategies/examples/` 目录中的示例:
@@ -11,7 +11,7 @@ for _s in (sys.stdout, sys.stderr):
11
11
  if hasattr(_s, "reconfigure"):
12
12
  _s.reconfigure(encoding="utf-8")
13
13
 
14
- tools = Path(__file__).resolve().parents[2] / "tools"
14
+ tools = Path(__file__).resolve().parents[3] / "tools"
15
15
  result = subprocess.run(
16
16
  [sys.executable, str(tools / "backtest.py"), "run"] + sys.argv[1:],
17
17
  capture_output=True,
@@ -1,16 +1,15 @@
1
1
  ---
2
2
  name: volume-breakout
3
- description: 放量突破策略 — 识别关键位置的放量突破行情。当用户要求分析突破形态时使用。
4
- allowed-tools: Bash(python3:*) Read
3
+ description: 放量突破分析:判断价格对前高、平台或其他阻力位的突破是否有效。低位异常放量用 bottom-volume。
5
4
  ---
6
5
 
7
6
  # 放量突破分析
8
7
 
9
- 你是一位专注突破形态的交易专家。
10
-
11
8
  ## 核心理念
12
9
 
13
- 真正的突破需要成交量的配合。放量突破关键阻力位(前高、平台、颈线、均线压制),意味着买方力量压倒卖方,是趋势加速或反转的信号。
10
+ 突破是价格离开原有平衡区后的待验证状态,不是单根阳线。成交量、收盘位置、相对强弱和后续接受共同决定它是延续还是失败。
11
+
12
+ 分析前读取[短线交易决策框架](../stock-analysis/references/short-term-trading.md),使用其中的市场状态、状态机和风险单位约束本流程。
14
13
 
15
14
  ## 执行流程
16
15
 
@@ -30,29 +29,28 @@ python3 scripts/gather.py <symbol>
30
29
  - **布林带上轨**:BOLL upper
31
30
  - **整数关口**:心理价位
32
31
 
33
- ### 3. 突破有效性判断
32
+ ### 3. 判断突破状态
33
+
34
+ 将共享状态机应用到突破场景:
34
35
 
35
- **有效突破条件**:
36
- - 收盘价突破阻力位(不仅是盘中触及)
37
- - 成交量至少放大到前 5 日均量的 2 倍(量比 ≥ 2)
38
- - 突破当日为中阳线或大阳线(涨幅 > 3%)
39
- - 突破后 2-3 日不回落至阻力位下方
36
+ - **Setup**:阻力位清晰,近期振幅或成交量相对自身基线收缩。
37
+ - **Trigger**:收盘越过阻力位,成交量和当日振幅相对近期基线扩张。
38
+ - **Acceptance**:后续收盘仍在突破位上方,回踩未放量跌破,个股相对板块和大盘未明显转弱。
39
+ - **Failure**:收盘重回原区间、放量反向运行,或板块退潮而个股失去相对强度。
40
40
 
41
- **假突破特征**:
42
- - 盘中突破但收盘回落(长上影线)
43
- - 突破时缩量
44
- - 突破后立即回落至阻力位下方
41
+ 量比、涨幅等固定数字只作为对应市场和周期的待回测参数。盘中触及但缺少收盘确认时,状态保持为 Setup。
45
42
 
46
- ### 4. 突破后操作
43
+ ### 4. 制定交易计划
47
44
 
48
- - **追涨买入**:突破当日或回踩确认后买入
49
- - **止损位**:阻力位下方 2%-3%(突破失败立即离场)
50
- - **目标位**:前一波下跌/盘整幅度的等幅上涨
45
+ - **触发**:事前选择收盘突破或回踩接受之一,并在报告中保持同一口径。
46
+ - **失效**:使用重新收回原区间或跌破回踩低点等能否定突破结构的位置。
47
+ - **时间止损**:以本次形态计划窗口评估后续接受;窗口结束仍无延续时退出或复核。
48
+ - **目标**:由下一阻力位或区间测量给出;潜在收益/R 达到策略要求时才形成交易计划。
51
49
 
52
50
  ## 输出要求
53
51
 
54
52
  1. 当前关键阻力位标注
55
- 2. 是否出现突破信号(或即将突破)
56
- 3. 突破有效性评级和依据
57
- 4. 买入区间、止损位、目标位
58
- 5. 假突破风险提示
53
+ 2. 当前处于 Setup、Trigger、Acceptance 或 Failure
54
+ 3. 成交量、收盘位置、市场状态和相对强弱证据
55
+ 4. 触发、失效、时间止损、目标位和潜在收益/R
56
+ 5. 数据缺口与不交易条件
@@ -11,7 +11,7 @@ for _s in (sys.stdout, sys.stderr):
11
11
  if hasattr(_s, "reconfigure"):
12
12
  _s.reconfigure(encoding="utf-8")
13
13
 
14
- tools = Path(__file__).resolve().parents[2] / "tools"
14
+ tools = Path(__file__).resolve().parents[3] / "tools"
15
15
  result = subprocess.run(
16
16
  [sys.executable, str(tools / "gather.py"), "technical", sys.argv[1], "--kline-count", "90"],
17
17
  capture_output=True,
@@ -1,13 +1,10 @@
1
1
  ---
2
2
  name: wave-theory
3
- description: 波浪理论分析 — 基于Elliott波浪理论的浪形识别和推演。当用户要求波浪分析时使用。
4
- allowed-tools: Bash(python3:*) Read
3
+ description: Elliott 波浪分析:在用户明确要求数浪时识别推动浪、调整浪、否定位和备选路径。
5
4
  ---
6
5
 
7
6
  # 波浪理论分析
8
7
 
9
- 你是一位精通 Elliott 波浪理论的交易专家。
10
-
11
8
  ## 核心理念
12
9
 
13
10
  市场走势遵循"5 浪推动 + 3 浪调整"的基本模式。通过识别当前所处的浪形位置,预判后续走势方向和幅度。
@@ -11,7 +11,7 @@ for _s in (sys.stdout, sys.stderr):
11
11
  if hasattr(_s, "reconfigure"):
12
12
  _s.reconfigure(encoding="utf-8")
13
13
 
14
- tools = Path(__file__).resolve().parents[2] / "tools"
14
+ tools = Path(__file__).resolve().parents[3] / "tools"
15
15
  result = subprocess.run(
16
16
  [sys.executable, str(tools / "gather.py"), "technical", sys.argv[1], "--kline-count", "120"],
17
17
  capture_output=True,
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: wisburg-research
3
- description: 智堡投研数据检索 — 投行研报、个股研究、财报公告、电话会纪要、市场日报、资讯流
3
+ description: 智堡投研检索:查找机构研报、财报公告、电话会纪要和市场日报。需要 Wisburg MCP;不可用时改用 search_comprehensive_intel。
4
4
  ---
5
5
 
6
6
  # 智堡(Wisburg)投研数据检索
7
7
 
8
- 你是一位投研分析助手,通过智堡 MCP 服务获取专业金融研究数据。智堡涵盖海外投行研报、国内券商研究、资管报告、央行/政府文献、电话会纪要、财报公告等。
8
+ 智堡 MCP 涵盖海外投行研报、国内券商研究、资管报告、央行/政府文献、电话会纪要和财报公告。首先检查这些 MCP 工具是否可用;不可用时直接改用 `search_comprehensive_intel`。
9
9
 
10
10
  ## 可用工具
11
11
 
package/tools/_subproc.py CHANGED
@@ -14,20 +14,33 @@ import sys
14
14
  TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
15
15
 
16
16
 
17
- def run_tool(script: str, args: list, timeout: int = 30):
17
+ def find_python() -> str:
18
+ """Prefer the repo .venv interpreter; fall back to the current one.
19
+
20
+ Windows venvs ship .venv/Scripts/python.exe (there is no python3);
21
+ POSIX venvs ship .venv/bin/python3 — same rule as hermes' _find_python.
22
+ """
23
+ parts = ("Scripts", "python.exe") if sys.platform == "win32" else ("bin", "python3")
24
+ venv = os.path.join(os.path.dirname(TOOLS_DIR), ".venv", *parts)
25
+ return venv if os.path.exists(venv) else sys.executable
26
+
27
+
28
+ def run_tool(script: str, args: list, timeout: int = 30, parse_json: bool = True):
18
29
  """Run tools/<script> with an argv list (never a shell). Returns parsed JSON
19
- stdout, or None on any failure (non-zero exit, empty/invalid output, timeout) —
20
- callers pick their own sentinel with `or {}` / `or []`."""
30
+ stdout (raw stripped stdout when parse_json=False), or None on any failure
31
+ (non-zero exit, empty/invalid output, timeout) — callers pick their own
32
+ sentinel with `or {}` / `or []`. Interpreter: find_python() (venv-first,
33
+ so child processes get the .venv deps)."""
21
34
  try:
22
35
  r = subprocess.run(
23
- [sys.executable, os.path.join(TOOLS_DIR, script), *args],
36
+ [find_python(), os.path.join(TOOLS_DIR, script), *args],
24
37
  capture_output=True,
25
38
  text=True,
26
39
  encoding="utf-8",
27
40
  timeout=timeout,
28
41
  )
29
42
  if r.returncode == 0 and r.stdout.strip():
30
- return json.loads(r.stdout)
43
+ return json.loads(r.stdout) if parse_json else r.stdout.strip()
31
44
  except Exception:
32
45
  pass
33
46
  return None
@@ -6,33 +6,14 @@ Does NOT store history, does NOT push, does NOT schedule. Host agent decides whe
6
6
 
7
7
  import argparse
8
8
  import json
9
- import subprocess
10
9
  import sys
11
10
  from datetime import datetime, timezone
12
11
  from pathlib import Path
13
12
 
14
13
  sys.path.insert(0, str(Path(__file__).resolve().parent))
14
+ from _subproc import run_tool as _run_json # noqa: E402
15
15
  from stock_data import detect_market # noqa: E402
16
16
 
17
- TOOLS_DIR = Path(__file__).resolve().parent
18
-
19
-
20
- def _find_python() -> str:
21
- venv = TOOLS_DIR.parent / ".venv" / "bin" / "python3"
22
- return str(venv) if venv.exists() else sys.executable
23
-
24
-
25
- def _run_json(script: str, args: list[str], timeout: int = 30):
26
- cmd = [_find_python(), str(TOOLS_DIR / script)] + args
27
- try:
28
- r = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", timeout=timeout)
29
- if r.returncode == 0 and r.stdout.strip():
30
- return json.loads(r.stdout)
31
- except Exception:
32
- pass
33
- return None
34
-
35
-
36
17
  RULE_TYPES = {
37
18
  "price_below",
38
19
  "price_above",
@@ -39,10 +39,9 @@ TOOL_MATRIX = {
39
39
  "get_market_stats": {"markets": ["A"], "reason": "A-share only"},
40
40
  "get_fundamental_context": {"markets": ["A"], "reason": "A-share only"},
41
41
  "resolve_stock_name": {"markets": ["A"], "reason": "A-share name/pinyin index only"},
42
- # US-leaning
43
42
  "get_social_sentiment": {
44
- "markets": ["US"],
45
- "reason": "sentiment providers are US-centric; requires SENTIMENT_API_KEY",
43
+ "markets": ["A", "HK", "US"],
44
+ "reason": "A-share uses Eastmoney/Xueqiu; HK/US require SENTIMENT_API_KEY",
46
45
  },
47
46
  "get_trending_sentiment": {
48
47
  "markets": ALL_MARKETS,
@@ -52,7 +51,7 @@ TOOL_MATRIX = {
52
51
  "search_stock_news": {"markets": ALL_MARKETS, "reason": None},
53
52
  "search_comprehensive_intel": {"markets": ALL_MARKETS, "reason": None},
54
53
  "extract_article": {"markets": ALL_MARKETS, "reason": None},
55
- "screen_risk": {"markets": ALL_MARKETS, "reason": None},
54
+ "screen_risk": {"markets": ["A"], "reason": "A-share only"},
56
55
  }
57
56
 
58
57
 
@@ -3,6 +3,8 @@
3
3
 
4
4
  Checks: (1) python package importable, (2) required env vars present.
5
5
  Does NOT hit the network — this is a cheap capability probe, not a health check.
6
+ `available` therefore means "package + credentials ready"; actual reachability
7
+ is reported as `reachable: null` (unknown) rather than guessed (issue #25).
6
8
  """
7
9
 
8
10
  import argparse
@@ -22,8 +24,16 @@ PROVIDERS = {
22
24
  "akshare": ("akshare", [], ["A"], None),
23
25
  "tushare": ("tushare", ["TUSHARE_TOKEN"], ["A"], None),
24
26
  "efinance": ("efinance", [], ["A"], None),
27
+ "tencent": ("requests", [], ["A"], "qt.gtimg.cn quote/kline, no auth (issue #25)"),
28
+ "sina": (
29
+ "requests",
30
+ [],
31
+ ["A"],
32
+ "hq.sinajs.cn quote + daily kline, no auth; full-market snapshot via akshare (issue #25)",
33
+ ),
25
34
  "xueqiu": ("akshare", ["XUEQIU_TOKEN"], ["A"], "industry board fallback via akshare"),
26
35
  "pytdx": ("pytdx", [], ["A"], "connects to public Tencent servers"),
36
+ "baostock": ("baostock", [], ["A"], None),
27
37
  "yfinance": ("yfinance", [], ["HK", "US", "JP", "KR", "TW"], "quote may be delayed 15-20min"),
28
38
  "finnhub": ("finnhub", ["FINNHUB_API_KEY"], ["HK", "US"], None),
29
39
  "longbridge": (
@@ -61,6 +71,7 @@ def _check_provider(name: str) -> dict:
61
71
  entry = {
62
72
  "name": name,
63
73
  "available": available,
74
+ "reachable": None, # not probed — available only means package + env ready
64
75
  "markets": markets,
65
76
  "reason": "; ".join(reasons) if reasons else None,
66
77
  }
@@ -92,10 +103,10 @@ def diagnose(market: str = "all") -> dict:
92
103
 
93
104
  warnings = []
94
105
  if not available:
95
- warnings.append(f"no working data source for {m}")
106
+ warnings.append(f"no configured data source for {m} (package/credentials not ready)")
96
107
  # market-specific caveats
97
108
  if m == "A" and not any(p["name"] == "tushare" and p["available"] for p in providers):
98
- warnings.append("TUSHARE_TOKEN not set — akshare-only, some deep data unavailable")
109
+ warnings.append("TUSHARE_TOKEN not set — Tushare unavailable; some deep A-share data may be limited")
99
110
  if (
100
111
  m in ("HK", "US")
101
112
  and not any(p["name"] == "longbridge" and p["available"] for p in providers)
package/tools/gather.py CHANGED
@@ -3,33 +3,19 @@
3
3
 
4
4
  import argparse
5
5
  import json
6
- import subprocess
7
6
  import sys
8
7
  from concurrent.futures import ThreadPoolExecutor, as_completed
9
8
  from pathlib import Path
10
9
 
11
- TOOLS_DIR = Path(__file__).resolve().parent
10
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
11
+ from _subproc import run_tool # noqa: E402
12
12
 
13
13
 
14
- def _find_python() -> str:
15
- venv = TOOLS_DIR.parent / ".venv" / "bin" / "python3"
16
- if venv.exists():
17
- return str(venv)
18
- return sys.executable
19
-
20
-
21
- def _run(script: str, args: list[str], timeout: int = 60) -> str | None:
22
- python = _find_python()
23
- cmd = [python, str(TOOLS_DIR / script)] + args
24
- try:
25
- r = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", timeout=timeout)
26
- if r.returncode == 0 and r.stdout.strip():
27
- return r.stdout.strip()
28
- except subprocess.TimeoutExpired:
29
- pass
30
- except Exception:
31
- pass
32
- return None
14
+ # gather fans out the heavier CLIs, so the default timeout stays 60s; JSON parsing
15
+ # is _parse_json's job, so raw stdout is wanted here. A def wrapper (not
16
+ # functools.partial) keeps timeout passable both positionally and by keyword.
17
+ def _run(script, args, timeout=60):
18
+ return run_tool(script, args, timeout=timeout, parse_json=False)
33
19
 
34
20
 
35
21
  def _parse_json(raw: str | None):
@@ -38,7 +38,10 @@ SKILL_RECOMMEND = {
38
38
 
39
39
  def _get_index_kline(market: str) -> list:
40
40
  code, _ = INDEX_MAP[market]
41
- data = _run_tool("stock_data.py", ["kline", code, "--period", "daily", "--count", "80"])
41
+ # A 股指数走显式交易所前缀(sh000001),避免与深市个股 000001(平安银行)撞代码
42
+ data = _run_tool(
43
+ "stock_data.py", ["kline", f"sh{code}" if market == "A" else code, "--period", "daily", "--count", "80"]
44
+ )
42
45
  if isinstance(data, list) and len(data) > 0:
43
46
  return data
44
47
  return []
@@ -6,32 +6,14 @@ Not a portfolio system. Stateless: user passes cost/quantity/stops each call.
6
6
 
7
7
  import argparse
8
8
  import json
9
- import subprocess
10
9
  import sys
11
10
  from datetime import datetime, timezone
12
11
  from pathlib import Path
13
12
 
14
13
  sys.path.insert(0, str(Path(__file__).resolve().parent))
14
+ from _subproc import run_tool as _run_json # noqa: E402
15
15
  from stock_data import detect_market # noqa: E402
16
16
 
17
- TOOLS_DIR = Path(__file__).resolve().parent
18
-
19
-
20
- def _find_python() -> str:
21
- venv = TOOLS_DIR.parent / ".venv" / "bin" / "python3"
22
- return str(venv) if venv.exists() else sys.executable
23
-
24
-
25
- def _run_json(script: str, args: list[str], timeout: int = 30):
26
- cmd = [_find_python(), str(TOOLS_DIR / script)] + args
27
- try:
28
- r = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", timeout=timeout)
29
- if r.returncode == 0 and r.stdout.strip():
30
- return json.loads(r.stdout)
31
- except Exception:
32
- pass
33
- return None
34
-
35
17
 
36
18
  def _risk_level(distance_to_stop_pct: float, pnl_pct: float, trend: str) -> str:
37
19
  # ponytail: simple 3-bucket heuristic, upgrade to volatility-adjusted if needed