@weaxs/dsh-stock-analysis 0.1.10 → 0.1.12
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/dist/index.js +31 -29
- package/package.json +1 -1
- package/skills/stock-analysis/SKILL.md +12 -1
- package/skills/stock-screener/SKILL.md +8 -2
- package/tools/market_review.py +2 -2
- package/tools/screener.py +236 -19
- package/tools/search_intel.py +129 -105
- package/tools/stock_data.py +76 -65
package/dist/index.js
CHANGED
|
@@ -84,7 +84,7 @@ function apply(ctx) {
|
|
|
84
84
|
ctx.tools.register(
|
|
85
85
|
pyTool({
|
|
86
86
|
name: "get_kline",
|
|
87
|
-
description: "\u83B7\u53D6\u80A1\u7968K\u7EBF\u6570\u636E\uFF08OHLCV\uFF09\u3002\u652F\u6301A\u80A1\uFF08\u5982600519\uFF09\u3001\u6E2F\u80A1\uFF08\u598200700.HK\uFF09\u3001\u7F8E\u80A1\uFF08\u5982AAPL\uFF09\u3001\u65E5\u80A1\uFF08\u59827203.T\uFF09\u3001\u97E9\u80A1\uFF08\u5982005930.KS\uFF09\u3001\u53F0\u80A1\uFF08\u59822330.TW\uFF09\u53CAA\u80A1ETF",
|
|
87
|
+
description: "\u83B7\u53D6\u80A1\u7968K\u7EBF\u6570\u636E\uFF08OHLCV\uFF09\u3002\u652F\u6301A\u80A1\uFF08\u5982600519\uFF09\u3001\u6E2F\u80A1\uFF08\u598200700.HK\uFF09\u3001\u7F8E\u80A1\uFF08\u5982AAPL\uFF09\u3001\u65E5\u80A1\uFF08\u59827203.T\uFF09\u3001\u97E9\u80A1\uFF08\u5982005930.KS\uFF09\u3001\u53F0\u80A1\uFF08\u59822330.TW\uFF09\u53CAA\u80A1ETF\u3002\u9700\u8981\u539F\u59CB\u5386\u53F2\u4EF7\u683C\u81EA\u884C\u8BA1\u7B97\u6216\u753B\u56FE\u65F6\u7528\uFF1B\u53EA\u95EE\u6307\u6807\u7528 get_technical_analysis\uFF0C\u53EA\u95EE\u73B0\u4EF7\u7528 get_quote",
|
|
88
88
|
parameters: {
|
|
89
89
|
symbol: {
|
|
90
90
|
type: "string",
|
|
@@ -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\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",
|
|
116
116
|
parameters: {
|
|
117
117
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" }
|
|
118
118
|
},
|
|
@@ -123,7 +123,7 @@ function apply(ctx) {
|
|
|
123
123
|
ctx.tools.register(
|
|
124
124
|
pyTool({
|
|
125
125
|
name: "get_capital_flow",
|
|
126
|
-
description: "\u83B7\u53D6A\u80A1\u8D44\u91D1\u6D41\u5411\
|
|
126
|
+
description: "\u83B7\u53D6A\u80A1\u8D44\u91D1\u6D41\u5411\uFF08\u4E3B\u529B/\u8D85\u5927\u5355/\u5927\u5355/\u4E2D\u5355/\u5C0F\u5355\u51C0\u6D41\u5165\uFF09\u3002detail=\u4E2A\u80A1\u6BCF\u65E5\u660E\u7EC6\uFF0Csummary=\u591A\u65E5\u6C47\u603B+\u8D8B\u52BF\uFF0Csector_flow=\u677F\u5757\u8D44\u91D1\u6D41\u6392\u884C\u3002\u53EF\u914D\u5408 get_chip_distribution \u9A8C\u8BC1\u4E3B\u529B\u884C\u4E3A",
|
|
127
127
|
parameters: {
|
|
128
128
|
symbol: {
|
|
129
129
|
type: "string",
|
|
@@ -147,7 +147,7 @@ function apply(ctx) {
|
|
|
147
147
|
ctx.tools.register(
|
|
148
148
|
pyTool({
|
|
149
149
|
name: "get_news",
|
|
150
|
-
description: "\u83B7\u53D6\u80A1\
|
|
150
|
+
description: "\u83B7\u53D6\u4E2A\u80A1\u6700\u8FD1N\u5929\u8D22\u7ECF\u65B0\u95FB\u5FEB\u8BAF\uFF08\u8F7B\u91CF\u3001\u65E0\u9700\u914D\u7F6E\uFF09\u3002\u9700\u8981\u6DF1\u5EA6\u5168\u7F51\u60C5\u62A5\u7528 search_comprehensive_intel\uFF0C\u6309\u4E3B\u9898\u641C\u7D22\u7528 search_stock_news\uFF0C\u8BFB\u6587\u7AE0\u5168\u6587\u7528 extract_article",
|
|
151
151
|
parameters: {
|
|
152
152
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
153
153
|
days: { type: "number", description: "\u83B7\u53D6\u6700\u8FD1\u51E0\u5929\u7684\u65B0\u95FB\uFF0C\u9ED8\u8BA4 3" }
|
|
@@ -159,7 +159,7 @@ function apply(ctx) {
|
|
|
159
159
|
ctx.tools.register(
|
|
160
160
|
pyTool({
|
|
161
161
|
name: "get_financials",
|
|
162
|
-
description: "\u83B7\u53D6\u80A1\u7968\u5173\u952E\u8D22\u52A1\u6307\u6807\uFF08PE/PB/\u5E02\u503C/\u8425\u6536/\u51C0\u5229\u6DA6/ROE\u7B49\uFF09",
|
|
162
|
+
description: "\u83B7\u53D6\u80A1\u7968\u5173\u952E\u8D22\u52A1\u6307\u6807\uFF08PE/PB/\u5E02\u503C/\u8425\u6536/\u51C0\u5229\u6DA6/ROE\u7B49\uFF09\uFF0C\u9002\u5408\u5FEB\u901F\u4F30\u503C\u5FEB\u67E5\u3002A\u80A1\u6DF1\u5EA6\u57FA\u672C\u9762\uFF08\u6210\u957F\u6027/\u76C8\u5229\u80FD\u529B/\u5206\u7EA2\uFF09\u7528 get_fundamental_context",
|
|
163
163
|
parameters: {
|
|
164
164
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" }
|
|
165
165
|
},
|
|
@@ -170,7 +170,7 @@ function apply(ctx) {
|
|
|
170
170
|
ctx.tools.register(
|
|
171
171
|
pyTool({
|
|
172
172
|
name: "get_technical_analysis",
|
|
173
|
-
description: "\u83B7\u53D6\u80A1\u7968\u6280\u672F\u9762\u5206\u6790\uFF08MA/MACD/RSI/BOLL/KDJ/\u6210\u4EA4\u91CF\u7B49\u6307\u6807 + 100\u5206\u7EFC\u5408\u8BC4\u5206 + 6\u7EA7\u4E70\u5356\u4FE1\u53F7 + \u8D8B\u52BF/\u504F\u79BB\u5EA6/\u652F\u6491\u538B\u529B\u4F4D\uFF09",
|
|
173
|
+
description: "\u83B7\u53D6\u80A1\u7968\u6280\u672F\u9762\u5206\u6790\uFF08MA/MACD/RSI/BOLL/KDJ/\u6210\u4EA4\u91CF\u7B49\u6307\u6807 + 100\u5206\u7EFC\u5408\u8BC4\u5206 + 6\u7EA7\u4E70\u5356\u4FE1\u53F7 + \u8D8B\u52BF/\u504F\u79BB\u5EA6/\u652F\u6491\u538B\u529B\u4F4D\uFF09\u3002\u4E2A\u80A1\u6280\u672F\u9762\u7EFC\u5408\u5224\u65AD\u4E0E\u4E70\u5356\u65F6\u673A\u5206\u6790\u7684\u9996\u9009\uFF1B\u53EA\u8981\u5747\u7EBF\u6570\u503C\u6216\u81EA\u5B9A\u4E49\u5468\u671F\u7528 calculate_ma\uFF0C\u4E13\u95EE\u91CF\u4EF7\u7528 get_volume_analysis\uFF0C\u626B\u5F53\u65E5\u5F02\u52A8\u7528 detect_anomaly",
|
|
174
174
|
parameters: {
|
|
175
175
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
176
176
|
period: {
|
|
@@ -194,7 +194,7 @@ function apply(ctx) {
|
|
|
194
194
|
ctx.tools.register(
|
|
195
195
|
pyTool({
|
|
196
196
|
name: "analyze_pattern",
|
|
197
|
-
description: "K\u7EBF\u5F62\u6001\u8BC6\u522B \u2014 \u68C0\u6D4B\u5341\u5B57\u661F\u3001\u9524\u5B50\u7EBF\u3001\u541E\u6CA1\u3001\u542F\u660E\u661F\u3001\u9EC4\u660F\u661F\u3001\u53CC\u5E95\u300120\u65E5\u7A81\u7834\u7B4912+\u79CD\u7ECF\u5178\u5F62\u6001",
|
|
197
|
+
description: "K\u7EBF\u5F62\u6001\u8BC6\u522B \u2014 \u68C0\u6D4B\u5341\u5B57\u661F\u3001\u9524\u5B50\u7EBF\u3001\u541E\u6CA1\u3001\u542F\u660E\u661F\u3001\u9EC4\u660F\u661F\u3001\u53CC\u5E95\u300120\u65E5\u7A81\u7834\u7B4912+\u79CD\u7ECF\u5178\u5F62\u6001\u3002\u7EFC\u5408\u6280\u672F\u9762\u5224\u65AD\u7528 get_technical_analysis",
|
|
198
198
|
parameters: {
|
|
199
199
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
200
200
|
period: {
|
|
@@ -218,7 +218,7 @@ function apply(ctx) {
|
|
|
218
218
|
ctx.tools.register(
|
|
219
219
|
pyTool({
|
|
220
220
|
name: "get_market_indices",
|
|
221
|
-
description: "\u83B7\u53D6\u4E3B\u8981\u5E02\u573A\u6307\u6570\u884C\u60C5\u3002CN: \u4E0A\u8BC1/\u6DF1\u8BC1/\u521B\u4E1A\u677F/\u79D1\u521B50/\u6CAA\u6DF1300\uFF1BHK: \u6052\u751F/\u56FD\u4F01/\u79D1\u6280\uFF1BUS: \u9053\u743C\u65AF/\u7EB3\u65AF\u8FBE\u514B/\u6807\u666E500\uFF1BJP: \u65E5\u7ECF225/\u4E1C\u8BC1\uFF1BKR: KOSPI/KOSDAQ\uFF1BTW: \u53F0\u6E7E\u52A0\u6743",
|
|
221
|
+
description: "\u83B7\u53D6\u4E3B\u8981\u5E02\u573A\u6307\u6570\u884C\u60C5\u3002CN: \u4E0A\u8BC1/\u6DF1\u8BC1/\u521B\u4E1A\u677F/\u79D1\u521B50/\u6CAA\u6DF1300\uFF1BHK: \u6052\u751F/\u56FD\u4F01/\u79D1\u6280\uFF1BUS: \u9053\u743C\u65AF/\u7EB3\u65AF\u8FBE\u514B/\u6807\u666E500\uFF1BJP: \u65E5\u7ECF225/\u4E1C\u8BC1\uFF1BKR: KOSPI/KOSDAQ\uFF1BTW: \u53F0\u6E7E\u52A0\u6743\u3002\u5927\u76D8\u590D\u76D8\u7528 get_market_review \u4E00\u7AD9\u5F0F\u83B7\u53D6",
|
|
222
222
|
parameters: {
|
|
223
223
|
region: {
|
|
224
224
|
type: "string",
|
|
@@ -266,7 +266,7 @@ function apply(ctx) {
|
|
|
266
266
|
ctx.tools.register(
|
|
267
267
|
pyTool({
|
|
268
268
|
name: "get_chip_distribution",
|
|
269
|
-
description: "\u83B7\u53D6A\u80A1\u7B79\u7801\u5206\u5E03\u6570\u636E\uFF08\u83B7\u5229\u6BD4\u4F8B\u3001\u5E73\u5747\u6210\u672C\u300190%/70%\u6210\u672C\u96C6\u4E2D\u5EA6\uFF09\u3002\u4EC5\u652F\u6301A\u80A1",
|
|
269
|
+
description: "\u83B7\u53D6A\u80A1\u7B79\u7801\u5206\u5E03\u6570\u636E\uFF08\u83B7\u5229\u6BD4\u4F8B\u3001\u5E73\u5747\u6210\u672C\u300190%/70%\u6210\u672C\u96C6\u4E2D\u5EA6\uFF09\u3002\u4EC5\u652F\u6301A\u80A1\u3002\u4E0E get_capital_flow \u914D\u5408\u9A8C\u8BC1\u4E3B\u529B\u884C\u4E3A",
|
|
270
270
|
parameters: {
|
|
271
271
|
symbol: {
|
|
272
272
|
type: "string",
|
|
@@ -281,7 +281,7 @@ function apply(ctx) {
|
|
|
281
281
|
ctx.tools.register(
|
|
282
282
|
pyTool({
|
|
283
283
|
name: "get_market_stats",
|
|
284
|
-
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",
|
|
284
|
+
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",
|
|
285
285
|
parameters: {
|
|
286
286
|
market: {
|
|
287
287
|
type: "string",
|
|
@@ -296,7 +296,7 @@ function apply(ctx) {
|
|
|
296
296
|
ctx.tools.register(
|
|
297
297
|
pyTool({
|
|
298
298
|
name: "get_fundamental_context",
|
|
299
|
-
description: "\u83B7\u53D6A\u80A1\u6DF1\u5EA6\u57FA\u672C\u9762\uFF08\u4F30\u503CPE/PB/PS + \u6210\u957F\u6027\u8425\u6536/\u51C0\u5229\u589E\u901F + \u76C8\u5229\u80FD\u529BROE/\u6BDB\u5229\u7387 + \u5206\u7EA2\u5386\u53F2\uFF09",
|
|
299
|
+
description: "\u83B7\u53D6A\u80A1\u6DF1\u5EA6\u57FA\u672C\u9762\uFF08\u4F30\u503CPE/PB/PS + \u6210\u957F\u6027\u8425\u6536/\u51C0\u5229\u589E\u901F + \u76C8\u5229\u80FD\u529BROE/\u6BDB\u5229\u7387 + \u5206\u7EA2\u5386\u53F2\uFF09\u3002\u7528\u4E8E\u8BC4\u4F30\u516C\u53F8\u8D28\u5730\u4E0E\u957F\u671F\u6301\u6709\u4EF7\u503C\uFF1B\u5FEB\u901F\u67E5PE/PB\u7528 get_financials",
|
|
300
300
|
parameters: {
|
|
301
301
|
symbol: {
|
|
302
302
|
type: "string",
|
|
@@ -311,7 +311,7 @@ function apply(ctx) {
|
|
|
311
311
|
ctx.tools.register(
|
|
312
312
|
pyTool({
|
|
313
313
|
name: "screen_stocks",
|
|
314
|
-
description: "\u5168\u5E02\u573A\u80A1\u7968\u7B5B\u9009\uFF08AlphaSift L1 \u591A\u56E0\u5B50\u786C\u7B5B\uFF09\u3002\u6309PE/PB/\u5E02\u503C/\u6362\u624B\u7387/\u6DA8\u8DCC\u5E45/\u91CF\u6BD4\u7B49\u56E0\u5B50\u8FC7\u6EE4\u548C\u8BC4\u5206",
|
|
314
|
+
description: "\u5168\u5E02\u573A\u80A1\u7968\u7B5B\u9009\uFF08AlphaSift L1 \u591A\u56E0\u5B50\u786C\u7B5B + \u5E02\u573A\u60C5\u7EEA\u8C03\u8282\uFF09\u3002\u6309PE/PB/\u5E02\u503C/\u6362\u624B\u7387/\u6DA8\u8DCC\u5E45/\u91CF\u6BD4\u7B49\u56E0\u5B50\u8FC7\u6EE4\u548C\u8BC4\u5206\uFF0C\u53EF\u7528 l2 \u5F00\u542F\u8D28\u91CF/\u6210\u957F/\u52A8\u91CF/\u6CE2\u52A8\u7387/\u8D44\u91D1\u6D41\u589E\u5F3A",
|
|
315
315
|
parameters: {
|
|
316
316
|
market: {
|
|
317
317
|
type: "string",
|
|
@@ -319,12 +319,14 @@ function apply(ctx) {
|
|
|
319
319
|
description: "\u5E02\u573A\uFF0C\u9ED8\u8BA4 A"
|
|
320
320
|
},
|
|
321
321
|
top: { type: "number", description: "\u8FD4\u56DE\u6392\u540D\u524DN\u7684\u80A1\u7968\uFF0C\u9ED8\u8BA4 20" },
|
|
322
|
-
config: { type: "string", description: "\u81EA\u5B9A\u4E49\u7B5B\u9009\u914D\u7F6EYAML\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09" }
|
|
322
|
+
config: { type: "string", description: "\u81EA\u5B9A\u4E49\u7B5B\u9009\u914D\u7F6EYAML\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09" },
|
|
323
|
+
l2: { type: "boolean", description: "\u5F00\u542FL2\u91CF\u5316\u589E\u5F3A\uFF08\u8D28\u91CF/\u6210\u957F/\u771F\u5B9E\u52A8\u91CF/\u6CE2\u52A8\u7387/\u8D44\u91D1\u6D41\u56E0\u5B50\uFF0C\u9010\u80A1\u6293\u53D6\u6570\u636E\u8F83\u6162\uFF09\uFF0C\u9ED8\u8BA4\u5173\u95ED" }
|
|
323
324
|
},
|
|
324
325
|
script: "screener.py",
|
|
325
326
|
argv: (p) => {
|
|
326
327
|
const args = ["screen", "--market", p.market ?? "A", "--top", String(p.top ?? 20)];
|
|
327
328
|
if (p.config) args.push("--config", p.config);
|
|
329
|
+
if (p.l2) args.push("--l2");
|
|
328
330
|
return args;
|
|
329
331
|
}
|
|
330
332
|
})
|
|
@@ -332,7 +334,7 @@ function apply(ctx) {
|
|
|
332
334
|
ctx.tools.register(
|
|
333
335
|
pyTool({
|
|
334
336
|
name: "run_backtest",
|
|
335
|
-
description: "\u7B56\u7565\u56DE\u6D4B\uFF08AlphaEvo\uFF09\u3002\u8BFB\u53D6YAML\u7B56\u7565\u5B9A\u4E49\uFF0C\u5728\u5386\u53F2\u6570\u636E\u4E0A\u6A21\u62DF\u4EA4\u6613\uFF0C\u8F93\u51FA\u6536\u76CA\u7387/\u56DE\u64A4/\u80DC\u7387\u7B49\u6307\u6807",
|
|
337
|
+
description: "\u7B56\u7565\u56DE\u6D4B\uFF08AlphaEvo\uFF09\u3002\u8BFB\u53D6YAML\u7B56\u7565\u5B9A\u4E49\uFF0C\u5728\u5386\u53F2\u6570\u636E\u4E0A\u6A21\u62DF\u4EA4\u6613\uFF0C\u8F93\u51FA\u6536\u76CA\u7387/\u56DE\u64A4/\u80DC\u7387\u7B49\u6307\u6807\u3002\u53EA\u60F3\u77E5\u9053\u5355\u4E2A\u6280\u672F\u4FE1\u53F7\u7684\u5386\u53F2\u80DC\u7387\u7528\u66F4\u8F7B\u91CF\u7684 evaluate_signal",
|
|
336
338
|
parameters: {
|
|
337
339
|
strategy: { type: "string", required: true, description: "\u7B56\u7565YAML\u6587\u4EF6\u8DEF\u5F84" },
|
|
338
340
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
@@ -353,7 +355,7 @@ function apply(ctx) {
|
|
|
353
355
|
ctx.tools.register(
|
|
354
356
|
pyTool({
|
|
355
357
|
name: "evaluate_signal",
|
|
356
|
-
description: "\u6280\u672F\u4FE1\u53F7\u5386\u53F2\u51C6\u786E\u7387\u8BC4\u4F30 \u2014 \u56DE\u6EAF\u5386\u53F2\u6570\u636E\uFF0C\u7EDF\u8BA1\u67D0\u4E2A\u6280\u672F\u4FE1\u53F7\u89E6\u53D1\u540EN\u65E5\u7684\u80DC\u7387\u548C\u5E73\u5747\u6536\u76CA\u3002\u652F\u63019\u79CD\u4FE1\u53F7\uFF1Amacd_golden_cross/macd_death_cross/rsi_oversold/rsi_overbought/breakout_20d/breakdown_20d/volume_surge/ma_golden_cross/ma_death_cross",
|
|
358
|
+
description: "\u6280\u672F\u4FE1\u53F7\u5386\u53F2\u51C6\u786E\u7387\u8BC4\u4F30 \u2014 \u56DE\u6EAF\u5386\u53F2\u6570\u636E\uFF0C\u7EDF\u8BA1\u67D0\u4E2A\u6280\u672F\u4FE1\u53F7\u89E6\u53D1\u540EN\u65E5\u7684\u80DC\u7387\u548C\u5E73\u5747\u6536\u76CA\u3002\u652F\u63019\u79CD\u4FE1\u53F7\uFF1Amacd_golden_cross/macd_death_cross/rsi_oversold/rsi_overbought/breakout_20d/breakdown_20d/volume_surge/ma_golden_cross/ma_death_cross\u3002\u8981\u5B8C\u6574\u6A21\u62DF\u4EA4\u6613\u8FC7\u7A0B\u7528 run_backtest",
|
|
357
359
|
parameters: {
|
|
358
360
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
359
361
|
signal: {
|
|
@@ -393,7 +395,7 @@ function apply(ctx) {
|
|
|
393
395
|
ctx.tools.register(
|
|
394
396
|
pyTool({
|
|
395
397
|
name: "resolve_stock_name",
|
|
396
|
-
description: "\u80A1\u7968\u540D\u79F0\u667A\u80FD\u89E3\u6790 \u2014 \u8F93\u5165\u4E2D\u6587\u540D\uFF08\u8D35\u5DDE\u8305\u53F0\uFF09\u3001\u62FC\u97F3\uFF08guizhou maotai/gzmt\uFF09\u3001\u90E8\u5206\u4EE3\u7801\uFF0C\u8FD4\u56DE\u5339\u914D\u7684\u80A1\u7968\u4EE3\u7801\u3002\u4EC5\u652F\u6301A\u80A1",
|
|
398
|
+
description: "\u80A1\u7968\u540D\u79F0\u667A\u80FD\u89E3\u6790 \u2014 \u8F93\u5165\u4E2D\u6587\u540D\uFF08\u8D35\u5DDE\u8305\u53F0\uFF09\u3001\u62FC\u97F3\uFF08guizhou maotai/gzmt\uFF09\u3001\u90E8\u5206\u4EE3\u7801\uFF0C\u8FD4\u56DE\u5339\u914D\u7684\u80A1\u7968\u4EE3\u7801\u3002\u4EC5\u652F\u6301A\u80A1\u3002\u7528\u6237\u7ED9\u51FA\u4E2D\u6587\u540D/\u62FC\u97F3/\u90E8\u5206\u4EE3\u7801\u65F6\u5148\u8C03\u672C\u5DE5\u5177\u6362\u6210\u4EE3\u7801\u518D\u8C03\u5176\u4ED6\u5DE5\u5177",
|
|
397
399
|
parameters: {
|
|
398
400
|
query: {
|
|
399
401
|
type: "string",
|
|
@@ -457,7 +459,7 @@ function apply(ctx) {
|
|
|
457
459
|
ctx.tools.register(
|
|
458
460
|
pyTool({
|
|
459
461
|
name: "calculate_ma",
|
|
460
|
-
description: "\u72EC\u7ACB\u5747\u7EBF\u8BA1\u7B97\u5668 \u2014 \u652F\u6301\u4EFB\u610F\u5468\u671FMA\uFF085/10/20/30/60/120/250\u6216\u81EA\u5B9A\u4E49\uFF09+ \u504F\u79BB\u5EA6 + \u5747\u7EBF\u6392\u5217 + \u91D1\u53C9\u6B7B\u53C9\u68C0\u6D4B",
|
|
462
|
+
description: "\u72EC\u7ACB\u5747\u7EBF\u8BA1\u7B97\u5668 \u2014 \u652F\u6301\u4EFB\u610F\u5468\u671FMA\uFF085/10/20/30/60/120/250\u6216\u81EA\u5B9A\u4E49\uFF09+ \u504F\u79BB\u5EA6 + \u5747\u7EBF\u6392\u5217 + \u91D1\u53C9\u6B7B\u53C9\u68C0\u6D4B\u3002\u53EA\u8981\u5747\u7EBF\u6570\u503C\u6216\u9700\u898130/120/250\u7B49\u975E\u9ED8\u8BA4\u5468\u671F\u65F6\u7528\u672C\u5DE5\u5177\uFF1B\u7EFC\u5408\u6280\u672F\u9762\u5206\u6790\u7528 get_technical_analysis",
|
|
461
463
|
parameters: {
|
|
462
464
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
463
465
|
periods: {
|
|
@@ -486,7 +488,7 @@ function apply(ctx) {
|
|
|
486
488
|
ctx.tools.register(
|
|
487
489
|
pyTool({
|
|
488
490
|
name: "get_volume_analysis",
|
|
489
|
-
description: "\u72EC\u7ACB\u91CF\u4EF7\u5206\u6790 \u2014 \u91CF\u4EF7\u76F8\u5173\u6027\u3001\u4E0A\u6DA8/\u4E0B\u8DCC\u65E5\u6210\u4EA4\u91CF\u5BF9\u6BD4\u3001\u91CF\u80FD\u8D8B\u52BF\u3001\u91CF\u4EF7\u6A21\u5F0F\u89E3\u8BFB\uFF08\u653E\u91CF\u4E0A\u6DA8/\u7F29\u91CF\u56DE\u8C03\u7B49\uFF09",
|
|
491
|
+
description: "\u72EC\u7ACB\u91CF\u4EF7\u5206\u6790 \u2014 \u91CF\u4EF7\u76F8\u5173\u6027\u3001\u4E0A\u6DA8/\u4E0B\u8DCC\u65E5\u6210\u4EA4\u91CF\u5BF9\u6BD4\u3001\u91CF\u80FD\u8D8B\u52BF\u3001\u91CF\u4EF7\u6A21\u5F0F\u89E3\u8BFB\uFF08\u653E\u91CF\u4E0A\u6DA8/\u7F29\u91CF\u56DE\u8C03\u7B49\uFF09\u3002\u7EFC\u5408\u6280\u672F\u9762\u5224\u65AD\u7528 get_technical_analysis\uFF0C\u626B\u5F53\u65E5\u5F02\u52A8\u7528 detect_anomaly",
|
|
490
492
|
parameters: {
|
|
491
493
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
492
494
|
period: {
|
|
@@ -510,7 +512,7 @@ function apply(ctx) {
|
|
|
510
512
|
ctx.tools.register(
|
|
511
513
|
pyTool({
|
|
512
514
|
name: "search_stock_news",
|
|
513
|
-
description: "\u591A\u5F15\u64CE\u80A1\u7968\u65B0\u95FB\u641C\u7D22\uFF08\u652F\u6301 Tavily/Brave/SerpAPI\uFF09\u3002\u9700\u914D\u7F6E\u5BF9\u5E94 API Key \u73AF\u5883\u53D8\u91CF",
|
|
515
|
+
description: "\u591A\u5F15\u64CE\u80A1\u7968\u65B0\u95FB\u641C\u7D22\uFF08\u652F\u6301 Tavily/Brave/SerpAPI\uFF09\u3002\u9700\u914D\u7F6E\u5BF9\u5E94 API Key \u73AF\u5883\u53D8\u91CF\u3002get_news \u5FEB\u8BAF\u4E0D\u591F\u6216\u8981\u6309\u4E3B\u9898\u641C\u7D22\u65F6\u7528\u672C\u5DE5\u5177\uFF1B\u6DF1\u5EA66\u7EF4\u60C5\u62A5\u7528 search_comprehensive_intel",
|
|
514
516
|
parameters: {
|
|
515
517
|
query: { type: "string", required: true, description: "\u641C\u7D22\u5173\u952E\u8BCD" },
|
|
516
518
|
count: { type: "number", description: "\u8FD4\u56DE\u7ED3\u679C\u6570\u91CF\uFF0C\u9ED8\u8BA4 10" }
|
|
@@ -522,7 +524,7 @@ function apply(ctx) {
|
|
|
522
524
|
ctx.tools.register(
|
|
523
525
|
pyTool({
|
|
524
526
|
name: "search_comprehensive_intel",
|
|
525
|
-
description: "\u80A1\u7968\u7EFC\u5408\u60C5\u62A5\u641C\u7D22 \u2014 \u4ECE6\u4E2A\u7EF4\u5EA6\uFF08\u65B0\u95FB/\u516C\u544A/\u884C\u60C5\u5206\u6790/\u98CE\u9669/\u4E1A\u7EE9/\u884C\u4E1A\uFF09\u641C\u7D22\u7EFC\u5408\u4FE1\u606F",
|
|
527
|
+
description: "\u80A1\u7968\u7EFC\u5408\u60C5\u62A5\u641C\u7D22 \u2014 \u4ECE6\u4E2A\u7EF4\u5EA6\uFF08\u65B0\u95FB/\u516C\u544A/\u884C\u60C5\u5206\u6790/\u98CE\u9669/\u4E1A\u7EE9/\u884C\u4E1A\uFF09\u641C\u7D22\u7EFC\u5408\u4FE1\u606F\u3002\u7528\u4E8E\u4E2A\u80A1\u7684\u6DF1\u5165\u7814\u7A76/\u5168\u9762\u8C03\u7814\uFF1B\u5FEB\u901F\u770B\u65B0\u95FB\u7528 get_news",
|
|
526
528
|
parameters: {
|
|
527
529
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801" },
|
|
528
530
|
name: { type: "string", description: "\u80A1\u7968\u540D\u79F0\uFF08\u53EF\u9009\uFF0C\u63D0\u5347\u641C\u7D22\u51C6\u786E\u5EA6\uFF09" }
|
|
@@ -538,7 +540,7 @@ function apply(ctx) {
|
|
|
538
540
|
ctx.tools.register(
|
|
539
541
|
pyTool({
|
|
540
542
|
name: "get_social_sentiment",
|
|
541
|
-
description: "\u83B7\u53D6\u80A1\u7968\u793E\u4EA4\u5A92\u4F53\u60C5\u7EEA\u6570\u636E\
|
|
543
|
+
description: "\u83B7\u53D6\u80A1\u7968\u793E\u4EA4\u5A92\u4F53\u60C5\u7EEA\u6570\u636E\u3002A\u80A1\uFF1A\u4E1C\u65B9\u8D22\u5BCC\u80A1\u5427\u70ED\u5EA6+\u96EA\u7403\u8BA8\u8BBA\u70ED\u5EA6\uFF08\u65E0\u9700\u914D\u7F6E\uFF09\uFF1B\u7F8E\u80A1/\u6E2F\u80A1\uFF1AReddit/X/Polymarket\u60C5\u7EEA\uFF08\u9700 SENTIMENT_API_KEY\uFF09\u3002\u81EA\u52A8\u6309\u5E02\u573A\u9009\u6570\u636E\u6E90\u3002\u9762\u5411\u4E2A\u80A1\u7EF4\u5EA6\uFF1B\u5168\u5E02\u573A\u70ED\u95E8\u8BA8\u8BBA\u7528 get_trending_sentiment",
|
|
542
544
|
parameters: {
|
|
543
545
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08\u5982 AAPL\uFF09" }
|
|
544
546
|
},
|
|
@@ -549,7 +551,7 @@ function apply(ctx) {
|
|
|
549
551
|
ctx.tools.register(
|
|
550
552
|
pyTool({
|
|
551
553
|
name: "get_trending_sentiment",
|
|
552
|
-
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",
|
|
554
|
+
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",
|
|
553
555
|
parameters: {},
|
|
554
556
|
script: "search_intel.py",
|
|
555
557
|
argv: () => ["trending"]
|
|
@@ -558,7 +560,7 @@ function apply(ctx) {
|
|
|
558
560
|
ctx.tools.register(
|
|
559
561
|
pyTool({
|
|
560
562
|
name: "extract_article",
|
|
561
|
-
description: "\u7F51\u9875\u6587\u7AE0\u5168\u6587\u63D0\u53D6 \u2014 \u8F93\u5165URL\uFF0C\u63D0\u53D6\u6587\u7AE0\u6807\u9898\u3001\u6B63\u6587\uFF08\u6700\u591A3000\u5B57\uFF09\u3001\u4F5C\u8005\u3001\u53D1\u5E03\u65E5\u671F\u7B49\u3002\
|
|
563
|
+
description: "\u7F51\u9875\u6587\u7AE0\u5168\u6587\u63D0\u53D6 \u2014 \u8F93\u5165URL\uFF0C\u63D0\u53D6\u6587\u7AE0\u6807\u9898\u3001\u6B63\u6587\uFF08\u6700\u591A3000\u5B57\uFF09\u3001\u4F5C\u8005\u3001\u53D1\u5E03\u65E5\u671F\u7B49\u3002\u914D\u5408 get_news/search_stock_news \u7684\u641C\u7D22\u7ED3\u679C\u505A\u6DF1\u5EA6\u9605\u8BFB",
|
|
562
564
|
parameters: {
|
|
563
565
|
url: { type: "string", required: true, description: "\u6587\u7AE0URL" }
|
|
564
566
|
},
|
|
@@ -569,7 +571,7 @@ function apply(ctx) {
|
|
|
569
571
|
ctx.tools.register(
|
|
570
572
|
pyTool({
|
|
571
573
|
name: "screen_risk",
|
|
572
|
-
description: "\u98CE\u9669\u4E13\u9879\u7B5B\u67E5 \u2014 7\u7EF4\u5EA6\u98CE\u9669\u68C0\u6D4B\uFF08\u4F30\u503C\u6781\u7AEF/\u6280\u672F\u9884\u8B66/\u89E3\u7981\u5230\u671F/\u5185\u90E8\u4EBA\u51CF\u6301/\u4E1A\u7EE9\u9884\u8B66/\u76D1\u7BA1\u5904\u7F5A/\u884C\u4E1A\u653F\u7B56\uFF09\uFF0C\u8FD4\u56DE\u98CE\u9669\u8BC4\u7EA7\u548C\u4E00\u7968\u5426\u51B3\u6807\u8BB0",
|
|
574
|
+
description: "\u98CE\u9669\u4E13\u9879\u7B5B\u67E5 \u2014 7\u7EF4\u5EA6\u98CE\u9669\u68C0\u6D4B\uFF08\u4F30\u503C\u6781\u7AEF/\u6280\u672F\u9884\u8B66/\u89E3\u7981\u5230\u671F/\u5185\u90E8\u4EBA\u51CF\u6301/\u4E1A\u7EE9\u9884\u8B66/\u76D1\u7BA1\u5904\u7F5A/\u884C\u4E1A\u653F\u7B56\uFF09\uFF0C\u8FD4\u56DE\u98CE\u9669\u8BC4\u7EA7\u548C\u4E00\u7968\u5426\u51B3\u6807\u8BB0\u3002\u5165\u573A\u51B3\u7B56\u524D\u7684\u6392\u96F7\u5FC5\u8C03\u672C\u5DE5\u5177",
|
|
573
575
|
parameters: {
|
|
574
576
|
symbol: {
|
|
575
577
|
type: "string",
|
|
@@ -604,7 +606,7 @@ function apply(ctx) {
|
|
|
604
606
|
ctx.tools.register(
|
|
605
607
|
pyTool({
|
|
606
608
|
name: "get_market_review",
|
|
607
|
-
description: "\u5927\u76D8\u590D\u76D8 \u2014 \u83B7\u53D6\u5E02\u573A\u65E5\u5EA6\u590D\u76D8\u6570\u636E\uFF0C\u5305\u542B\u6307\u6570\u3001\u6DA8\u8DCC\u7EDF\u8BA1\u3001\u677F\u5757\u6392\u540D\u3001\u65B0\u95FB\u3001\u5E02\u573A\u6E29\u5EA6\u4E0E\u7B56\u7565\u5EFA\u8BAE",
|
|
609
|
+
description: "\u5927\u76D8\u590D\u76D8 \u2014 \u83B7\u53D6\u5E02\u573A\u65E5\u5EA6\u590D\u76D8\u6570\u636E\uFF0C\u5305\u542B\u6307\u6570\u3001\u6DA8\u8DCC\u7EDF\u8BA1\u3001\u677F\u5757\u6392\u540D\u3001\u65B0\u95FB\u3001\u5E02\u573A\u6E29\u5EA6\u4E0E\u7B56\u7565\u5EFA\u8BAE\u3002\u590D\u76D8\u7C7B\u9700\u6C42\u7684\u9996\u9009\uFF0C\u65E0\u9700\u518D\u5206\u522B\u8C03\u6307\u6570/\u7EDF\u8BA1/\u677F\u5757\u5DE5\u5177",
|
|
608
610
|
parameters: {
|
|
609
611
|
market: {
|
|
610
612
|
type: "string",
|
|
@@ -638,7 +640,7 @@ function apply(ctx) {
|
|
|
638
640
|
ctx.tools.register(
|
|
639
641
|
pyTool({
|
|
640
642
|
name: "detect_anomaly",
|
|
641
|
-
description: "\u5F02\u5E38/\u4E8B\u4EF6\u68C0\u6D4B \u2014 \u4E00\u952E\u626B\u63CF\u80A1\u7968\u5F53\u524D\u6240\u6709\u5F02\u52A8\u4FE1\u53F7\uFF08MACD\u91D1\u53C9\u6B7B\u53C9\u3001RSI\u8D85\u4E70\u8D85\u5356\u300120\u65E5\u7A81\u7834\u3001\u653E\u91CF\u5F02\u52A8\u3001\u6DA8\u8DCC\u505C\u3001\u5E03\u6797\u7A81\u7834\u3001KDJ\u6781\u503C\u3001\u8D44\u91D1\u5F02\u52A8\u7B49\uFF09\uFF0C\u8FD4\u56DE\u7ED3\u6784\u5316\u5F02\u5E38\u5217\u8868",
|
|
643
|
+
description: "\u5F02\u5E38/\u4E8B\u4EF6\u68C0\u6D4B \u2014 \u4E00\u952E\u626B\u63CF\u80A1\u7968\u5F53\u524D\u6240\u6709\u5F02\u52A8\u4FE1\u53F7\uFF08MACD\u91D1\u53C9\u6B7B\u53C9\u3001RSI\u8D85\u4E70\u8D85\u5356\u300120\u65E5\u7A81\u7834\u3001\u653E\u91CF\u5F02\u52A8\u3001\u6DA8\u8DCC\u505C\u3001\u5E03\u6797\u7A81\u7834\u3001KDJ\u6781\u503C\u3001\u8D44\u91D1\u5F02\u52A8\u7B49\uFF09\uFF0C\u8FD4\u56DE\u7ED3\u6784\u5316\u5F02\u5E38\u5217\u8868\u3002\u5F53\u65E5\u5F02\u52A8\u5F52\u56E0\u7684\u9996\u9009\uFF1B\u7EFC\u5408\u6280\u672F\u9762\u5224\u65AD\u7528 get_technical_analysis",
|
|
642
644
|
parameters: {
|
|
643
645
|
symbol: {
|
|
644
646
|
type: "string",
|
|
@@ -653,7 +655,7 @@ function apply(ctx) {
|
|
|
653
655
|
ctx.tools.register(
|
|
654
656
|
pyTool({
|
|
655
657
|
name: "diagnose_data_sources",
|
|
656
|
-
description: "\u6570\u636E\u6E90\u8BCA\u65AD \u2014 \u68C0\u67E5\u5F53\u524D\u73AF\u5883\u53EF\u7528\u7684\u6570\u636E provider\uFF08akshare/tushare/yfinance/finnhub/longbridge/alphavantage\uFF09\uFF0C\u8F93\u51FA\u6BCF\u4E2A\u5E02\u573A\u7684\u53EF\u7528\u94FE\u8DEF\u3001\u7F3A\u5931 env\u3001warnings",
|
|
658
|
+
description: "\u6570\u636E\u6E90\u8BCA\u65AD \u2014 \u68C0\u67E5\u5F53\u524D\u73AF\u5883\u53EF\u7528\u7684\u6570\u636E provider\uFF08akshare/tushare/yfinance/finnhub/longbridge/alphavantage\uFF09\uFF0C\u8F93\u51FA\u6BCF\u4E2A\u5E02\u573A\u7684\u53EF\u7528\u94FE\u8DEF\u3001\u7F3A\u5931 env\u3001warnings\u3002\u5DE5\u5177\u62FF\u4E0D\u5230\u6570\u636E\u6216\u62A5\u9519\u65F6\u8C03\u7528\u6392\u67E5",
|
|
657
659
|
parameters: {
|
|
658
660
|
market: {
|
|
659
661
|
type: "string",
|
|
@@ -668,7 +670,7 @@ function apply(ctx) {
|
|
|
668
670
|
ctx.tools.register(
|
|
669
671
|
pyTool({
|
|
670
672
|
name: "get_market_capabilities",
|
|
671
|
-
description: "\u5E02\u573A\u80FD\u529B\u8FB9\u754C \u2014 \u8FD4\u56DE\u6307\u5B9A\u5E02\u573A\u652F\u6301/\u4E0D\u652F\u6301\u7684\u5DE5\u5177\u5217\u8868\
|
|
673
|
+
description: "\u5E02\u573A\u80FD\u529B\u8FB9\u754C \u2014 \u8FD4\u56DE\u6307\u5B9A\u5E02\u573A\u652F\u6301/\u4E0D\u652F\u6301\u7684\u5DE5\u5177\u5217\u8868\u3002\u4E0D\u786E\u5B9A\u67D0\u5E02\u573A\u80FD\u5426\u7528\u67D0\u5DE5\u5177\uFF08\u5982\u6E2F\u80A1\u7684\u7B79\u7801\u5206\u5E03\u3001\u7F8E\u80A1\u7684\u8D44\u91D1\u6D41\uFF09\u65F6\u5148\u8C03\u672C\u5DE5\u5177\uFF0C\u907F\u514D\u8C03\u7528\u4E0D\u652F\u6301\u7684\u5DE5\u5177\u540E\u7F16\u9020\u6570\u636E",
|
|
672
674
|
parameters: {
|
|
673
675
|
market: {
|
|
674
676
|
type: "string",
|
|
@@ -684,7 +686,7 @@ function apply(ctx) {
|
|
|
684
686
|
ctx.tools.register(
|
|
685
687
|
pyTool({
|
|
686
688
|
name: "render_stock_report",
|
|
687
|
-
description: "\u80A1\u7968\u5206\u6790\u62A5\u544A\u6E32\u67D3 \u2014 \u5C06\u7ED3\u6784\u5316 JSON\uFF08\u7B26\u5408 schemas/report_schema.json\uFF09\u901A\u8FC7 j2 \u6A21\u677F\u6E32\u67D3\u4E3A Markdown\u3002template: brief|full\u3002\u4EC5\u6E32\u67D3\uFF0C\u4E0D\u4FDD\u5B58\u4E0D\u63A8\u9001",
|
|
689
|
+
description: "\u80A1\u7968\u5206\u6790\u62A5\u544A\u6E32\u67D3 \u2014 \u5C06\u7ED3\u6784\u5316 JSON\uFF08\u7B26\u5408 schemas/report_schema.json\uFF09\u901A\u8FC7 j2 \u6A21\u677F\u6E32\u67D3\u4E3A Markdown\u3002template: brief|full\u3002\u5168\u90E8\u5206\u6790\u5B8C\u6210\u540E\u7684\u6700\u540E\u4E00\u6B65\u8C03\u7528\u3002\u4EC5\u6E32\u67D3\uFF0C\u4E0D\u4FDD\u5B58\u4E0D\u63A8\u9001",
|
|
688
690
|
parameters: {
|
|
689
691
|
report: {
|
|
690
692
|
type: "object",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weaxs/dsh-stock-analysis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
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",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stock-analysis
|
|
3
|
-
description: 综合股票分析 —
|
|
3
|
+
description: 综合股票分析 — 技术面+基本面+资金面+消息面+风险筛查多维研判。用于个股综合研判类问题:走势判断、买卖时机、风险排雷、持仓处理。
|
|
4
4
|
allowed-tools: Bash(python3:*) Read
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -8,6 +8,17 @@ allowed-tools: Bash(python3:*) Read
|
|
|
8
8
|
|
|
9
9
|
你是一位专业的股票分析师。用户提供股票代码后,你需要进行全面的多维度分析并输出结构化研报。
|
|
10
10
|
|
|
11
|
+
## 意图路由表
|
|
12
|
+
|
|
13
|
+
快速问答先判断意图,按下表走最短调用链;完整综合研判走下方执行流程(gather 采集管线),不受此表限制。单工具可答的问题按各工具描述中的适用场景选择,本表不再重复。
|
|
14
|
+
|
|
15
|
+
| 意图 | 调用序列 |
|
|
16
|
+
|------|---------|
|
|
17
|
+
| 个股买卖时机 | `get_technical_analysis` → `get_capital_flow`(summary, 仅A股) → `screen_risk` → `detect_market_regime`。合成规则:screen_risk 有一票否决则不入场(无视评分);BUY/STRONG_BUY + 主力净流入 + 大盘非下跌 → 可入场;大盘下跌趋势中个股 BUY 降级为轻仓试错或等待;HOLD/WAIT 则给出具体触发条件(如回踩 MA10 不破、放量突破 20 日高点) |
|
|
18
|
+
| 个股状态速览 | `get_quote` + `get_technical_analysis` |
|
|
19
|
+
| 异动归因 | `detect_anomaly` + `get_news` |
|
|
20
|
+
| 大盘择时 | `detect_market_regime` + `get_market_stats` |
|
|
21
|
+
|
|
11
22
|
## 执行流程
|
|
12
23
|
|
|
13
24
|
### 第一步:采集数据
|
|
@@ -25,11 +25,17 @@ allowed-tools: Bash(python3:*) Read
|
|
|
25
25
|
python3 scripts/gather.py --market A --top 20
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
可选参数:`--market`(A/HK/US)、`--top`(返回数量)、`--config`(自定义 YAML
|
|
28
|
+
可选参数:`--market`(A/HK/US)、`--top`(返回数量)、`--config`(自定义 YAML 配置路径)、`--l2`(L2 量化增强开关,默认关闭)。
|
|
29
|
+
|
|
30
|
+
**何时开启 `--l2`**:需要对候选股做量化因子精排时开启。开启后逐股补算质量/成长/真实动量/波动率/资金流五类因子,结果更精细,但逐股抓取数据较慢,日常快速筛选保持关闭即可。开启 `--l2` 后候选按 `scores.final` 重新排序,config 里的 `sort_by`/`sort_order` 不生效;且 l2 模式下 `scores.momentum` 仍是 L1 参考值,不参与 final 综合分(final 用的是真实动量组)。
|
|
31
|
+
|
|
32
|
+
**`market_sentiment` 输出字段**:无论是否开 `--l2`,输出始终带 `market_sentiment`(市场情绪温度 0-100、level、multiplier 0.8-1.2 的 regime 调节器)。`multiplier < 1` 表示市场情绪偏弱,排序和推荐应更保守(收紧入选数量、降低激进度);`multiplier > 1` 表示情绪偏暖,可适度放宽。
|
|
29
33
|
|
|
30
34
|
### 第三步:L2 智能排序
|
|
31
35
|
|
|
32
|
-
对 L1 筛选出的候选股,基于返回的各项数据进行 LLM
|
|
36
|
+
对 L1 筛选出的候选股,基于返回的各项数据进行 LLM 智能排序。
|
|
37
|
+
|
|
38
|
+
注意区分两层"增强":`--l2` 是工具内的量化因子增强(在 L1 结果上补算因子,发生在排序之前);本步的 LLM 排序是 skill 流程的最后一环,在量化结果之上综合形态/量价/安全边际做最终排序。两者可叠加使用:先 `--l2` 拿精细因子,再做 LLM 排序。
|
|
33
39
|
|
|
34
40
|
排序考虑因素:
|
|
35
41
|
1. **技术形态质量**:趋势明确 > 震荡 > 趋势不明
|
package/tools/market_review.py
CHANGED
|
@@ -22,7 +22,7 @@ def _run_tool(script: str, args: str, timeout: int = 30):
|
|
|
22
22
|
return None
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def
|
|
25
|
+
def calc_temperature(stats: dict, indices: list) -> dict:
|
|
26
26
|
"""Calculate market temperature score from breadth, index change, and limit data."""
|
|
27
27
|
scores = []
|
|
28
28
|
weights = []
|
|
@@ -105,7 +105,7 @@ def review_market(market: str = "A") -> dict:
|
|
|
105
105
|
except Exception:
|
|
106
106
|
results[key] = None
|
|
107
107
|
|
|
108
|
-
temperature =
|
|
108
|
+
temperature = calc_temperature(results.get("stats"), results.get("indices"))
|
|
109
109
|
|
|
110
110
|
output = {
|
|
111
111
|
"market": market,
|
package/tools/screener.py
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""AlphaSift L1 — multi-factor stock screener with hard filter + scoring.
|
|
2
|
+
"""AlphaSift L1 — multi-factor stock screener with hard filter + scoring.
|
|
3
|
+
|
|
4
|
+
L1: snapshot → hard filters → value/momentum/liquidity composite.
|
|
5
|
+
Regime gate: market sentiment temperature scales the final score (multiplier in [0.8, 1.2]).
|
|
6
|
+
L2 (opt-in via --l2 / config l2: true): per-candidate quality/growth/momentum/volatility/moneyflow factors.
|
|
7
|
+
"""
|
|
3
8
|
|
|
4
9
|
import argparse
|
|
5
10
|
import json
|
|
6
11
|
import os
|
|
7
12
|
import subprocess
|
|
8
13
|
import sys
|
|
14
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
15
|
+
from pathlib import Path
|
|
9
16
|
|
|
10
17
|
import numpy as np
|
|
11
18
|
import pandas as pd
|
|
12
19
|
import yaml
|
|
13
20
|
|
|
21
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
22
|
+
|
|
23
|
+
from market_review import calc_temperature
|
|
24
|
+
from stock_data import compute_market_stats
|
|
25
|
+
|
|
14
26
|
DEFAULT_FILTERS = {
|
|
15
27
|
"pe_min": 0,
|
|
16
28
|
"pe_max": 100,
|
|
@@ -24,16 +36,40 @@ DEFAULT_FILTERS = {
|
|
|
24
36
|
"volume_ratio_min": 0.5,
|
|
25
37
|
}
|
|
26
38
|
|
|
39
|
+
L2_WEIGHTS = {
|
|
40
|
+
"value": 0.15,
|
|
41
|
+
"quality": 0.20,
|
|
42
|
+
"growth": 0.15,
|
|
43
|
+
"momentum": 0.20,
|
|
44
|
+
"liquidity": 0.10,
|
|
45
|
+
"moneyflow": 0.15,
|
|
46
|
+
"low_volatility": 0.05,
|
|
47
|
+
}
|
|
27
48
|
|
|
28
|
-
|
|
49
|
+
_INDEX_REGION = {"A": "cn", "HK": "hk", "US": "us"}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _fetch_json(args: list[str], timeout: int = 30) -> dict | list | None:
|
|
53
|
+
"""Run a stock_data.py CLI command and parse its JSON stdout; None on any failure."""
|
|
29
54
|
script = os.path.join(os.path.dirname(os.path.abspath(__file__)), "stock_data.py")
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
55
|
+
try:
|
|
56
|
+
r = subprocess.run(
|
|
57
|
+
[sys.executable, script, *args],
|
|
58
|
+
capture_output=True,
|
|
59
|
+
text=True,
|
|
60
|
+
encoding="utf-8",
|
|
61
|
+
timeout=timeout,
|
|
62
|
+
)
|
|
63
|
+
if r.returncode == 0 and r.stdout.strip():
|
|
64
|
+
return json.loads(r.stdout)
|
|
65
|
+
except Exception:
|
|
66
|
+
pass
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def fetch_snapshot(market: str) -> list:
|
|
71
|
+
# a cold full-market snapshot can exceed 30s (CI runners) — allow longer
|
|
72
|
+
return _fetch_json(["market_snapshot", "--market", market], timeout=120)
|
|
37
73
|
|
|
38
74
|
|
|
39
75
|
def load_config(path: str) -> dict:
|
|
@@ -111,10 +147,175 @@ def compute_scores(df: pd.DataFrame) -> pd.DataFrame:
|
|
|
111
147
|
return df
|
|
112
148
|
|
|
113
149
|
|
|
114
|
-
def
|
|
150
|
+
def sentiment_multiplier(score: float) -> float:
|
|
151
|
+
return round(0.8 + score / 100 * 0.4, 3) # linear map to [0.8, 1.2]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def compute_sentiment(market: str, snapshot: list | None = None) -> dict:
|
|
155
|
+
"""Market sentiment gate; degrades to a neutral multiplier of 1.0 on any failure."""
|
|
156
|
+
fallback = {"score": None, "level": "unknown", "signal": None, "multiplier": 1.0}
|
|
157
|
+
region = _INDEX_REGION.get(market)
|
|
158
|
+
if region is None:
|
|
159
|
+
return fallback
|
|
160
|
+
try:
|
|
161
|
+
stats = None
|
|
162
|
+
if isinstance(snapshot, list) and snapshot:
|
|
163
|
+
try:
|
|
164
|
+
stats = compute_market_stats(snapshot)
|
|
165
|
+
except Exception:
|
|
166
|
+
stats = None
|
|
167
|
+
indices = _fetch_json(["market_indices", "--region", region])
|
|
168
|
+
if not isinstance(indices, list) or not indices:
|
|
169
|
+
return fallback
|
|
170
|
+
temp = calc_temperature(stats, indices)
|
|
171
|
+
score = temp.get("score")
|
|
172
|
+
if not isinstance(score, (int, float)):
|
|
173
|
+
return fallback
|
|
174
|
+
return {
|
|
175
|
+
"score": score,
|
|
176
|
+
"level": temp.get("level", "unknown"),
|
|
177
|
+
"signal": temp.get("signal"),
|
|
178
|
+
"multiplier": sentiment_multiplier(float(score)),
|
|
179
|
+
}
|
|
180
|
+
except Exception:
|
|
181
|
+
return fallback
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _enrich_one(symbol: str, market: str) -> dict:
|
|
185
|
+
"""Fetch raw L2 indicators for one candidate; missing factor sources just yield missing keys."""
|
|
186
|
+
result: dict = {}
|
|
187
|
+
try:
|
|
188
|
+
kline = _fetch_json(["kline", symbol, "--period", "daily", "--count", "250"])
|
|
189
|
+
if isinstance(kline, list) and len(kline) >= 2:
|
|
190
|
+
closes = pd.Series([float(k["close"]) for k in kline if k.get("close") is not None])
|
|
191
|
+
highs = [float(k["high"]) for k in kline if k.get("high") is not None]
|
|
192
|
+
if len(closes) >= 21:
|
|
193
|
+
result["ret_20d"] = round(float(closes.iloc[-1] / closes.iloc[-21] - 1) * 100, 2)
|
|
194
|
+
if len(closes) >= 61:
|
|
195
|
+
result["ret_60d"] = round(float(closes.iloc[-1] / closes.iloc[-61] - 1) * 100, 2)
|
|
196
|
+
if len(closes) and highs:
|
|
197
|
+
peak = max(highs)
|
|
198
|
+
if peak > 0:
|
|
199
|
+
result["high_250_proximity"] = round(float(closes.iloc[-1]) / peak, 4)
|
|
200
|
+
rets = closes.pct_change().dropna().tail(20)
|
|
201
|
+
if len(rets) >= 2:
|
|
202
|
+
result["vol20"] = round(float(rets.std()) * float(np.sqrt(252)), 4)
|
|
203
|
+
except Exception:
|
|
204
|
+
pass
|
|
205
|
+
|
|
206
|
+
if market == "A":
|
|
207
|
+
fund = _fetch_json(["fundamental_context", symbol])
|
|
208
|
+
if isinstance(fund, dict) and "error" not in fund:
|
|
209
|
+
prof = fund.get("profitability") or {}
|
|
210
|
+
for key in ("roe", "gross_margin", "net_margin"):
|
|
211
|
+
if prof.get(key) is not None:
|
|
212
|
+
result[key] = prof[key]
|
|
213
|
+
growth = fund.get("growth") or {}
|
|
214
|
+
for key in ("revenue_yoy", "net_income_yoy"):
|
|
215
|
+
if growth.get(key) is not None:
|
|
216
|
+
result[key] = growth[key]
|
|
217
|
+
else:
|
|
218
|
+
fin = _fetch_json(["financials", symbol])
|
|
219
|
+
if isinstance(fin, dict) and "error" not in fin:
|
|
220
|
+
for key in ("roe", "profit_margin"):
|
|
221
|
+
if fin.get(key) is not None:
|
|
222
|
+
result[key] = fin[key]
|
|
223
|
+
|
|
224
|
+
if market == "A":
|
|
225
|
+
flow = _fetch_json(["capital_flow", symbol, "--mode", "summary"])
|
|
226
|
+
if isinstance(flow, dict) and "error" not in flow and flow.get("main_net_5d") is not None:
|
|
227
|
+
result["main_net_5d"] = flow["main_net_5d"]
|
|
228
|
+
return result
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _cross_sectional_scores(enrichments: dict) -> dict:
|
|
232
|
+
"""Min-max normalize enrichment factors across the candidate set; groups fully missing are skipped."""
|
|
233
|
+
fdf = pd.DataFrame.from_dict(enrichments, orient="index") if enrichments else pd.DataFrame()
|
|
234
|
+
out: dict = {sym: {} for sym in fdf.index}
|
|
235
|
+
|
|
236
|
+
def col(name: str) -> pd.Series | None:
|
|
237
|
+
return pd.to_numeric(fdf[name], errors="coerce") if name in fdf.columns else None
|
|
238
|
+
|
|
239
|
+
def add_group(group: str, parts: list):
|
|
240
|
+
valid = [p for p in parts if p is not None and p.notna().any()]
|
|
241
|
+
if not valid:
|
|
242
|
+
return
|
|
243
|
+
combined = pd.concat(valid, axis=1).mean(axis=1)
|
|
244
|
+
for sym, v in combined.items():
|
|
245
|
+
if not pd.isna(v):
|
|
246
|
+
out[sym][group] = float(v)
|
|
247
|
+
|
|
248
|
+
margin = col("gross_margin")
|
|
249
|
+
profit_margin = col("profit_margin")
|
|
250
|
+
if margin is None:
|
|
251
|
+
margin = profit_margin
|
|
252
|
+
elif profit_margin is not None:
|
|
253
|
+
margin = margin.combine_first(profit_margin)
|
|
254
|
+
add_group("quality", [_minmax(s) for s in (col("roe"), margin, col("net_margin")) if s is not None])
|
|
255
|
+
add_group(
|
|
256
|
+
"growth", [_minmax(s.clip(-50, 100)) for s in (col("revenue_yoy"), col("net_income_yoy")) if s is not None]
|
|
257
|
+
)
|
|
258
|
+
add_group(
|
|
259
|
+
"momentum",
|
|
260
|
+
[_minmax(s) for s in (col("ret_20d"), col("ret_60d"), col("high_250_proximity")) if s is not None],
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
flow = col("main_net_5d")
|
|
264
|
+
if flow is not None:
|
|
265
|
+
add_group("moneyflow", [_minmax(flow)])
|
|
266
|
+
|
|
267
|
+
vol = col("vol20")
|
|
268
|
+
if vol is not None:
|
|
269
|
+
add_group("low_volatility", [100 - _minmax(vol)])
|
|
270
|
+
|
|
271
|
+
return out
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _apply_l2(candidates: list, market: str, multiplier: float) -> None:
|
|
275
|
+
"""Enrich candidates with L2 factors and rewrite each scores['final'] as composite_l2 × multiplier."""
|
|
276
|
+
symbols = [c.get("symbol") for c in candidates]
|
|
277
|
+
enrichments: dict = {}
|
|
278
|
+
with ThreadPoolExecutor(max_workers=6) as executor:
|
|
279
|
+
futures = {executor.submit(_enrich_one, sym, market): sym for sym in symbols if sym}
|
|
280
|
+
for future, sym in futures.items():
|
|
281
|
+
try:
|
|
282
|
+
enrichments[sym] = future.result() or {}
|
|
283
|
+
except Exception:
|
|
284
|
+
enrichments[sym] = {}
|
|
285
|
+
|
|
286
|
+
factor_scores = _cross_sectional_scores(enrichments)
|
|
287
|
+
|
|
288
|
+
for c in candidates:
|
|
289
|
+
sym = c.get("symbol")
|
|
290
|
+
groups = factor_scores.get(sym, {})
|
|
291
|
+
c["enriched"] = bool(enrichments.get(sym))
|
|
292
|
+
scores = c["scores"]
|
|
293
|
+
components = {
|
|
294
|
+
"value": scores["value"],
|
|
295
|
+
"liquidity": scores["liquidity"],
|
|
296
|
+
}
|
|
297
|
+
# momentum is L2-only: candidates without kline factors drop the group and renormalize weights.
|
|
298
|
+
components.update(
|
|
299
|
+
{g: groups[g] for g in ("momentum", "quality", "growth", "moneyflow", "low_volatility") if g in groups}
|
|
300
|
+
)
|
|
301
|
+
scores.update(
|
|
302
|
+
{g: round(groups[g], 1) for g in ("quality", "growth", "moneyflow", "low_volatility") if g in groups}
|
|
303
|
+
)
|
|
304
|
+
total_weight = sum(L2_WEIGHTS[g] for g in components)
|
|
305
|
+
composite_l2 = sum(L2_WEIGHTS[g] * components[g] for g in components) / total_weight
|
|
306
|
+
scores["final"] = round(composite_l2 * multiplier, 1)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def screen(market: str, top: int, config: dict | None, l2: bool = False) -> dict:
|
|
115
310
|
raw = fetch_snapshot(market)
|
|
116
311
|
if isinstance(raw, dict) and "error" in raw:
|
|
117
312
|
return raw
|
|
313
|
+
if raw is None:
|
|
314
|
+
return {"error": "failed to fetch market snapshot", "market": market}
|
|
315
|
+
|
|
316
|
+
l2_enabled = bool(l2 or (config or {}).get("l2"))
|
|
317
|
+
sentiment = compute_sentiment(market, raw if isinstance(raw, list) else None)
|
|
318
|
+
multiplier = sentiment["multiplier"]
|
|
118
319
|
|
|
119
320
|
df = pd.DataFrame(raw)
|
|
120
321
|
total = len(df)
|
|
@@ -140,18 +341,21 @@ def screen(market: str, top: int, config: dict | None) -> dict:
|
|
|
140
341
|
"returned_count": 0,
|
|
141
342
|
"filters_applied": filters,
|
|
142
343
|
"candidates": [],
|
|
344
|
+
"market_sentiment": sentiment,
|
|
345
|
+
"l2_enabled": l2_enabled,
|
|
143
346
|
}
|
|
144
347
|
|
|
145
348
|
df = compute_scores(df)
|
|
146
349
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if sort_by in df.columns:
|
|
152
|
-
df = df.sort_values(sort_by, ascending=ascending)
|
|
350
|
+
# L2 re-scores by final afterwards; config sort_by/sort_order only apply to the non-L2 path.
|
|
351
|
+
if l2_enabled or not config:
|
|
352
|
+
sort_by, ascending = "composite_score", False
|
|
153
353
|
else:
|
|
154
|
-
|
|
354
|
+
sort_by = config.get("sort_by", "composite_score")
|
|
355
|
+
ascending = config.get("sort_order", "desc") == "asc"
|
|
356
|
+
if sort_by not in df.columns:
|
|
357
|
+
sort_by, ascending = "composite_score", False
|
|
358
|
+
df = df.sort_values(sort_by, ascending=ascending)
|
|
155
359
|
|
|
156
360
|
df = df.head(top)
|
|
157
361
|
|
|
@@ -173,14 +377,22 @@ def screen(market: str, top: int, config: dict | None) -> dict:
|
|
|
173
377
|
v = row.get(field)
|
|
174
378
|
if v is not None and not (isinstance(v, float) and np.isnan(v)):
|
|
175
379
|
entry[field] = round(float(v), 2) if isinstance(v, (float, np.floating)) else v
|
|
380
|
+
composite = float(row.get("composite_score", 0))
|
|
176
381
|
entry["scores"] = {
|
|
177
382
|
"value": round(float(row.get("value_score", 0)), 1),
|
|
178
383
|
"momentum": round(float(row.get("momentum_score", 0)), 1),
|
|
179
384
|
"liquidity": round(float(row.get("liquidity_score", 0)), 1),
|
|
180
|
-
"composite": round(
|
|
385
|
+
"composite": round(composite, 1),
|
|
386
|
+
"final": round(composite * multiplier, 1),
|
|
181
387
|
}
|
|
182
388
|
candidates.append(entry)
|
|
183
389
|
|
|
390
|
+
if l2_enabled:
|
|
391
|
+
_apply_l2(candidates, market, multiplier)
|
|
392
|
+
candidates.sort(key=lambda c: c["scores"]["final"], reverse=True)
|
|
393
|
+
for rank, entry in enumerate(candidates, 1):
|
|
394
|
+
entry["rank"] = rank
|
|
395
|
+
|
|
184
396
|
return {
|
|
185
397
|
"market": market,
|
|
186
398
|
"total_stocks": total,
|
|
@@ -188,6 +400,8 @@ def screen(market: str, top: int, config: dict | None) -> dict:
|
|
|
188
400
|
"returned_count": len(candidates),
|
|
189
401
|
"filters_applied": filters,
|
|
190
402
|
"candidates": candidates,
|
|
403
|
+
"market_sentiment": sentiment,
|
|
404
|
+
"l2_enabled": l2_enabled,
|
|
191
405
|
}
|
|
192
406
|
|
|
193
407
|
|
|
@@ -199,6 +413,9 @@ def main():
|
|
|
199
413
|
p.add_argument("--market", default="A", choices=["A", "HK", "US"])
|
|
200
414
|
p.add_argument("--top", type=int, default=20)
|
|
201
415
|
p.add_argument("--config", help="Path to YAML config file")
|
|
416
|
+
p.add_argument(
|
|
417
|
+
"--l2", action="store_true", help="Enable L2 factor enrichment (quality/growth/momentum/volatility/moneyflow)"
|
|
418
|
+
)
|
|
202
419
|
|
|
203
420
|
args = parser.parse_args()
|
|
204
421
|
if not args.command:
|
|
@@ -206,7 +423,7 @@ def main():
|
|
|
206
423
|
sys.exit(1)
|
|
207
424
|
|
|
208
425
|
config = load_config(args.config) if args.config else None
|
|
209
|
-
result = screen(args.market, args.top, config)
|
|
426
|
+
result = screen(args.market, args.top, config, l2=args.l2)
|
|
210
427
|
print(json.dumps(result, ensure_ascii=False, default=str))
|
|
211
428
|
|
|
212
429
|
|
package/tools/search_intel.py
CHANGED
|
@@ -27,123 +27,130 @@ def _cache_set(key: str, data):
|
|
|
27
27
|
|
|
28
28
|
# --------------- Web Search ---------------
|
|
29
29
|
|
|
30
|
+
_SECRET_PARAM_RE = re.compile(r"(?i)((?:api[_-]?key|token|secret|access[_-]?token)=)[^&\s]+")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _scrub_secrets(msg: str) -> str:
|
|
34
|
+
"""Error text may embed request URLs (requests connection errors) — never leak keys to stdout JSON."""
|
|
35
|
+
return _SECRET_PARAM_RE.sub(r"\1***", msg)
|
|
36
|
+
|
|
30
37
|
|
|
31
38
|
def _tavily_search(query: str, max_results: int = 5) -> list[dict]:
|
|
32
39
|
api_key = os.environ.get("TAVILY_API_KEY")
|
|
33
40
|
if not api_key:
|
|
34
41
|
return []
|
|
35
|
-
|
|
36
|
-
import requests
|
|
42
|
+
import requests
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
resp = requests.post(
|
|
45
|
+
"https://api.tavily.com/search",
|
|
46
|
+
json={
|
|
47
|
+
"api_key": api_key,
|
|
48
|
+
"query": query,
|
|
49
|
+
"max_results": max_results,
|
|
50
|
+
"search_depth": "basic",
|
|
51
|
+
},
|
|
52
|
+
timeout=15,
|
|
53
|
+
)
|
|
54
|
+
if not resp.ok:
|
|
55
|
+
raise RuntimeError(f"tavily HTTP {resp.status_code}")
|
|
56
|
+
data = resp.json()
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
"title": r.get("title", ""),
|
|
60
|
+
"url": r.get("url", ""),
|
|
61
|
+
"snippet": r.get("content", "")[:200],
|
|
62
|
+
"source": "tavily",
|
|
63
|
+
}
|
|
64
|
+
for r in data.get("results", [])
|
|
65
|
+
]
|
|
60
66
|
|
|
61
67
|
|
|
62
68
|
def _brave_search(query: str, count: int = 5) -> list[dict]:
|
|
63
69
|
api_key = os.environ.get("BRAVE_API_KEY")
|
|
64
70
|
if not api_key:
|
|
65
71
|
return []
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
]
|
|
85
|
-
|
|
86
|
-
return []
|
|
72
|
+
import requests
|
|
73
|
+
|
|
74
|
+
resp = requests.get(
|
|
75
|
+
"https://api.search.brave.com/res/v1/web/search",
|
|
76
|
+
headers={"X-Subscription-Token": api_key, "Accept": "application/json"},
|
|
77
|
+
params={"q": query, "count": count},
|
|
78
|
+
timeout=15,
|
|
79
|
+
)
|
|
80
|
+
if not resp.ok:
|
|
81
|
+
raise RuntimeError(f"brave HTTP {resp.status_code}")
|
|
82
|
+
data = resp.json()
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
"title": r.get("title", ""),
|
|
86
|
+
"url": r.get("url", ""),
|
|
87
|
+
"snippet": r.get("description", "")[:200],
|
|
88
|
+
"source": "brave",
|
|
89
|
+
}
|
|
90
|
+
for r in data.get("web", {}).get("results", [])
|
|
91
|
+
]
|
|
87
92
|
|
|
88
93
|
|
|
89
94
|
def _serpapi_search(query: str, num: int = 5) -> list[dict]:
|
|
90
95
|
api_key = os.environ.get("SERPAPI_KEY")
|
|
91
96
|
if not api_key:
|
|
92
97
|
return []
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
]
|
|
116
|
-
|
|
117
|
-
return []
|
|
98
|
+
import requests
|
|
99
|
+
|
|
100
|
+
resp = requests.get(
|
|
101
|
+
"https://serpapi.com/search",
|
|
102
|
+
params={
|
|
103
|
+
"api_key": api_key,
|
|
104
|
+
"q": query,
|
|
105
|
+
"num": num,
|
|
106
|
+
"engine": "google",
|
|
107
|
+
},
|
|
108
|
+
timeout=15,
|
|
109
|
+
)
|
|
110
|
+
if not resp.ok:
|
|
111
|
+
raise RuntimeError(f"serpapi HTTP {resp.status_code}")
|
|
112
|
+
data = resp.json()
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
"title": r.get("title", ""),
|
|
116
|
+
"url": r.get("link", ""),
|
|
117
|
+
"snippet": r.get("snippet", "")[:200],
|
|
118
|
+
"source": "serpapi",
|
|
119
|
+
}
|
|
120
|
+
for r in data.get("organic_results", [])
|
|
121
|
+
]
|
|
118
122
|
|
|
119
123
|
|
|
120
124
|
def _bocha_search(query: str, max_results: int = 5) -> list[dict]:
|
|
121
125
|
api_key = os.environ.get("BOCHA_API_KEY")
|
|
122
126
|
if not api_key:
|
|
123
127
|
return []
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
128
|
+
import requests
|
|
129
|
+
|
|
130
|
+
resp = requests.post(
|
|
131
|
+
"https://api.bochaai.com/v1/web-search",
|
|
132
|
+
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"},
|
|
133
|
+
json={"query": query, "count": max_results},
|
|
134
|
+
timeout=15,
|
|
135
|
+
)
|
|
136
|
+
if not resp.ok:
|
|
137
|
+
raise RuntimeError(f"bocha HTTP {resp.status_code}")
|
|
138
|
+
data = resp.json()
|
|
139
|
+
code = data.get("code")
|
|
140
|
+
if code is not None and str(code) != "200":
|
|
141
|
+
# Bocha can signal quota/auth failure via HTTP 200 + non-200 envelope code
|
|
142
|
+
raise RuntimeError(f"bocha code {code}: {data.get('msg') or data.get('message') or 'unknown'}")
|
|
143
|
+
# Bocha web-search returns Bing-style data.webPages.value[] (issue #13)
|
|
144
|
+
items = ((data.get("data") or {}).get("webPages") or {}).get("value") or []
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
"title": item.get("name", ""),
|
|
148
|
+
"url": item.get("url", ""),
|
|
149
|
+
"snippet": (item.get("snippet") or "")[:200],
|
|
150
|
+
"source": "bocha",
|
|
151
|
+
}
|
|
152
|
+
for item in items
|
|
153
|
+
]
|
|
147
154
|
|
|
148
155
|
|
|
149
156
|
def _searxng_search(query: str, max_results: int = 5) -> list[dict]:
|
|
@@ -155,10 +162,10 @@ def _searxng_search(query: str, max_results: int = 5) -> list[dict]:
|
|
|
155
162
|
base_urls = [u.strip().rstrip("/") for u in os.environ.get("SEARXNG_BASE_URLS", "").split(",") if u.strip()]
|
|
156
163
|
if not base_urls:
|
|
157
164
|
return []
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
165
|
+
import requests
|
|
166
|
+
|
|
167
|
+
last_error = None
|
|
168
|
+
responded = False
|
|
162
169
|
for base in base_urls:
|
|
163
170
|
try:
|
|
164
171
|
resp = requests.get(
|
|
@@ -168,7 +175,9 @@ def _searxng_search(query: str, max_results: int = 5) -> list[dict]:
|
|
|
168
175
|
timeout=15,
|
|
169
176
|
)
|
|
170
177
|
if not resp.ok:
|
|
178
|
+
last_error = f"searxng {base} HTTP {resp.status_code}"
|
|
171
179
|
continue
|
|
180
|
+
responded = True
|
|
172
181
|
data = resp.json()
|
|
173
182
|
results = [
|
|
174
183
|
{
|
|
@@ -181,8 +190,10 @@ def _searxng_search(query: str, max_results: int = 5) -> list[dict]:
|
|
|
181
190
|
]
|
|
182
191
|
if results:
|
|
183
192
|
return results
|
|
184
|
-
except Exception:
|
|
185
|
-
|
|
193
|
+
except Exception as e:
|
|
194
|
+
last_error = f"searxng {base}: {e}"
|
|
195
|
+
if last_error and not responded:
|
|
196
|
+
raise RuntimeError(last_error)
|
|
186
197
|
return []
|
|
187
198
|
|
|
188
199
|
|
|
@@ -190,6 +201,7 @@ def search_news(query: str, max_results: int = 10) -> dict:
|
|
|
190
201
|
results = []
|
|
191
202
|
engines_tried = []
|
|
192
203
|
engines_available = []
|
|
204
|
+
engines_errors = {}
|
|
193
205
|
|
|
194
206
|
for name, fn in [
|
|
195
207
|
("tavily", _tavily_search),
|
|
@@ -199,7 +211,11 @@ def search_news(query: str, max_results: int = 10) -> dict:
|
|
|
199
211
|
("searxng", _searxng_search),
|
|
200
212
|
]:
|
|
201
213
|
engines_tried.append(name)
|
|
202
|
-
|
|
214
|
+
try:
|
|
215
|
+
items = fn(query, max_results)
|
|
216
|
+
except Exception as e:
|
|
217
|
+
engines_errors[name] = _scrub_secrets(str(e))
|
|
218
|
+
continue
|
|
203
219
|
if items:
|
|
204
220
|
engines_available.append(name)
|
|
205
221
|
results.extend(items)
|
|
@@ -207,14 +223,19 @@ def search_news(query: str, max_results: int = 10) -> dict:
|
|
|
207
223
|
break
|
|
208
224
|
|
|
209
225
|
if not results:
|
|
226
|
+
if engines_errors:
|
|
227
|
+
note = "All configured search engines failed; see engines_errors for per-engine reasons."
|
|
228
|
+
else:
|
|
229
|
+
note = (
|
|
230
|
+
"No search engines configured. Set TAVILY_API_KEY, BRAVE_API_KEY, BOCHA_API_KEY, "
|
|
231
|
+
"SERPAPI_KEY, or SEARXNG_BASE_URLS in environment."
|
|
232
|
+
)
|
|
210
233
|
return {
|
|
211
234
|
"query": query,
|
|
212
235
|
"results": [],
|
|
213
236
|
"engines_tried": engines_tried,
|
|
214
|
-
"
|
|
215
|
-
|
|
216
|
-
"SERPAPI_KEY, or SEARXNG_BASE_URLS in environment."
|
|
217
|
-
),
|
|
237
|
+
"engines_errors": engines_errors,
|
|
238
|
+
"note": note,
|
|
218
239
|
}
|
|
219
240
|
|
|
220
241
|
seen_urls = set()
|
|
@@ -228,6 +249,7 @@ def search_news(query: str, max_results: int = 10) -> dict:
|
|
|
228
249
|
"query": query,
|
|
229
250
|
"results": deduped[:max_results],
|
|
230
251
|
"engines_used": engines_available,
|
|
252
|
+
"engines_errors": engines_errors,
|
|
231
253
|
"total": len(deduped),
|
|
232
254
|
}
|
|
233
255
|
|
|
@@ -244,11 +266,13 @@ def search_comprehensive(symbol: str, name: str = None) -> dict:
|
|
|
244
266
|
}
|
|
245
267
|
|
|
246
268
|
results = {}
|
|
269
|
+
engines_errors = {}
|
|
247
270
|
for dim, query in dimensions.items():
|
|
248
271
|
data = search_news(query, max_results=3)
|
|
249
272
|
results[dim] = data.get("results", [])
|
|
273
|
+
engines_errors.update(data.get("engines_errors") or {})
|
|
250
274
|
|
|
251
|
-
return {"symbol": symbol, "name": label, "dimensions": results}
|
|
275
|
+
return {"symbol": symbol, "name": label, "dimensions": results, "engines_errors": engines_errors}
|
|
252
276
|
|
|
253
277
|
|
|
254
278
|
# --------------- A-share Sentiment Sources ---------------
|
package/tools/stock_data.py
CHANGED
|
@@ -1248,7 +1248,11 @@ def cmd_market_indices(args):
|
|
|
1248
1248
|
("sh000016", "上证50"),
|
|
1249
1249
|
]
|
|
1250
1250
|
results = []
|
|
1251
|
-
|
|
1251
|
+
try:
|
|
1252
|
+
df = _akshare_retry(ak.stock_zh_index_spot_em)
|
|
1253
|
+
except Exception:
|
|
1254
|
+
# eastmoney refuses datacenter/proxy IPs (RemoteDisconnected) — sina is the fallback
|
|
1255
|
+
df = _akshare_retry(ak.stock_zh_index_spot_sina)
|
|
1252
1256
|
for code, name in indices:
|
|
1253
1257
|
clean_code = code[2:] if code[:2] in ("sh", "sz") else code
|
|
1254
1258
|
row = df[df["代码"] == clean_code]
|
|
@@ -1497,76 +1501,80 @@ def cmd_chip_distribution(args):
|
|
|
1497
1501
|
# --------------- market_stats ---------------
|
|
1498
1502
|
|
|
1499
1503
|
|
|
1504
|
+
def compute_market_stats(data: list) -> dict:
|
|
1505
|
+
"""Compute breadth/limit/turnover statistics from a market snapshot list."""
|
|
1506
|
+
import numpy as np
|
|
1507
|
+
|
|
1508
|
+
changes = []
|
|
1509
|
+
turnovers = []
|
|
1510
|
+
limit_ups = []
|
|
1511
|
+
limit_downs = []
|
|
1512
|
+
up_count = down_count = flat_count = 0
|
|
1513
|
+
|
|
1514
|
+
for s in data:
|
|
1515
|
+
chg = s.get("change_pct")
|
|
1516
|
+
if chg is not None:
|
|
1517
|
+
changes.append(float(chg))
|
|
1518
|
+
if chg > 0:
|
|
1519
|
+
up_count += 1
|
|
1520
|
+
elif chg < 0:
|
|
1521
|
+
down_count += 1
|
|
1522
|
+
else:
|
|
1523
|
+
flat_count += 1
|
|
1524
|
+
t = s.get("turnover")
|
|
1525
|
+
if t is not None:
|
|
1526
|
+
turnovers.append(float(t))
|
|
1527
|
+
|
|
1528
|
+
price = s.get("price")
|
|
1529
|
+
prev = s.get("prev_close")
|
|
1530
|
+
sym = s.get("symbol", "")
|
|
1531
|
+
if price and prev and prev > 0:
|
|
1532
|
+
code_info = normalize_stock_code(sym)
|
|
1533
|
+
lp = code_info.get("limit_pct")
|
|
1534
|
+
if lp:
|
|
1535
|
+
limit_up = calc_limit_price(float(prev), lp, "up")
|
|
1536
|
+
limit_down = calc_limit_price(float(prev), lp, "down")
|
|
1537
|
+
if abs(float(price) - limit_up) < 0.01:
|
|
1538
|
+
limit_ups.append({"symbol": sym, "name": s.get("name"), "change_pct": chg})
|
|
1539
|
+
elif abs(float(price) - limit_down) < 0.01:
|
|
1540
|
+
limit_downs.append({"symbol": sym, "name": s.get("name"), "change_pct": chg})
|
|
1541
|
+
|
|
1542
|
+
changes_arr = np.array(changes) if changes else np.array([0])
|
|
1543
|
+
sorted_data = sorted(data, key=lambda x: x.get("change_pct") or 0, reverse=True)
|
|
1544
|
+
|
|
1545
|
+
return _clean_row(
|
|
1546
|
+
{
|
|
1547
|
+
"total_stocks": len(data),
|
|
1548
|
+
"up_count": up_count,
|
|
1549
|
+
"down_count": down_count,
|
|
1550
|
+
"flat_count": flat_count,
|
|
1551
|
+
"limit_up_count": len(limit_ups),
|
|
1552
|
+
"limit_down_count": len(limit_downs),
|
|
1553
|
+
"avg_change_pct": round(float(changes_arr.mean()), 2),
|
|
1554
|
+
"median_change_pct": round(float(np.median(changes_arr)), 2),
|
|
1555
|
+
"total_turnover": round(sum(turnovers), 0) if turnovers else None,
|
|
1556
|
+
"top5_gainers": [
|
|
1557
|
+
{"symbol": s.get("symbol"), "name": s.get("name"), "change_pct": s.get("change_pct")}
|
|
1558
|
+
for s in sorted_data[:5]
|
|
1559
|
+
],
|
|
1560
|
+
"top5_losers": [
|
|
1561
|
+
{"symbol": s.get("symbol"), "name": s.get("name"), "change_pct": s.get("change_pct")}
|
|
1562
|
+
for s in sorted_data[-5:]
|
|
1563
|
+
],
|
|
1564
|
+
"limit_up_samples": limit_ups[:5],
|
|
1565
|
+
"limit_down_samples": limit_downs[:5],
|
|
1566
|
+
}
|
|
1567
|
+
)
|
|
1568
|
+
|
|
1569
|
+
|
|
1500
1570
|
def cmd_market_stats(args):
|
|
1501
1571
|
try:
|
|
1502
|
-
import numpy as np
|
|
1503
|
-
|
|
1504
1572
|
data = snapshot_a()
|
|
1505
1573
|
if isinstance(data, dict) and "error" in data:
|
|
1506
1574
|
return data
|
|
1507
1575
|
if not data:
|
|
1508
1576
|
return {"error": "No market data"}
|
|
1509
|
-
|
|
1510
|
-
changes = []
|
|
1511
|
-
turnovers = []
|
|
1512
|
-
limit_ups = []
|
|
1513
|
-
limit_downs = []
|
|
1514
|
-
up_count = down_count = flat_count = 0
|
|
1515
|
-
|
|
1516
|
-
for s in data:
|
|
1517
|
-
chg = s.get("change_pct")
|
|
1518
|
-
if chg is not None:
|
|
1519
|
-
changes.append(float(chg))
|
|
1520
|
-
if chg > 0:
|
|
1521
|
-
up_count += 1
|
|
1522
|
-
elif chg < 0:
|
|
1523
|
-
down_count += 1
|
|
1524
|
-
else:
|
|
1525
|
-
flat_count += 1
|
|
1526
|
-
t = s.get("turnover")
|
|
1527
|
-
if t is not None:
|
|
1528
|
-
turnovers.append(float(t))
|
|
1529
|
-
|
|
1530
|
-
price = s.get("price")
|
|
1531
|
-
prev = s.get("prev_close")
|
|
1532
|
-
sym = s.get("symbol", "")
|
|
1533
|
-
if price and prev and prev > 0:
|
|
1534
|
-
code_info = normalize_stock_code(sym)
|
|
1535
|
-
lp = code_info.get("limit_pct")
|
|
1536
|
-
if lp:
|
|
1537
|
-
limit_up = calc_limit_price(float(prev), lp, "up")
|
|
1538
|
-
limit_down = calc_limit_price(float(prev), lp, "down")
|
|
1539
|
-
if abs(float(price) - limit_up) < 0.01:
|
|
1540
|
-
limit_ups.append({"symbol": sym, "name": s.get("name"), "change_pct": chg})
|
|
1541
|
-
elif abs(float(price) - limit_down) < 0.01:
|
|
1542
|
-
limit_downs.append({"symbol": sym, "name": s.get("name"), "change_pct": chg})
|
|
1543
|
-
|
|
1544
|
-
changes_arr = np.array(changes) if changes else np.array([0])
|
|
1545
|
-
sorted_data = sorted(data, key=lambda x: x.get("change_pct") or 0, reverse=True)
|
|
1546
|
-
|
|
1547
|
-
return _clean_row(
|
|
1548
|
-
{
|
|
1549
|
-
"total_stocks": len(data),
|
|
1550
|
-
"up_count": up_count,
|
|
1551
|
-
"down_count": down_count,
|
|
1552
|
-
"flat_count": flat_count,
|
|
1553
|
-
"limit_up_count": len(limit_ups),
|
|
1554
|
-
"limit_down_count": len(limit_downs),
|
|
1555
|
-
"avg_change_pct": round(float(changes_arr.mean()), 2),
|
|
1556
|
-
"median_change_pct": round(float(np.median(changes_arr)), 2),
|
|
1557
|
-
"total_turnover": round(sum(turnovers), 0) if turnovers else None,
|
|
1558
|
-
"top5_gainers": [
|
|
1559
|
-
{"symbol": s.get("symbol"), "name": s.get("name"), "change_pct": s.get("change_pct")}
|
|
1560
|
-
for s in sorted_data[:5]
|
|
1561
|
-
],
|
|
1562
|
-
"top5_losers": [
|
|
1563
|
-
{"symbol": s.get("symbol"), "name": s.get("name"), "change_pct": s.get("change_pct")}
|
|
1564
|
-
for s in sorted_data[-5:]
|
|
1565
|
-
],
|
|
1566
|
-
"limit_up_samples": limit_ups[:5],
|
|
1567
|
-
"limit_down_samples": limit_downs[:5],
|
|
1568
|
-
}
|
|
1569
|
-
)
|
|
1577
|
+
return compute_market_stats(data)
|
|
1570
1578
|
except Exception as e:
|
|
1571
1579
|
return {"error": str(e)}
|
|
1572
1580
|
|
|
@@ -1708,7 +1716,10 @@ def main():
|
|
|
1708
1716
|
"market_stats": cmd_market_stats,
|
|
1709
1717
|
"fundamental_context": cmd_fundamental_context,
|
|
1710
1718
|
}
|
|
1711
|
-
|
|
1719
|
+
# Provider libraries (baostock etc.) print prose to stdout on failure,
|
|
1720
|
+
# which would corrupt the JSON-only contract — divert that noise to stderr.
|
|
1721
|
+
with contextlib.redirect_stdout(sys.stderr):
|
|
1722
|
+
result = dispatch[args.command](args)
|
|
1712
1723
|
output(result)
|
|
1713
1724
|
|
|
1714
1725
|
|