openclaw-stock-analysis 0.2.2 → 0.2.6

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 (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -2
  3. package/dist/index.js +228 -30
  4. package/index.ts +246 -33
  5. package/openclaw.plugin.json +13 -1
  6. package/package.json +1 -1
  7. package/schemas/report_schema.json +3 -3
  8. package/scripts/ci-resolve-llm-host.mjs +29 -0
  9. package/scripts/setup-python.mjs +11 -13
  10. package/skills/bull-trend/SKILL.md +34 -10
  11. package/skills/bull-trend/references/fat-tails.md +91 -0
  12. package/skills/bull-trend/scripts/tail_analysis.py +132 -0
  13. package/skills/event-driven/SKILL.md +8 -0
  14. package/skills/growth-quality/SKILL.md +8 -0
  15. package/skills/hot-theme/SKILL.md +3 -2
  16. package/skills/stock-analysis/SKILL.md +31 -3
  17. package/skills/stock-screener/SKILL.md +21 -1
  18. package/skills/strategy-backtest/SKILL.md +15 -5
  19. package/skills/wisburg-research/SKILL.md +2 -0
  20. package/strategies/examples/bottom_volume.yaml +5 -0
  21. package/strategies/examples/box_oscillation.yaml +5 -0
  22. package/strategies/examples/bull_trend.yaml +11 -3
  23. package/strategies/examples/dragon_head.yaml +4 -2
  24. package/strategies/examples/emotion_cycle.yaml +5 -0
  25. package/strategies/examples/ma_crossover.yaml +10 -3
  26. package/strategies/examples/rsi_oversold.yaml +5 -0
  27. package/strategies/examples/shrink_pullback.yaml +7 -1
  28. package/strategies/examples/volume_breakout.yaml +7 -1
  29. package/templates/stock_analysis/brief.md.j2 +4 -1
  30. package/templates/stock_analysis/full.md.j2 +6 -3
  31. package/tools/_cache.py +61 -0
  32. package/tools/_subproc.py +49 -0
  33. package/tools/alert_rules.py +51 -13
  34. package/tools/anomaly_detect.py +24 -35
  35. package/tools/backtest.py +202 -104
  36. package/tools/capabilities.py +16 -5
  37. package/tools/diagnostics.py +12 -6
  38. package/tools/gather.py +33 -19
  39. package/tools/import_parser.py +2 -5
  40. package/tools/lixinger.py +100 -0
  41. package/tools/market_regime.py +34 -38
  42. package/tools/market_review.py +57 -9
  43. package/tools/name_resolver.py +2 -5
  44. package/tools/pattern.py +2 -5
  45. package/tools/position_context.py +22 -7
  46. package/tools/report_renderer.py +12 -6
  47. package/tools/requirements.txt +2 -1
  48. package/tools/risk_screening.py +73 -39
  49. package/tools/screener.py +90 -20
  50. package/tools/search_intel.py +5 -13
  51. package/tools/sec_edgar.py +346 -0
  52. package/tools/sec_holders.py +263 -0
  53. package/tools/signal_tracker.py +144 -25
  54. package/tools/stock_data.py +600 -186
  55. package/tools/technical.py +152 -42
  56. package/tools/trading_calendar.py +78 -18
  57. package/tools/value_data.py +1527 -0
  58. package/tools/volume_analysis.py +2 -5
  59. package/tools/watchlist.py +26 -6
  60. package/tools/watchlist_context.py +9 -8
@@ -10,6 +10,7 @@ import numpy as np
10
10
 
11
11
  sys.path.insert(0, str(Path(__file__).resolve().parent))
12
12
 
13
+ from _subproc import utf8_stdio # noqa: E402
13
14
  from technical import fetch_kline, to_dataframe # noqa: E402
14
15
 
15
16
 
@@ -150,9 +151,5 @@ def main():
150
151
 
151
152
 
152
153
  if __name__ == "__main__":
153
- # Windows defaults stdio to a legacy code page (cp1252) that cannot encode the
154
- # Chinese text these tools emit — force UTF-8 so stdout never crashes there.
155
- for _s in (sys.stdout, sys.stderr):
156
- if hasattr(_s, "reconfigure"):
157
- _s.reconfigure(encoding="utf-8")
154
+ utf8_stdio()
158
155
  main()
@@ -3,15 +3,34 @@
3
3
 
4
4
  import argparse
5
5
  import json
6
+ import math
6
7
  import sys
7
8
  from concurrent.futures import ThreadPoolExecutor, as_completed
8
9
  from pathlib import Path
9
10
 
10
11
  sys.path.insert(0, str(Path(__file__).resolve().parent))
12
+ from _subproc import utf8_stdio
11
13
  from gather import gather_analysis
12
14
 
13
15
 
16
+ def has_analysis_data(data) -> bool:
17
+ if not isinstance(data, dict):
18
+ return False
19
+ for key, field in (("quote", "price"), ("kline", "close"), ("technical", "signal_score")):
20
+ payload = data.get(key)
21
+ rows = payload if isinstance(payload, list) else [payload]
22
+ for row in rows:
23
+ if not isinstance(row, dict) or "error" in row:
24
+ continue
25
+ value = row.get(field)
26
+ if isinstance(value, (int, float)) and math.isfinite(value) and (key == "technical" or value > 0):
27
+ return True
28
+ return False
29
+
30
+
14
31
  def analyze_watchlist(symbols: list[str], workers: int = 3) -> dict:
32
+ if isinstance(workers, bool) or not isinstance(workers, int) or workers <= 0:
33
+ return {"error": "workers must be a positive integer"}
15
34
  results = {}
16
35
  success = 0
17
36
  failed = 0
@@ -23,7 +42,10 @@ def analyze_watchlist(symbols: list[str], workers: int = 3) -> dict:
23
42
  try:
24
43
  data = future.result()
25
44
  results[sym] = data
26
- success += 1
45
+ if has_analysis_data(data):
46
+ success += 1
47
+ else:
48
+ failed += 1
27
49
  except Exception:
28
50
  results[sym] = None
29
51
  failed += 1
@@ -52,15 +74,13 @@ def main():
52
74
  result = analyze_watchlist(codes, workers=args.workers)
53
75
  json.dump(result, sys.stdout, ensure_ascii=False, indent=2)
54
76
  print()
77
+ if "error" in result:
78
+ sys.exit(1)
55
79
  else:
56
80
  parser.print_help()
57
81
  sys.exit(1)
58
82
 
59
83
 
60
84
  if __name__ == "__main__":
61
- # Windows defaults stdio to a legacy code page (cp1252) that cannot encode the
62
- # Chinese text these tools emit — force UTF-8 so stdout never crashes there.
63
- for _s in (sys.stdout, sys.stderr):
64
- if hasattr(_s, "reconfigure"):
65
- _s.reconfigure(encoding="utf-8")
85
+ utf8_stdio()
66
86
  main()
@@ -14,8 +14,9 @@ from pathlib import Path
14
14
 
15
15
  sys.path.insert(0, str(Path(__file__).resolve().parent))
16
16
  from _subproc import run_tool as _run_json # noqa: E402
17
+ from _subproc import utf8_stdio
17
18
  from stock_data import detect_market # noqa: E402
18
- from watchlist import analyze_watchlist # noqa: E402
19
+ from watchlist import analyze_watchlist, has_analysis_data # noqa: E402
19
20
 
20
21
 
21
22
  def _suggest_next_tools(market: str, trend: str, anomalies: list, risk_level: str) -> list:
@@ -38,7 +39,7 @@ def _suggest_next_tools(market: str, trend: str, anomalies: list, risk_level: st
38
39
 
39
40
 
40
41
  def _build_item(symbol: str, data: dict | None) -> dict:
41
- if not data:
42
+ if not has_analysis_data(data):
42
43
  return {"symbol": symbol, "error": "no data"}
43
44
 
44
45
  tech = data.get("technical") or {}
@@ -51,7 +52,7 @@ def _build_item(symbol: str, data: dict | None) -> dict:
51
52
  score = tech.get("signal_score")
52
53
  trend = (tech.get("trend") or {}).get("overall") or "unknown"
53
54
  risk_level = risk.get("risk_level", "unknown")
54
- veto = bool(risk.get("veto_buy", False))
55
+ veto = risk.get("veto_buy")
55
56
  buy_signal = tech.get("buy_signal")
56
57
  market = detect_market(symbol)
57
58
 
@@ -78,6 +79,8 @@ def _build_item(symbol: str, data: dict | None) -> dict:
78
79
 
79
80
  def build_context(symbols: list[str], include_market_review: bool = False, workers: int = 3) -> dict:
80
81
  raw = analyze_watchlist(symbols, workers=workers)
82
+ if "error" in raw:
83
+ return raw
81
84
  results = raw.get("results", {})
82
85
 
83
86
  items = []
@@ -147,12 +150,10 @@ def main():
147
150
  result = build_context(codes, include_market_review=args.include_market_review, workers=args.workers)
148
151
  json.dump(result, sys.stdout, ensure_ascii=False, indent=2, default=str)
149
152
  print()
153
+ if "error" in result:
154
+ sys.exit(1)
150
155
 
151
156
 
152
157
  if __name__ == "__main__":
153
- # Windows defaults stdio to a legacy code page (cp1252) that cannot encode the
154
- # Chinese text these tools emit — force UTF-8 so stdout never crashes there.
155
- for _s in (sys.stdout, sys.stderr):
156
- if hasattr(_s, "reconfigure"):
157
- _s.reconfigure(encoding="utf-8")
158
+ utf8_stdio()
158
159
  main()