dsh-stock-analysis 0.1.15 → 0.2.1

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Stock Analysis — DeepSeek Harness (dsh) Plugin
2
2
 
3
- A股 / 港股 / 美股 / 日股 / 韩股 / 台股 行情、技术分析、筛选与回测。作为 dsh bundle 安装到 profile 后,对话中可调用 41 个工具,并自动注册 20 个工作流/策略方法论 skill。
3
+ A股 / 港股 / 美股 / 日股 / 韩股 / 台股 行情、技术分析、筛选与回测。作为 dsh bundle 安装到 profile 后,对话中可调用 48 个工具,并自动注册 20 个工作流/策略方法论 skill。
4
4
 
5
5
  ## 安装
6
6
 
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ function __setExecutor(fn) {
26
26
  executor = fn;
27
27
  }
28
28
  var here = dirname(fileURLToPath(import.meta.url));
29
- var toolsDir = existsSync(join2(here, "tools")) ? join2(here, "tools") : join2(here, "..", "tools");
29
+ var toolsDir = join2(here, "..", "tools");
30
30
  var pkgRoot = dirname(toolsDir);
31
31
  var isWin2 = process.platform === "win32";
32
32
  function pythonBin() {
@@ -53,7 +53,7 @@ function pyTool(opts) {
53
53
  }
54
54
  });
55
55
  }
56
- var skillsDir = existsSync(join2(here, "skills")) ? join2(here, "skills") : join2(here, "..", "skills");
56
+ var skillsDir = join2(here, "..", "skills");
57
57
  function frontmatterValue(raw, key) {
58
58
  const block = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
59
59
  const line = block?.[1].match(new RegExp(`^${key}:\\s*(.+)$`, "m"));
@@ -112,7 +112,7 @@ function apply(ctx) {
112
112
  ctx.tools.register(
113
113
  pyTool({
114
114
  name: "get_quote",
115
- description: "\u83B7\u53D6\u80A1\u7968\u5B9E\u65F6\u884C\u60C5\u62A5\u4EF7\uFF08\u73B0\u4EF7\u3001\u6DA8\u8DCC\u5E45\u3001\u91CF\u6BD4\u7B49\uFF09\u3002\u652F\u6301A\u80A1\u3001\u6E2F\u80A1\u3001\u7F8E\u80A1\u3001\u65E5\u80A1\u3001\u97E9\u80A1\u3001\u53F0\u80A1",
115
+ description: "\u83B7\u53D6\u80A1\u7968\u5B9E\u65F6\u884C\u60C5\u62A5\u4EF7\uFF08\u73B0\u4EF7\u3001\u6DA8\u8DCC\u5E45\u3001\u91CF\u6BD4\u7B49\uFF09\u3002\u652F\u6301A\u80A1\u3001\u6E2F\u80A1\u3001\u7F8E\u80A1\u3001\u65E5\u80A1\u3001\u97E9\u80A1\u3001\u53F0\u80A1\uFF1B\u975E\u4EA4\u6613\u65F6\u6BB5\u8FD4\u56DE\u6700\u8FD1\u4EA4\u6613\u65E5\u6536\u76D8\u4EF7\u5E76\u4EE5 as_of/stale \u6807\u6CE8",
116
116
  parameters: {
117
117
  symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" }
118
118
  },
@@ -233,13 +233,18 @@ function apply(ctx) {
233
233
  ctx.tools.register(
234
234
  pyTool({
235
235
  name: "get_sector_rankings",
236
- description: "\u83B7\u53D6A\u80A1\u884C\u4E1A\u677F\u5757\u6DA8\u8DCC\u5E45\u6392\u884C\uFF08\u542B\u9886\u6DA8\u80A1\u3001\u6DA8\u8DCC\u5BB6\u6570\u7B49\uFF09\u3002\u652F\u6301\u67E5\u770B\u6DA8\u5E45\u699C/\u8DCC\u5E45\u699C/\u53CC\u5411",
236
+ description: "\u83B7\u53D6A\u80A1\u677F\u5757\u6DA8\u8DCC\u5E45\u6392\u884C\uFF08\u542B\u9886\u6DA8\u80A1\u3001\u6DA8\u8DCC\u5BB6\u6570\u7B49\uFF09\u3002board_type=industry\uFF08\u9ED8\u8BA4\uFF09\u4E3A\u884C\u4E1A\u677F\u5757\uFF0Cboard_type=concept \u65F6\u4E3A\u6982\u5FF5\u677F\u5757\u6392\u884C\u3002\u652F\u6301\u67E5\u770B\u6DA8\u5E45\u699C/\u8DCC\u5E45\u699C/\u53CC\u5411",
237
237
  parameters: {
238
238
  top: { type: "number", description: "\u8FD4\u56DE\u6392\u540D\u524DN\u7684\u677F\u5757\uFF0C\u9ED8\u8BA4 10" },
239
239
  direction: {
240
240
  type: "string",
241
241
  enum: ["top", "bottom", "both"],
242
242
  description: "top=\u6DA8\u5E45\u699C\uFF08\u9ED8\u8BA4\uFF09\uFF0Cbottom=\u8DCC\u5E45\u699C\uFF0Cboth=\u53CC\u5411"
243
+ },
244
+ board_type: {
245
+ type: "string",
246
+ enum: ["industry", "concept"],
247
+ description: "\u677F\u5757\u7C7B\u578B\uFF1Aindustry=\u884C\u4E1A\uFF08\u9ED8\u8BA4\uFF09\uFF0Cconcept=\u6982\u5FF5"
243
248
  }
244
249
  },
245
250
  script: "stock_data.py",
@@ -248,7 +253,9 @@ function apply(ctx) {
248
253
  "--top",
249
254
  String(p.top ?? 10),
250
255
  "--direction",
251
- p.direction ?? "top"
256
+ p.direction ?? "top",
257
+ "--board-type",
258
+ p.board_type ?? "industry"
252
259
  ]
253
260
  })
254
261
  );
@@ -322,15 +329,54 @@ function apply(ctx) {
322
329
  pyTool({
323
330
  name: "get_market_stats",
324
331
  description: "\u83B7\u53D6A\u80A1\u5E02\u573A\u6574\u4F53\u7EDF\u8BA1\uFF08\u6DA8\u8DCC\u5BB6\u6570\u3001\u6DA8\u505C\u8DCC\u505C\u6570\u3001\u5E73\u5747\u6DA8\u5E45\u3001\u6DA8\u8DCCTop5\u3001\u603B\u6210\u4EA4\u989D\uFF09\u3002\u7528\u4E8E\u8861\u91CF\u5E02\u573A\u6574\u4F53\u60C5\u7EEA\u4E0E\u6E29\u5EA6",
332
+ parameters: {},
333
+ script: "stock_data.py",
334
+ argv: () => ["market_stats"]
335
+ })
336
+ );
337
+ ctx.tools.register(
338
+ pyTool({
339
+ name: "get_limit_up_pool",
340
+ description: "\u83B7\u53D6A\u80A1\u6DA8\u505C\u6C60/\u6DA8\u505C\u677F\u590D\u76D8\u2014\u2014\u5F53\u65E5\u6DA8\u505C\u4E2A\u80A1\uFF0C\u542B\u8FDE\u677F\u6570\u3001\u5C01\u677F\u8D44\u91D1\u3001\u70B8\u677F\u6B21\u6570\u3001\u9996\u672B\u6B21\u5C01\u677F\u65F6\u95F4\u3001\u6240\u5C5E\u884C\u4E1A\u3002\u77ED\u7EBF\u60C5\u7EEA\u4E0E\u9F99\u5934\u6218\u6CD5\u6838\u5FC3\u6570\u636E",
325
341
  parameters: {
326
- market: {
327
- type: "string",
328
- enum: ["A"],
329
- description: "\u5E02\u573A\uFF0C\u76EE\u524D\u4EC5\u652F\u6301 A"
330
- }
342
+ date: { type: "string", description: "\u65E5\u671F\uFF08YYYYMMDD\uFF09\uFF0C\u9ED8\u8BA4\u5F53\u65E5\uFF1B\u975E\u4EA4\u6613\u65E5\u6216\u672A\u6765\u65E5\u671F\u81EA\u52A8\u56DE\u9000\u5230\u6700\u8FD1\u4EA4\u6613\u65E5\uFF08\u8FD4\u56DE\u542B requested_date \u4E0E stale \u6807\u6CE8\uFF09" }
343
+ },
344
+ script: "stock_data.py",
345
+ argv: (p) => {
346
+ const args = ["limit_up_pool"];
347
+ if (p.date) args.push("--date", p.date);
348
+ return args;
349
+ }
350
+ })
351
+ );
352
+ ctx.tools.register(
353
+ pyTool({
354
+ name: "get_dragon_tiger",
355
+ description: "\u83B7\u53D6A\u80A1\u9F99\u864E\u699C\u2014\u2014\u4E0A\u699C\u4E2A\u80A1\u51C0\u4E70\u989D/\u4E70\u5165\u989D/\u5356\u51FA\u989D/\u4E0A\u699C\u539F\u56E0/\u89E3\u8BFB\uFF0C\u53EF\u6309\u4E2A\u80A1\u8FC7\u6EE4",
356
+ parameters: {
357
+ date: { type: "string", description: "\u65E5\u671F\uFF08YYYY-MM-DD\uFF09\uFF0C\u9ED8\u8BA4\u5F53\u65E5\uFF1B\u975E\u4EA4\u6613\u65E5\u6216\u672A\u6765\u65E5\u671F\u81EA\u52A8\u56DE\u9000\u5230\u6700\u8FD1\u4EA4\u6613\u65E5\uFF08\u8FD4\u56DE\u542B requested_date \u4E0E stale \u6807\u6CE8\uFF09" },
358
+ symbol: { type: "string", description: "A\u80A1\u80A1\u7968\u4EE3\u7801\uFF08\u53EF\u9009\uFF0C\u6309\u4E2A\u80A1\u8FC7\u6EE4\uFF09\uFF0C\u5982 600519" },
359
+ top: { type: "number", description: "\u8FD4\u56DE\u524DN\u6761\uFF0C\u9ED8\u8BA4 20" }
360
+ },
361
+ script: "stock_data.py",
362
+ argv: (p) => {
363
+ const args = ["dragon_tiger"];
364
+ if (p.date) args.push("--date", p.date);
365
+ if (p.symbol) args.push("--symbol", p.symbol);
366
+ args.push("--top", String(p.top ?? 20));
367
+ return args;
368
+ }
369
+ })
370
+ );
371
+ ctx.tools.register(
372
+ pyTool({
373
+ name: "get_hot_stocks",
374
+ description: "\u83B7\u53D6A\u80A1\u5168\u5E02\u573A\u4EBA\u6C14\u70ED\u641C\u699C\uFF08\u4E1C\u65B9\u8D22\u5BCC\u4EBA\u6C14\u699C\uFF09",
375
+ parameters: {
376
+ top: { type: "number", description: "\u8FD4\u56DE\u524DN\u53EA\uFF0C\u9ED8\u8BA4 20" }
331
377
  },
332
378
  script: "stock_data.py",
333
- argv: (p) => ["market_stats", "--market", p.market ?? "A"]
379
+ argv: (p) => ["hot_stocks", "--top", String(p.top ?? 20)]
334
380
  })
335
381
  );
336
382
  ctx.tools.register(
@@ -496,6 +542,22 @@ function apply(ctx) {
496
542
  }
497
543
  })
498
544
  );
545
+ ctx.tools.register(
546
+ pyTool({
547
+ name: "get_trading_phase",
548
+ description: "\u67E5\u8BE2\u67D0\u5E02\u573A\u5F53\u524D\u4EA4\u6613\u65F6\u6BB5\uFF08\u76D8\u524D/\u65E9\u76D8/\u5348\u95F4\u4F11\u5E02/\u5348\u76D8/\u4EA4\u6613\u4E2D/\u76D8\u540E/\u4F11\u5E02\uFF09\uFF0C\u7528\u4E8E\u6B63\u786E\u89E3\u8BFB\u5B9E\u65F6\u884C\u60C5\u7684\u76D8\u4E2D\u8BED\u4E49\u3002\u652F\u6301CN/HK/US/JP/KR/TW",
549
+ parameters: {
550
+ market: {
551
+ type: "string",
552
+ required: true,
553
+ enum: ["CN", "HK", "US", "JP", "KR", "TW"],
554
+ description: "\u5E02\u573A"
555
+ }
556
+ },
557
+ script: "trading_calendar.py",
558
+ argv: (p) => ["phase", p.market]
559
+ })
560
+ );
499
561
  ctx.tools.register(
500
562
  pyTool({
501
563
  name: "calculate_ma",
@@ -591,7 +653,7 @@ function apply(ctx) {
591
653
  ctx.tools.register(
592
654
  pyTool({
593
655
  name: "get_trending_sentiment",
594
- description: "\u83B7\u53D6\u793E\u4EA4\u5A92\u4F53\u70ED\u95E8\u8D8B\u52BF\uFF08Reddit/X/Polymarket\u70ED\u95E8\u80A1\u7968\u8BA8\u8BBA\uFF09\u3002\u6570\u636E\u7F13\u5B5810\u5206\u949F\u3002\u9002\u7528\u4E8E\u53D1\u73B0\u5E02\u573A\u70ED\u70B9\uFF1B\u67E5\u4E2A\u80A1\u60C5\u7EEA\u7528 get_social_sentiment",
656
+ description: "\u83B7\u53D6\u793E\u4EA4\u5A92\u4F53\u70ED\u95E8\u8D8B\u52BF\uFF08Reddit/X/Polymarket\u70ED\u95E8\u80A1\u7968\u8BA8\u8BBA\uFF09\u3002\u9002\u7528\u4E8E\u53D1\u73B0\u5E02\u573A\u70ED\u70B9\uFF1B\u67E5\u4E2A\u80A1\u60C5\u7EEA\u7528 get_social_sentiment",
595
657
  parameters: {},
596
658
  script: "search_intel.py",
597
659
  argv: () => ["trending"]
@@ -757,17 +819,12 @@ function apply(ctx) {
757
819
  additionalProperties: true,
758
820
  required: true,
759
821
  description: "\u7ED3\u6784\u5316\u5E02\u573A\u590D\u76D8"
760
- },
761
- template: {
762
- type: "string",
763
- enum: ["full"],
764
- description: "\u6A21\u677F\u7C7B\u578B\uFF0C\u9ED8\u8BA4 full"
765
822
  }
766
823
  },
767
824
  script: "report_renderer.py",
768
825
  argv: (p) => {
769
826
  const b64 = Buffer.from(JSON.stringify(p.report), "utf-8").toString("base64");
770
- return ["market", "--template", p.template ?? "full", "--input-b64", b64];
827
+ return ["market", "--input-b64", b64];
771
828
  }
772
829
  })
773
830
  );
@@ -838,6 +895,82 @@ function apply(ctx) {
838
895
  }
839
896
  })
840
897
  );
898
+ ctx.tools.register(
899
+ pyTool({
900
+ name: "record_signal",
901
+ description: "\u8BB0\u5F55\u4E00\u6761 AI \u5206\u6790\u5EFA\u8BAE\u4FE1\u53F7\uFF08\u65B9\u5411/\u5165\u573A\u4EF7/\u76EE\u6807\u4EF7/\u6B62\u635F\u4EF7/\u6301\u6709\u671F\u9650\uFF09\uFF0C\u4F9B\u540E\u7EED\u80DC\u7387\u8BC4\u4F30\u3002\u4FE1\u53F7\u6301\u4E45\u5316\u5728\u672C\u5730 JSONL\uFF08$STOCK_SIGNAL_STORE \u6216 ~/.stock-analysis/signals.jsonl\uFF09\uFF0C\u5BBF\u4E3B Agent \u81EA\u884C\u51B3\u5B9A\u4F55\u65F6 record/evaluate",
902
+ parameters: {
903
+ symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" },
904
+ direction: {
905
+ type: "string",
906
+ required: true,
907
+ enum: ["buy", "sell"],
908
+ description: "\u5EFA\u8BAE\u65B9\u5411"
909
+ },
910
+ entry_price: { type: "number", description: "\u5165\u573A\u4EF7\uFF08\u53EF\u9009\uFF09" },
911
+ target_price: { type: "number", description: "\u76EE\u6807\u4EF7\uFF08\u53EF\u9009\uFF09" },
912
+ stop_price: { type: "number", description: "\u6B62\u635F\u4EF7\uFF08\u53EF\u9009\uFF09" },
913
+ horizon_days: { type: "number", description: "\u6301\u6709\u671F\u9650\uFF08\u4EA4\u6613\u65E5\uFF09\uFF0C\u9ED8\u8BA4 10" },
914
+ source: { type: "string", description: "\u4FE1\u53F7\u6765\u6E90\uFF08\u5982\u89E6\u53D1\u8BE5\u5EFA\u8BAE\u7684 skill \u540D\uFF09" },
915
+ note: { type: "string", description: "\u5907\u6CE8\uFF08\u53EF\u9009\uFF09" }
916
+ },
917
+ script: "signal_tracker.py",
918
+ argv: (p) => {
919
+ const args = [
920
+ "record",
921
+ p.symbol,
922
+ "--direction",
923
+ p.direction,
924
+ "--horizon-days",
925
+ String(p.horizon_days ?? 10)
926
+ ];
927
+ if (p.entry_price !== void 0) args.push("--entry-price", String(p.entry_price));
928
+ if (p.target_price !== void 0) args.push("--target-price", String(p.target_price));
929
+ if (p.stop_price !== void 0) args.push("--stop-price", String(p.stop_price));
930
+ if (p.source) args.push("--source", p.source);
931
+ if (p.note) args.push("--note", p.note);
932
+ return args;
933
+ }
934
+ })
935
+ );
936
+ ctx.tools.register(
937
+ pyTool({
938
+ name: "evaluate_signals",
939
+ description: "\u8BC4\u4F30\u5230\u671F\u4FE1\u53F7\uFF1A\u62C9\u53D6\u8BB0\u5F55\u65E5\u4E4B\u540E\u7684\u65E5K\uFF0C\u5224\u5B9A target_hit/stop_hit/timeout \u5E76\u8BA1\u7B97\u6536\u76CA\uFF0C\u56DE\u5199\u5B58\u50A8\u3002\u8BB0\u5F55\u5EFA\u8BAE\u7528 record_signal\uFF0C\u80DC\u7387\u590D\u76D8\u7528 get_signal_summary",
940
+ parameters: {
941
+ symbol: { type: "string", description: "\u80A1\u7968\u4EE3\u7801\uFF08\u53EF\u9009\uFF0C\u53EA\u8BC4\u4F30\u8BE5\u80A1\u7684\u4FE1\u53F7\uFF09" }
942
+ },
943
+ script: "signal_tracker.py",
944
+ argv: (p) => {
945
+ const args = ["evaluate"];
946
+ if (p.symbol) args.push("--symbol", p.symbol);
947
+ return args;
948
+ }
949
+ })
950
+ );
951
+ ctx.tools.register(
952
+ pyTool({
953
+ name: "get_signal_summary",
954
+ description: "\u4FE1\u53F7\u80DC\u7387\u6C47\u603B\uFF08\u53EF\u6309 source/symbol/status \u8FC7\u6EE4\uFF09\uFF1A\u80DC\u7387\u3001\u5E73\u5747\u6536\u76CA\u3001\u7ED3\u679C\u5206\u5E03\u4E0E\u660E\u7EC6",
955
+ parameters: {
956
+ source: { type: "string", description: "\u6309\u4FE1\u53F7\u6765\u6E90\u8FC7\u6EE4\uFF08\u53EF\u9009\uFF09" },
957
+ symbol: { type: "string", description: "\u6309\u80A1\u7968\u4EE3\u7801\u8FC7\u6EE4\uFF08\u53EF\u9009\uFF09" },
958
+ status: {
959
+ type: "string",
960
+ enum: ["open", "closed", "all"],
961
+ description: "open=\u672A\u7ED3\u7B97\uFF0Cclosed=\u5DF2\u7ED3\u7B97\uFF0Call=\u5168\u90E8\uFF08\u9ED8\u8BA4\uFF09"
962
+ }
963
+ },
964
+ script: "signal_tracker.py",
965
+ argv: (p) => {
966
+ const args = ["summary"];
967
+ if (p.source) args.push("--source", p.source);
968
+ if (p.symbol) args.push("--symbol", p.symbol);
969
+ args.push("--status", p.status ?? "all");
970
+ return args;
971
+ }
972
+ })
973
+ );
841
974
  ctx.tools.register(
842
975
  pyTool({
843
976
  name: "parse_stock_list",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-stock-analysis",
3
- "version": "0.1.15",
3
+ "version": "0.2.1",
4
4
  "description": "DeepSeek Harness (dsh) plugin for stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,6 +24,8 @@ python3 scripts/gather.py <symbol>
24
24
  同时用 resolve_stock_sectors 确认个股所属板块,再用 get_sector_constituents 拉取同板块个股列表——后续「龙头 vs 跟风」的强弱对比都在这个板块池内进行。
25
25
  获取不到板块池或池内个股同期表现时,只评估候选股的强势特征,不给出“龙头/龙一”结论。
26
26
 
27
+ 短线情绪与资金席位补充:`get_limit_up_pool`(涨停池的连板数、首末次封板时间、封板资金、炸板次数)用于确认板块内个股的高度与封板质量;`get_dragon_tiger`(龙虎榜)用于查看上榜个股的席位净买额与上榜原因。两者在非交易日或未来日期会自动回退到最近交易日的数据(返回含 `requested_date` 与 `stale: true` 标注),解读时以 `date` 字段的实际数据日期为准,不得把回退数据当成请求日当日数据。
28
+
27
29
  ### 2. 相对强弱验证
28
30
 
29
31
  在同一截止时间比较板块候选股:
@@ -33,7 +35,7 @@ python3 scripts/gather.py <symbol>
33
35
  - 上涨日与下跌日的成交量结构
34
36
  - 板块上涨时是否领涨,板块分歧时是否保持相对强度
35
37
 
36
- 封单大小、开板次数、竞价强弱和分时承接需要盘口或分钟数据。当前数据无法验证时明确标注缺失,不得据此评定龙头。
38
+ 连板数、封板资金、炸板次数和首末次封板时间用 `get_limit_up_pool` 获取;竞价强弱和分时承接仍需盘口或分钟数据。当前数据无法验证时明确标注缺失,不得据此评定龙头。
37
39
 
38
40
  ### 3. 判断阶段与计划
39
41
 
@@ -17,6 +17,8 @@ description: 市场情绪周期:用市场宽度、涨跌停、成交额和热
17
17
  python3 scripts/gather.py [A|HK|US]
18
18
  ```
19
19
 
20
+ A 股情绪另有两个直接数据源:`get_limit_up_pool`(涨停池:连板梯队高度、炸板率、封板资金)与 `get_hot_stocks`(全市场人气热搜榜)。`get_limit_up_pool` 在非交易日或未来日期会回退到最近交易日数据(返回含 `requested_date` 与 `stale: true`),情绪判断以其 `date` 字段的实际数据日期为准。
21
+
20
22
  ### 2. 情绪指标
21
23
 
22
24
  - 市场温度和策略姿态
@@ -20,7 +20,8 @@ gather 工具返回:
20
20
  - `financials` — 基本面数据(实质受益判断)
21
21
  - `news` — 近期新闻(题材催化来源)
22
22
  - `stock_info` — 公司基本信息(行业、业务)
23
- - `sector_rankings` — 板块排名(核心数据源)
23
+ - `sector_rankings` — 板块排名(核心数据源);`get_sector_rankings` 传 `board_type=concept` 时为概念板块排行,热点题材以概念口径为主
24
+ - `hot_stocks` — 全市场人气热搜榜(`get_hot_stocks`,东方财富人气榜),辅助判断题材热度
24
25
 
25
26
  评估扩散度前,必须获取板块成分股及其当日表现;只有板块排名时,仅可判断当日相对强弱,不判断扩散度或持续性。
26
27
 
@@ -30,6 +30,8 @@ python3 scripts/gather.py <symbol>
30
30
 
31
31
  解析返回的 JSON 数据。如果某个字段为 `null`,表示该数据获取失败,基于可用数据继续分析。
32
32
 
33
+ 解读实时行情前先调 `get_trading_phase` 确认该市场当前盘中阶段(盘前/早盘/午间休市/午盘/交易中/盘后/休市),避免把休市时的静态快照当作盘中信号解读。
34
+
33
35
  ### 第二步:综合研判
34
36
 
35
37
  根据获取的数据进行多维度分析:
@@ -63,11 +65,17 @@ python3 scripts/gather.py <symbol>
63
65
 
64
66
  ### 第三步:渲染研报
65
67
 
66
- 1. 按 [报告 schema](references/report_schema.json) 构建结构化报告。
68
+ 1. 按 [报告 schema](../../schemas/report_schema.json) 构建结构化报告。
67
69
  2. 每个结论只使用成功返回的数据;缺失维度在 `risk_warning` 中说明影响。
68
70
  3. 调用 `render_stock_report`:快速问答用 `brief`,完整研判用 `full`。
69
71
  4. 输出渲染后的 Markdown;只在用户要求机器可读数据时附加结构化 JSON。
70
72
 
73
+ ## 信号跟踪闭环
74
+
75
+ - 给出明确买卖建议(方向 + 入场价/目标价/止损价)时,调 `record_signal` 存档,`source` 填触发该建议的 skill 名(如 `stock-analysis`、`dragon-head`)。
76
+ - 后续会话用 `evaluate_signals` 结算到期信号(target_hit/stop_hit/timeout 并回写收益),用 `get_signal_summary` 复盘胜率(可按 source/symbol/status 过滤)。
77
+ - 信号持久化在本地 JSONL(`$STOCK_SIGNAL_STORE` 或 `~/.stock-analysis/signals.jsonl`);是否记录由宿主 Agent 决定,不阻塞报告输出。
78
+
71
79
  ## 注意事项
72
80
  - 始终提供风险提示
73
81
  - 不做绝对化的涨跌预测
@@ -26,19 +26,6 @@ RULE_TYPES = {
26
26
  }
27
27
 
28
28
 
29
- def _severity_for(rule_type: str) -> str:
30
- return {
31
- "risk_veto": "high",
32
- "risk_level_at_least": "high",
33
- "anomaly": "medium",
34
- "price_below": "medium",
35
- "price_above": "medium",
36
- "change_pct_above": "medium",
37
- "change_pct_below": "medium",
38
- "volume_ratio_above": "medium",
39
- }.get(rule_type, "low")
40
-
41
-
42
29
  def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) -> dict | None:
43
30
  rtype = rule.get("type")
44
31
  value = rule.get("value")
@@ -55,7 +42,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
55
42
  "triggered": True,
56
43
  "value": value,
57
44
  "actual": price,
58
- "severity": _severity_for(rtype),
45
+ "severity": "medium",
59
46
  "message": f"现价 {price} 跌破 {value}",
60
47
  }
61
48
  elif rtype == "price_above":
@@ -65,7 +52,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
65
52
  "triggered": True,
66
53
  "value": value,
67
54
  "actual": price,
68
- "severity": _severity_for(rtype),
55
+ "severity": "medium",
69
56
  "message": f"现价 {price} 突破 {value}",
70
57
  }
71
58
  elif rtype == "change_pct_above":
@@ -75,7 +62,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
75
62
  "triggered": True,
76
63
  "value": value,
77
64
  "actual": change_pct,
78
- "severity": _severity_for(rtype),
65
+ "severity": "medium",
79
66
  "message": f"涨幅 {change_pct}% 超过 {value}%",
80
67
  }
81
68
  elif rtype == "change_pct_below":
@@ -85,7 +72,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
85
72
  "triggered": True,
86
73
  "value": value,
87
74
  "actual": change_pct,
88
- "severity": _severity_for(rtype),
75
+ "severity": "medium",
89
76
  "message": f"跌幅 {change_pct}% 低于 {value}%",
90
77
  }
91
78
  elif rtype == "volume_ratio_above":
@@ -97,7 +84,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
97
84
  "triggered": True,
98
85
  "value": value,
99
86
  "actual": ratio,
100
- "severity": _severity_for(rtype),
87
+ "severity": "medium",
101
88
  "message": f"量比 {ratio} 超过 {value}",
102
89
  }
103
90
  elif rtype == "anomaly":
package/tools/backtest.py CHANGED
@@ -482,7 +482,7 @@ def diagnose_advanced(metrics: dict, trades: list, equity_curve: list, strategy:
482
482
  trade_count_quality = "sufficient"
483
483
 
484
484
  # main_failure_reason — pick the most impactful weakness
485
- sell_trades = [t for t in trades if t.get("action") == "sell"]
485
+ sell_trades = [t for t in trades if t.get("type") == "sell"]
486
486
  stop_hits = sum(
487
487
  1
488
488
  for t in sell_trades
@@ -509,9 +509,9 @@ def diagnose_advanced(metrics: dict, trades: list, equity_curve: list, strategy:
509
509
  if len(equity_curve) >= 3:
510
510
  # split into halves, compare
511
511
  mid = len(equity_curve) // 2
512
- first = equity_curve[mid][1] if isinstance(equity_curve[mid], list) else equity_curve[mid]
513
- last = equity_curve[-1][1] if isinstance(equity_curve[-1], list) else equity_curve[-1]
514
- start_v = equity_curve[0][1] if isinstance(equity_curve[0], list) else equity_curve[0]
512
+ first = equity_curve[mid]["equity"]
513
+ last = equity_curve[-1]["equity"]
514
+ start_v = equity_curve[0]["equity"]
515
515
  first_half = (first - start_v) / start_v if start_v else 0
516
516
  second_half = (last - first) / first if first else 0
517
517
  if first_half > 0.05 and second_half > 0.05:
@@ -39,6 +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
+ "get_limit_up_pool": {"markets": ["A"], "reason": "A-share only"},
43
+ "get_dragon_tiger": {"markets": ["A"], "reason": "A-share only"},
44
+ "get_hot_stocks": {"markets": ["A"], "reason": "A-share only"},
42
45
  "get_social_sentiment": {
43
46
  "markets": ["A", "HK", "US"],
44
47
  "reason": "A-share uses Eastmoney/Xueqiu; HK/US require SENTIMENT_API_KEY",
@@ -52,6 +55,11 @@ TOOL_MATRIX = {
52
55
  "search_comprehensive_intel": {"markets": ALL_MARKETS, "reason": None},
53
56
  "extract_article": {"markets": ALL_MARKETS, "reason": None},
54
57
  "screen_risk": {"markets": ["A"], "reason": "A-share only"},
58
+ # trading phase (session tables) + signal tracking (local JSONL store)
59
+ "get_trading_phase": {"markets": ALL_MARKETS, "reason": None},
60
+ "record_signal": {"markets": ALL_MARKETS, "reason": None},
61
+ "evaluate_signals": {"markets": ALL_MARKETS, "reason": None},
62
+ "get_signal_summary": {"markets": ALL_MARKETS, "reason": None},
55
63
  }
56
64
 
57
65
 
package/tools/gather.py CHANGED
@@ -4,16 +4,15 @@
4
4
  import argparse
5
5
  import json
6
6
  import sys
7
- from concurrent.futures import ThreadPoolExecutor, as_completed
7
+ from concurrent.futures import ThreadPoolExecutor
8
8
  from pathlib import Path
9
9
 
10
10
  sys.path.insert(0, str(Path(__file__).resolve().parent))
11
11
  from _subproc import run_tool # noqa: E402
12
12
 
13
13
 
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.
14
+ # gather fans out the heavier CLIs, so the default timeout stays 60s; raw stdout
15
+ # wanted here (parsing is _parse_json's job); def keeps timeout kw-passable.
17
16
  def _run(script, args, timeout=60):
18
17
  return run_tool(script, args, timeout=timeout, parse_json=False)
19
18
 
@@ -27,6 +26,12 @@ def _parse_json(raw: str | None):
27
26
  return raw
28
27
 
29
28
 
29
+ def _run_all(tasks: dict) -> dict:
30
+ with ThreadPoolExecutor(max_workers=len(tasks)) as pool:
31
+ futures = {pool.submit(_run, script, args): key for key, (script, args) in tasks.items()}
32
+ return {key: _parse_json(f.result()) for f, key in futures.items()}
33
+
34
+
30
35
  def gather_analysis(symbol: str) -> dict:
31
36
  tasks = {
32
37
  "quote": ("stock_data.py", ["quote", symbol]),
@@ -38,15 +43,7 @@ def gather_analysis(symbol: str) -> dict:
38
43
  "risk": ("risk_screening.py", ["screen", symbol]),
39
44
  "regime": ("market_regime.py", ["detect"]),
40
45
  }
41
-
42
- results = {}
43
- with ThreadPoolExecutor(max_workers=8) as pool:
44
- futures = {pool.submit(_run, script, args): key for key, (script, args) in tasks.items()}
45
- for future in as_completed(futures):
46
- key = futures[future]
47
- results[key] = _parse_json(future.result())
48
-
49
- return results
46
+ return _run_all(tasks)
50
47
 
51
48
 
52
49
  def gather_technical(symbol: str, kline_count: int = 120, with_quote: bool = False) -> dict:
@@ -56,15 +53,7 @@ def gather_technical(symbol: str, kline_count: int = 120, with_quote: bool = Fal
56
53
  }
57
54
  if with_quote:
58
55
  tasks["quote"] = ("stock_data.py", ["quote", symbol])
59
-
60
- results = {}
61
- with ThreadPoolExecutor(max_workers=4) as pool:
62
- futures = {pool.submit(_run, script, args): key for key, (script, args) in tasks.items()}
63
- for future in as_completed(futures):
64
- key = futures[future]
65
- results[key] = _parse_json(future.result())
66
-
67
- return results
56
+ return _run_all(tasks)
68
57
 
69
58
 
70
59
  def gather_screen(market: str = "A", top: int = 20, config: str | None = None) -> dict:
@@ -85,15 +74,7 @@ def gather_fundamental(symbol: str) -> dict:
85
74
  "stock_info": ("stock_data.py", ["stock_info", symbol]),
86
75
  "sector_rankings": ("stock_data.py", ["sector_rankings", "--top", "5", "--direction", "both"]),
87
76
  }
88
-
89
- results = {}
90
- with ThreadPoolExecutor(max_workers=7) as pool:
91
- futures = {pool.submit(_run, script, args): key for key, (script, args) in tasks.items()}
92
- for future in as_completed(futures):
93
- key = futures[future]
94
- results[key] = _parse_json(future.result())
95
-
96
- return results
77
+ return _run_all(tasks)
97
78
 
98
79
 
99
80
  def main():
@@ -71,7 +71,7 @@ def review_market(market: str = "A") -> dict:
71
71
 
72
72
  if market == "A":
73
73
  tasks["indices"] = ("stock_data.py", ["market_indices", "--region", "cn"])
74
- tasks["stats"] = ("stock_data.py", ["market_stats", "--market", "A"])
74
+ tasks["stats"] = ("stock_data.py", ["market_stats"])
75
75
  tasks["sectors"] = ("stock_data.py", ["sector_rankings", "--top", "5", "--direction", "both"])
76
76
  # query 含空格,必须保持单个 argv 元素
77
77
  tasks["news"] = ("search_intel.py", ["search", "A股 今日 市场"])
@@ -4,20 +4,14 @@
4
4
  import argparse
5
5
  import json
6
6
  import sys
7
- import time
8
7
  from difflib import SequenceMatcher
8
+ from pathlib import Path
9
9
 
10
- _STOCK_MAP_CACHE = None
10
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
11
11
 
12
+ from stock_data import _akshare_retry # noqa: E402
12
13
 
13
- def _akshare_retry(fn, *args, retries=2, delay=1):
14
- for attempt in range(retries + 1):
15
- try:
16
- return fn(*args)
17
- except Exception:
18
- if attempt == retries:
19
- raise
20
- time.sleep(delay)
14
+ _STOCK_MAP_CACHE = None
21
15
 
22
16
 
23
17
  def _load_stock_map() -> list[dict]:
package/tools/pattern.py CHANGED
@@ -3,34 +3,15 @@
3
3
 
4
4
  import argparse
5
5
  import json
6
- import os
7
- import subprocess
8
6
  import sys
7
+ from pathlib import Path
9
8
 
10
9
  import numpy as np
11
10
  import pandas as pd
12
11
 
12
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
13
13
 
14
- def fetch_kline(symbol: str, period: str = "daily", count: int = 60) -> list:
15
- script = os.path.join(os.path.dirname(os.path.abspath(__file__)), "stock_data.py")
16
- r = subprocess.run(
17
- [sys.executable, script, "kline", symbol, "--period", period, "--count", str(count)],
18
- capture_output=True,
19
- text=True,
20
- encoding="utf-8",
21
- )
22
- return json.loads(r.stdout)
23
-
24
-
25
- def to_dataframe(records: list) -> pd.DataFrame:
26
- df = pd.DataFrame(records)
27
- for c in ["open", "high", "low", "close", "volume"]:
28
- if c in df.columns:
29
- df[c] = pd.to_numeric(df[c], errors="coerce")
30
- if "date" in df.columns:
31
- df["date"] = pd.to_datetime(df["date"], errors="coerce")
32
- df = df.sort_values("date").reset_index(drop=True)
33
- return df
14
+ from technical import fetch_kline, to_dataframe # noqa: E402
34
15
 
35
16
 
36
17
  def _body(row):
@@ -403,8 +384,6 @@ PATTERN_STRENGTH = {
403
384
  "hammer": "中",
404
385
  "hanging_man": "中",
405
386
  "shooting_star": "中",
406
- "big_candle_up": "中",
407
- "big_candle_down": "中",
408
387
  "double_bottom": "中",
409
388
  "box_oscillation": "中",
410
389
  "morning_star": "强",
@@ -92,7 +92,6 @@ def main():
92
92
  p.add_argument("--input-b64", help="Base64-encoded JSON (avoids shell escaping)")
93
93
 
94
94
  p2 = sub.add_parser("market", help="Render a market review report")
95
- p2.add_argument("--template", default="full", choices=["full"])
96
95
  p2.add_argument("--input", "-i", default="-", help="JSON file path or '-' for stdin")
97
96
  p2.add_argument("--input-b64", help="Base64-encoded JSON (avoids shell escaping)")
98
97
 
@@ -102,7 +101,7 @@ def main():
102
101
  sys.exit(1)
103
102
 
104
103
  report = _load_input(args.input, getattr(args, "input_b64", None))
105
- result = render(args.command, args.template, report)
104
+ result = render(args.command, getattr(args, "template", "full"), report)
106
105
  json.dump(result, sys.stdout, ensure_ascii=False, indent=2, default=str)
107
106
  print()
108
107