stock-analysis-plugin 0.1.10
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 +498 -0
- package/package.json +88 -0
- package/pi/index.ts +1142 -0
- package/schemas/market_review_schema.json +176 -0
- package/schemas/report_schema.json +131 -0
- package/scripts/setup-python.mjs +57 -0
- package/scripts/sync-version.sh +56 -0
- package/scripts/venv-python.mjs +20 -0
- package/skills/bottom-volume/SKILL.md +63 -0
- package/skills/bottom-volume/scripts/gather.py +22 -0
- package/skills/box-oscillation/SKILL.md +72 -0
- package/skills/box-oscillation/scripts/gather.py +22 -0
- package/skills/bull-trend/SKILL.md +60 -0
- package/skills/bull-trend/scripts/gather.py +22 -0
- package/skills/chan-theory/SKILL.md +71 -0
- package/skills/chan-theory/scripts/gather.py +22 -0
- package/skills/dragon-head/SKILL.md +69 -0
- package/skills/dragon-head/scripts/gather.py +22 -0
- package/skills/emotion-cycle/SKILL.md +65 -0
- package/skills/emotion-cycle/scripts/gather.py +22 -0
- package/skills/event-driven/SKILL.md +73 -0
- package/skills/event-driven/scripts/gather.py +22 -0
- package/skills/expectation-repricing/SKILL.md +72 -0
- package/skills/expectation-repricing/scripts/gather.py +22 -0
- package/skills/growth-quality/SKILL.md +74 -0
- package/skills/growth-quality/scripts/gather.py +22 -0
- package/skills/hot-theme/SKILL.md +74 -0
- package/skills/hot-theme/scripts/gather.py +22 -0
- package/skills/ma-crossover/SKILL.md +63 -0
- package/skills/ma-crossover/scripts/gather.py +22 -0
- package/skills/market-review/SKILL.md +70 -0
- package/skills/market-review/scripts/gather.py +23 -0
- package/skills/one-yang-three-yin/SKILL.md +74 -0
- package/skills/one-yang-three-yin/scripts/gather.py +22 -0
- package/skills/shrink-pullback/SKILL.md +59 -0
- package/skills/shrink-pullback/scripts/gather.py +22 -0
- package/skills/stock-analysis/SKILL.md +134 -0
- package/skills/stock-analysis/scripts/gather.py +22 -0
- package/skills/stock-screener/SKILL.md +68 -0
- package/skills/stock-screener/scripts/gather.py +22 -0
- package/skills/strategy-backtest/SKILL.md +129 -0
- package/skills/strategy-backtest/scripts/gather.py +23 -0
- package/skills/volume-breakout/SKILL.md +58 -0
- package/skills/volume-breakout/scripts/gather.py +22 -0
- package/skills/wave-theory/SKILL.md +67 -0
- package/skills/wave-theory/scripts/gather.py +22 -0
- package/skills/wisburg-research/SKILL.md +119 -0
- package/strategies/examples/bottom_volume.yaml +47 -0
- package/strategies/examples/box_oscillation.yaml +41 -0
- package/strategies/examples/bull_trend.yaml +42 -0
- package/strategies/examples/dragon_head.yaml +45 -0
- package/strategies/examples/emotion_cycle.yaml +43 -0
- package/strategies/examples/ma_crossover.yaml +34 -0
- package/strategies/examples/rsi_oversold.yaml +35 -0
- package/strategies/examples/shrink_pullback.yaml +45 -0
- package/strategies/examples/volume_breakout.yaml +42 -0
- package/templates/_macros.j2 +90 -0
- package/templates/market_review/full.md.j2 +103 -0
- package/templates/stock_analysis/brief.md.j2 +28 -0
- package/templates/stock_analysis/full.md.j2 +108 -0
- package/tools/__init__.py +0 -0
- package/tools/alert_rules.py +243 -0
- package/tools/anomaly_detect.py +575 -0
- package/tools/backtest.py +764 -0
- package/tools/capabilities.py +108 -0
- package/tools/diagnostics.py +146 -0
- package/tools/gather.py +157 -0
- package/tools/import_parser.py +279 -0
- package/tools/market_regime.py +252 -0
- package/tools/market_review.py +155 -0
- package/tools/name_resolver.py +136 -0
- package/tools/pattern.py +515 -0
- package/tools/position_context.py +161 -0
- package/tools/report_renderer.py +116 -0
- package/tools/requirements.txt +15 -0
- package/tools/risk_screening.py +323 -0
- package/tools/screener.py +219 -0
- package/tools/search_intel.py +504 -0
- package/tools/stock_data.py +1721 -0
- package/tools/technical.py +642 -0
- package/tools/trading_calendar.py +226 -0
- package/tools/volume_analysis.py +178 -0
- package/tools/watchlist.py +66 -0
- package/tools/watchlist_context.py +185 -0
package/pi/index.ts
ADDED
|
@@ -0,0 +1,1142 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "pi-agent";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
export default (pi: ExtensionAPI) => {
|
|
6
|
+
// Resolve the plugin root robustly: __dirname under jiti/CJS-style loaders,
|
|
7
|
+
// else import.meta.url under native ESM (where __dirname is undefined).
|
|
8
|
+
const baseDir =
|
|
9
|
+
typeof __dirname !== "undefined"
|
|
10
|
+
? `${__dirname}/..`
|
|
11
|
+
: fileURLToPath(new URL("..", import.meta.url));
|
|
12
|
+
const toolsDir = `${baseDir}/tools`;
|
|
13
|
+
const isWin = process.platform === "win32";
|
|
14
|
+
// Windows venvs ship Scripts/python.exe (there is no python3); POSIX venvs ship bin/python3.
|
|
15
|
+
const venvPython = `${baseDir}/.venv/${isWin ? "Scripts/python.exe" : "bin/python3"}`;
|
|
16
|
+
// Fallback: on Windows "python3" is usually the Microsoft Store stub — prefer "python".
|
|
17
|
+
const python = existsSync(venvPython) ? venvPython : isWin ? "python" : "python3";
|
|
18
|
+
const py = (script: string, args: string[]) =>
|
|
19
|
+
pi.exec(python, [`${toolsDir}/${script}`, ...args]);
|
|
20
|
+
const asText = (text: string) => ({
|
|
21
|
+
content: [{ type: "text" as const, text }],
|
|
22
|
+
details: {},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// --- Data Tools ---
|
|
26
|
+
|
|
27
|
+
pi.registerTool({
|
|
28
|
+
name: "get_kline",
|
|
29
|
+
description:
|
|
30
|
+
"获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF",
|
|
31
|
+
parameters: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
symbol: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "股票代码,如 600519(A股)、00700.HK(港股)、AAPL(美股)、7203.T(日股)、005930.KS(韩股)、2330.TW(台股)",
|
|
37
|
+
},
|
|
38
|
+
period: {
|
|
39
|
+
type: "string",
|
|
40
|
+
enum: ["daily", "weekly", "monthly"],
|
|
41
|
+
description: "K线周期,默认 daily",
|
|
42
|
+
},
|
|
43
|
+
count: {
|
|
44
|
+
type: "number",
|
|
45
|
+
description: "返回数据条数,默认 60",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
required: ["symbol"],
|
|
49
|
+
},
|
|
50
|
+
async execute(_id, { symbol, period = "daily", count = 60 }) {
|
|
51
|
+
const result = await py("stock_data.py", [
|
|
52
|
+
"kline",
|
|
53
|
+
symbol,
|
|
54
|
+
"--period",
|
|
55
|
+
period,
|
|
56
|
+
"--count",
|
|
57
|
+
String(count),
|
|
58
|
+
]);
|
|
59
|
+
return asText(result.stdout);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
pi.registerTool({
|
|
64
|
+
name: "get_quote",
|
|
65
|
+
description:
|
|
66
|
+
"获取股票实时行情报价。支持A股、港股、美股、日股、韩股、台股",
|
|
67
|
+
parameters: {
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
symbol: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description: "股票代码",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: ["symbol"],
|
|
76
|
+
},
|
|
77
|
+
async execute(_id, { symbol }) {
|
|
78
|
+
const result = await py("stock_data.py", ["quote", symbol]);
|
|
79
|
+
return asText(result.stdout);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
pi.registerTool({
|
|
84
|
+
name: "get_capital_flow",
|
|
85
|
+
description:
|
|
86
|
+
"获取A股资金流向数据。detail=个股每日明细,summary=多日汇总+趋势,sector_flow=板块资金流排行",
|
|
87
|
+
parameters: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
symbol: {
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "A股股票代码(detail/summary模式必填),如 600519",
|
|
93
|
+
},
|
|
94
|
+
mode: {
|
|
95
|
+
type: "string",
|
|
96
|
+
enum: ["detail", "summary", "sector_flow"],
|
|
97
|
+
description: "模式:detail=每日明细(默认),summary=多日汇总,sector_flow=板块排行",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
async execute(_id, { symbol = "", mode = "detail" }) {
|
|
102
|
+
const result = await py("stock_data.py", [
|
|
103
|
+
"capital_flow",
|
|
104
|
+
...(symbol ? [symbol] : []),
|
|
105
|
+
"--mode",
|
|
106
|
+
mode,
|
|
107
|
+
]);
|
|
108
|
+
return asText(result.stdout);
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
pi.registerTool({
|
|
113
|
+
name: "get_news",
|
|
114
|
+
description: "获取股票相关财经新闻",
|
|
115
|
+
parameters: {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
symbol: {
|
|
119
|
+
type: "string",
|
|
120
|
+
description: "股票代码",
|
|
121
|
+
},
|
|
122
|
+
days: {
|
|
123
|
+
type: "number",
|
|
124
|
+
description: "获取最近几天的新闻,默认 3",
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
required: ["symbol"],
|
|
128
|
+
},
|
|
129
|
+
async execute(_id, { symbol, days = 3 }) {
|
|
130
|
+
const result = await py("stock_data.py", ["news", symbol, "--days", String(days)]);
|
|
131
|
+
return asText(result.stdout);
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
pi.registerTool({
|
|
136
|
+
name: "get_financials",
|
|
137
|
+
description:
|
|
138
|
+
"获取股票关键财务指标(PE/PB/市值/营收/净利润/ROE等)",
|
|
139
|
+
parameters: {
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: {
|
|
142
|
+
symbol: {
|
|
143
|
+
type: "string",
|
|
144
|
+
description: "股票代码",
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
required: ["symbol"],
|
|
148
|
+
},
|
|
149
|
+
async execute(_id, { symbol }) {
|
|
150
|
+
const result = await py("stock_data.py", ["financials", symbol]);
|
|
151
|
+
return asText(result.stdout);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// --- Analysis Tools ---
|
|
156
|
+
|
|
157
|
+
pi.registerTool({
|
|
158
|
+
name: "get_technical_analysis",
|
|
159
|
+
description:
|
|
160
|
+
"获取股票技术面分析(MA/MACD/RSI/BOLL/KDJ/成交量等指标 + 100分综合评分 + 6级买卖信号 + 趋势/偏离度/支撑压力位)",
|
|
161
|
+
parameters: {
|
|
162
|
+
type: "object",
|
|
163
|
+
properties: {
|
|
164
|
+
symbol: {
|
|
165
|
+
type: "string",
|
|
166
|
+
description: "股票代码",
|
|
167
|
+
},
|
|
168
|
+
period: {
|
|
169
|
+
type: "string",
|
|
170
|
+
enum: ["daily", "weekly", "monthly"],
|
|
171
|
+
description: "分析周期,默认 daily",
|
|
172
|
+
},
|
|
173
|
+
count: {
|
|
174
|
+
type: "number",
|
|
175
|
+
description: "用于计算指标的K线条数,默认 120",
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
required: ["symbol"],
|
|
179
|
+
},
|
|
180
|
+
async execute(_id, { symbol, period = "daily", count = 120 }) {
|
|
181
|
+
const result = await py("technical.py", [
|
|
182
|
+
"analyze",
|
|
183
|
+
symbol,
|
|
184
|
+
"--period",
|
|
185
|
+
period,
|
|
186
|
+
"--count",
|
|
187
|
+
String(count),
|
|
188
|
+
]);
|
|
189
|
+
return asText(result.stdout);
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
pi.registerTool({
|
|
194
|
+
name: "analyze_pattern",
|
|
195
|
+
description:
|
|
196
|
+
"K线形态识别 — 检测十字星、锤子线、吞没、启明星、黄昏星、双底、20日突破等12+种经典形态",
|
|
197
|
+
parameters: {
|
|
198
|
+
type: "object",
|
|
199
|
+
properties: {
|
|
200
|
+
symbol: {
|
|
201
|
+
type: "string",
|
|
202
|
+
description: "股票代码",
|
|
203
|
+
},
|
|
204
|
+
period: {
|
|
205
|
+
type: "string",
|
|
206
|
+
enum: ["daily", "weekly", "monthly"],
|
|
207
|
+
description: "K线周期,默认 daily",
|
|
208
|
+
},
|
|
209
|
+
days: {
|
|
210
|
+
type: "number",
|
|
211
|
+
description: "分析的K线天数,默认 60",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
required: ["symbol"],
|
|
215
|
+
},
|
|
216
|
+
async execute(_id, { symbol, period = "daily", days = 60 }) {
|
|
217
|
+
const result = await py("pattern.py", [
|
|
218
|
+
"analyze",
|
|
219
|
+
symbol,
|
|
220
|
+
"--period",
|
|
221
|
+
period,
|
|
222
|
+
"--days",
|
|
223
|
+
String(days),
|
|
224
|
+
]);
|
|
225
|
+
return asText(result.stdout);
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// --- Market Tools ---
|
|
230
|
+
|
|
231
|
+
pi.registerTool({
|
|
232
|
+
name: "get_market_indices",
|
|
233
|
+
description:
|
|
234
|
+
"获取主要市场指数行情。CN: 上证/深证/创业板/科创50/沪深300;HK: 恒生/国企/科技;US: 道琼斯/纳斯达克/标普500;JP: 日经225/东证;KR: KOSPI/KOSDAQ;TW: 台湾加权",
|
|
235
|
+
parameters: {
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: {
|
|
238
|
+
region: {
|
|
239
|
+
type: "string",
|
|
240
|
+
enum: ["cn", "hk", "us", "jp", "kr", "tw"],
|
|
241
|
+
description: "市场区域,默认 cn",
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
async execute(_id, { region = "cn" }) {
|
|
246
|
+
const result = await py("stock_data.py", [
|
|
247
|
+
"market_indices",
|
|
248
|
+
"--region",
|
|
249
|
+
region,
|
|
250
|
+
]);
|
|
251
|
+
return asText(result.stdout);
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
pi.registerTool({
|
|
256
|
+
name: "get_sector_rankings",
|
|
257
|
+
description: "获取A股行业板块涨跌幅排行(含领涨股、涨跌家数等)。支持查看涨幅榜/跌幅榜/双向",
|
|
258
|
+
parameters: {
|
|
259
|
+
type: "object",
|
|
260
|
+
properties: {
|
|
261
|
+
top: {
|
|
262
|
+
type: "number",
|
|
263
|
+
description: "返回排名前N的板块,默认 10",
|
|
264
|
+
},
|
|
265
|
+
direction: {
|
|
266
|
+
type: "string",
|
|
267
|
+
enum: ["top", "bottom", "both"],
|
|
268
|
+
description: "top=涨幅榜(默认),bottom=跌幅榜,both=双向",
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
async execute(_id, { top = 10, direction = "top" }) {
|
|
273
|
+
const result = await py("stock_data.py", [
|
|
274
|
+
"sector_rankings",
|
|
275
|
+
"--top",
|
|
276
|
+
String(top),
|
|
277
|
+
"--direction",
|
|
278
|
+
direction,
|
|
279
|
+
]);
|
|
280
|
+
return asText(result.stdout);
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
pi.registerTool({
|
|
285
|
+
name: "get_stock_info",
|
|
286
|
+
description:
|
|
287
|
+
"获取股票基本信息(行业、板块、上市日期、总股本等)。A股返回板块/行业,其他市场返回行业/公司简介",
|
|
288
|
+
parameters: {
|
|
289
|
+
type: "object",
|
|
290
|
+
properties: {
|
|
291
|
+
symbol: {
|
|
292
|
+
type: "string",
|
|
293
|
+
description: "股票代码",
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
required: ["symbol"],
|
|
297
|
+
},
|
|
298
|
+
async execute(_id, { symbol }) {
|
|
299
|
+
const result = await py("stock_data.py", ["stock_info", symbol]);
|
|
300
|
+
return asText(result.stdout);
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
pi.registerTool({
|
|
305
|
+
name: "get_chip_distribution",
|
|
306
|
+
description:
|
|
307
|
+
"获取A股筹码分布数据(获利比例、平均成本、90%/70%成本集中度)。仅支持A股",
|
|
308
|
+
parameters: {
|
|
309
|
+
type: "object",
|
|
310
|
+
properties: {
|
|
311
|
+
symbol: {
|
|
312
|
+
type: "string",
|
|
313
|
+
description: "A股股票代码,如 600519",
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
required: ["symbol"],
|
|
317
|
+
},
|
|
318
|
+
async execute(_id, { symbol }) {
|
|
319
|
+
const result = await py("stock_data.py", ["chip_distribution", symbol]);
|
|
320
|
+
return asText(result.stdout);
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
pi.registerTool({
|
|
325
|
+
name: "get_market_stats",
|
|
326
|
+
description:
|
|
327
|
+
"获取A股市场整体统计(涨跌家数、涨停跌停数、平均涨幅、涨跌Top5、总成交额)",
|
|
328
|
+
parameters: {
|
|
329
|
+
type: "object",
|
|
330
|
+
properties: {
|
|
331
|
+
market: {
|
|
332
|
+
type: "string",
|
|
333
|
+
enum: ["A"],
|
|
334
|
+
description: "市场,目前仅支持 A",
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
async execute(_id, { market = "A" }) {
|
|
339
|
+
const result = await py("stock_data.py", ["market_stats", "--market", market]);
|
|
340
|
+
return asText(result.stdout);
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
pi.registerTool({
|
|
345
|
+
name: "get_fundamental_context",
|
|
346
|
+
description:
|
|
347
|
+
"获取A股深度基本面(估值PE/PB/PS + 成长性营收/净利增速 + 盈利能力ROE/毛利率 + 分红历史)",
|
|
348
|
+
parameters: {
|
|
349
|
+
type: "object",
|
|
350
|
+
properties: {
|
|
351
|
+
symbol: {
|
|
352
|
+
type: "string",
|
|
353
|
+
description: "A股股票代码,如 600519",
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
required: ["symbol"],
|
|
357
|
+
},
|
|
358
|
+
async execute(_id, { symbol }) {
|
|
359
|
+
const result = await py("stock_data.py", ["fundamental_context", symbol]);
|
|
360
|
+
return asText(result.stdout);
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// --- Screener & Backtest ---
|
|
365
|
+
|
|
366
|
+
pi.registerTool({
|
|
367
|
+
name: "screen_stocks",
|
|
368
|
+
description:
|
|
369
|
+
"全市场股票筛选(AlphaSift L1 多因子硬筛)。按PE/PB/市值/换手率/涨跌幅/量比等因子过滤和评分",
|
|
370
|
+
parameters: {
|
|
371
|
+
type: "object",
|
|
372
|
+
properties: {
|
|
373
|
+
market: {
|
|
374
|
+
type: "string",
|
|
375
|
+
enum: ["A", "HK", "US"],
|
|
376
|
+
description: "市场,默认 A",
|
|
377
|
+
},
|
|
378
|
+
top: {
|
|
379
|
+
type: "number",
|
|
380
|
+
description: "返回排名前N的股票,默认 20",
|
|
381
|
+
},
|
|
382
|
+
config: {
|
|
383
|
+
type: "string",
|
|
384
|
+
description: "自定义筛选配置YAML文件路径(可选)",
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
async execute(_id, { market = "A", top = 20, config }) {
|
|
389
|
+
const result = await py("screener.py", [
|
|
390
|
+
"screen",
|
|
391
|
+
"--market",
|
|
392
|
+
market,
|
|
393
|
+
"--top",
|
|
394
|
+
String(top),
|
|
395
|
+
...(config ? ["--config", config] : []),
|
|
396
|
+
]);
|
|
397
|
+
return asText(result.stdout);
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
pi.registerTool({
|
|
402
|
+
name: "run_backtest",
|
|
403
|
+
description:
|
|
404
|
+
"策略回测(AlphaEvo)。读取YAML策略定义,在历史数据上模拟交易,输出收益率/回撤/胜率等指标",
|
|
405
|
+
parameters: {
|
|
406
|
+
type: "object",
|
|
407
|
+
properties: {
|
|
408
|
+
strategy: {
|
|
409
|
+
type: "string",
|
|
410
|
+
description: "策略YAML文件路径",
|
|
411
|
+
},
|
|
412
|
+
symbol: {
|
|
413
|
+
type: "string",
|
|
414
|
+
description: "股票代码",
|
|
415
|
+
},
|
|
416
|
+
start: {
|
|
417
|
+
type: "string",
|
|
418
|
+
description: "回测起始日期,格式 YYYY-MM-DD",
|
|
419
|
+
},
|
|
420
|
+
end: {
|
|
421
|
+
type: "string",
|
|
422
|
+
description: "回测结束日期,格式 YYYY-MM-DD",
|
|
423
|
+
},
|
|
424
|
+
capital: {
|
|
425
|
+
type: "number",
|
|
426
|
+
description: "初始资金,默认 1000000",
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
required: ["strategy", "symbol"],
|
|
430
|
+
},
|
|
431
|
+
async execute(_id, { strategy, symbol, start, end, capital = 1000000 }) {
|
|
432
|
+
const result = await py("backtest.py", [
|
|
433
|
+
"run",
|
|
434
|
+
strategy,
|
|
435
|
+
symbol,
|
|
436
|
+
...(start ? ["--start", start] : []),
|
|
437
|
+
...(end ? ["--end", end] : []),
|
|
438
|
+
"--capital",
|
|
439
|
+
String(capital),
|
|
440
|
+
]);
|
|
441
|
+
return asText(result.stdout);
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
pi.registerTool({
|
|
446
|
+
name: "evaluate_signal",
|
|
447
|
+
description:
|
|
448
|
+
"技术信号历史准确率评估 — 回溯历史数据,统计某个技术信号触发后N日的胜率和平均收益。支持9种信号:macd_golden_cross/macd_death_cross/rsi_oversold/rsi_overbought/breakout_20d/breakdown_20d/volume_surge/ma_golden_cross/ma_death_cross",
|
|
449
|
+
parameters: {
|
|
450
|
+
type: "object",
|
|
451
|
+
properties: {
|
|
452
|
+
symbol: {
|
|
453
|
+
type: "string",
|
|
454
|
+
description: "股票代码",
|
|
455
|
+
},
|
|
456
|
+
signal: {
|
|
457
|
+
type: "string",
|
|
458
|
+
enum: [
|
|
459
|
+
"macd_golden_cross",
|
|
460
|
+
"macd_death_cross",
|
|
461
|
+
"rsi_oversold",
|
|
462
|
+
"rsi_overbought",
|
|
463
|
+
"breakout_20d",
|
|
464
|
+
"breakdown_20d",
|
|
465
|
+
"volume_surge",
|
|
466
|
+
"ma_golden_cross",
|
|
467
|
+
"ma_death_cross",
|
|
468
|
+
],
|
|
469
|
+
description: "信号名称",
|
|
470
|
+
},
|
|
471
|
+
forward_days: {
|
|
472
|
+
type: "string",
|
|
473
|
+
description: "逗号分隔的前瞻天数,默认 3,5,10",
|
|
474
|
+
},
|
|
475
|
+
lookback: {
|
|
476
|
+
type: "number",
|
|
477
|
+
description: "回溯K线条数,默认 250(约1年)",
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
required: ["symbol", "signal"],
|
|
481
|
+
},
|
|
482
|
+
async execute(_id, { symbol, signal, forward_days = "3,5,10", lookback = 250 }) {
|
|
483
|
+
const result = await py("backtest.py", [
|
|
484
|
+
"evaluate_signal",
|
|
485
|
+
symbol,
|
|
486
|
+
signal,
|
|
487
|
+
"--forward",
|
|
488
|
+
String(forward_days),
|
|
489
|
+
"--lookback",
|
|
490
|
+
String(lookback),
|
|
491
|
+
]);
|
|
492
|
+
return asText(result.stdout);
|
|
493
|
+
},
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
// --- Name Resolution ---
|
|
497
|
+
|
|
498
|
+
pi.registerTool({
|
|
499
|
+
name: "resolve_stock_name",
|
|
500
|
+
description:
|
|
501
|
+
"股票名称智能解析 — 输入中文名(贵州茅台)、拼音(guizhou maotai/gzmt)、部分代码,返回匹配的股票代码。仅支持A股",
|
|
502
|
+
parameters: {
|
|
503
|
+
type: "object",
|
|
504
|
+
properties: {
|
|
505
|
+
query: {
|
|
506
|
+
type: "string",
|
|
507
|
+
description: "股票名称、拼音、拼音首字母或部分代码",
|
|
508
|
+
},
|
|
509
|
+
top: {
|
|
510
|
+
type: "number",
|
|
511
|
+
description: "返回匹配数量,默认 5",
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
required: ["query"],
|
|
515
|
+
},
|
|
516
|
+
async execute(_id, { query, top = 5 }) {
|
|
517
|
+
const result = await py("name_resolver.py", [
|
|
518
|
+
"resolve",
|
|
519
|
+
query,
|
|
520
|
+
"--top",
|
|
521
|
+
String(top),
|
|
522
|
+
]);
|
|
523
|
+
return asText(result.stdout);
|
|
524
|
+
},
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
// --- Trading Calendar ---
|
|
528
|
+
|
|
529
|
+
pi.registerTool({
|
|
530
|
+
name: "check_trading_day",
|
|
531
|
+
description:
|
|
532
|
+
"查询某日是否为交易日。支持CN(A股)、HK(港股)、US(美股)、JP(日股)、KR(韩股)、TW(台股)",
|
|
533
|
+
parameters: {
|
|
534
|
+
type: "object",
|
|
535
|
+
properties: {
|
|
536
|
+
market: {
|
|
537
|
+
type: "string",
|
|
538
|
+
enum: ["CN", "HK", "US", "JP", "KR", "TW"],
|
|
539
|
+
description: "市场",
|
|
540
|
+
},
|
|
541
|
+
date: {
|
|
542
|
+
type: "string",
|
|
543
|
+
description: "日期(YYYY-MM-DD),不填则查今天",
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
required: ["market"],
|
|
547
|
+
},
|
|
548
|
+
async execute(_id, { market, date }) {
|
|
549
|
+
const result = await py("trading_calendar.py", [
|
|
550
|
+
"check",
|
|
551
|
+
market,
|
|
552
|
+
...(date ? ["--date", date] : []),
|
|
553
|
+
]);
|
|
554
|
+
return asText(result.stdout);
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
pi.registerTool({
|
|
559
|
+
name: "get_trading_days",
|
|
560
|
+
description:
|
|
561
|
+
"获取最近/未来N个交易日列表。支持CN/HK/US/JP/KR/TW",
|
|
562
|
+
parameters: {
|
|
563
|
+
type: "object",
|
|
564
|
+
properties: {
|
|
565
|
+
market: {
|
|
566
|
+
type: "string",
|
|
567
|
+
enum: ["CN", "HK", "US", "JP", "KR", "TW"],
|
|
568
|
+
description: "市场",
|
|
569
|
+
},
|
|
570
|
+
direction: {
|
|
571
|
+
type: "string",
|
|
572
|
+
enum: ["next", "prev"],
|
|
573
|
+
description: "next=未来交易日, prev=过去交易日",
|
|
574
|
+
},
|
|
575
|
+
count: {
|
|
576
|
+
type: "number",
|
|
577
|
+
description: "返回天数,默认 5",
|
|
578
|
+
},
|
|
579
|
+
date: {
|
|
580
|
+
type: "string",
|
|
581
|
+
description: "起始日期(YYYY-MM-DD),默认今天",
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
required: ["market"],
|
|
585
|
+
},
|
|
586
|
+
async execute(_id, { market, direction = "next", count = 5, date }) {
|
|
587
|
+
const result = await py("trading_calendar.py", [
|
|
588
|
+
direction,
|
|
589
|
+
market,
|
|
590
|
+
"--count",
|
|
591
|
+
String(count),
|
|
592
|
+
...(date ? ["--date", date] : []),
|
|
593
|
+
]);
|
|
594
|
+
return asText(result.stdout);
|
|
595
|
+
},
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// --- Standalone MA Calculator ---
|
|
599
|
+
|
|
600
|
+
pi.registerTool({
|
|
601
|
+
name: "calculate_ma",
|
|
602
|
+
description:
|
|
603
|
+
"独立均线计算器 — 支持任意周期MA(5/10/20/30/60/120/250或自定义)+ 偏离度 + 均线排列 + 金叉死叉检测",
|
|
604
|
+
parameters: {
|
|
605
|
+
type: "object",
|
|
606
|
+
properties: {
|
|
607
|
+
symbol: {
|
|
608
|
+
type: "string",
|
|
609
|
+
description: "股票代码",
|
|
610
|
+
},
|
|
611
|
+
periods: {
|
|
612
|
+
type: "string",
|
|
613
|
+
description: "逗号分隔的MA周期列表,如 5,10,20,60,120,250",
|
|
614
|
+
},
|
|
615
|
+
kline_period: {
|
|
616
|
+
type: "string",
|
|
617
|
+
enum: ["daily", "weekly", "monthly"],
|
|
618
|
+
description: "K线周期,默认 daily",
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
required: ["symbol"],
|
|
622
|
+
},
|
|
623
|
+
async execute(_id, { symbol, periods = "5,10,20,30,60,120,250", kline_period = "daily" }) {
|
|
624
|
+
const result = await py("technical.py", [
|
|
625
|
+
"calculate_ma",
|
|
626
|
+
symbol,
|
|
627
|
+
"--periods",
|
|
628
|
+
periods,
|
|
629
|
+
"--period",
|
|
630
|
+
kline_period,
|
|
631
|
+
"--count",
|
|
632
|
+
"300",
|
|
633
|
+
]);
|
|
634
|
+
return asText(result.stdout);
|
|
635
|
+
},
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
// --- Volume-Price Analysis ---
|
|
639
|
+
|
|
640
|
+
pi.registerTool({
|
|
641
|
+
name: "get_volume_analysis",
|
|
642
|
+
description:
|
|
643
|
+
"独立量价分析 — 量价相关性、上涨/下跌日成交量对比、量能趋势、量价模式解读(放量上涨/缩量回调等)",
|
|
644
|
+
parameters: {
|
|
645
|
+
type: "object",
|
|
646
|
+
properties: {
|
|
647
|
+
symbol: {
|
|
648
|
+
type: "string",
|
|
649
|
+
description: "股票代码",
|
|
650
|
+
},
|
|
651
|
+
period: {
|
|
652
|
+
type: "string",
|
|
653
|
+
enum: ["daily", "weekly", "monthly"],
|
|
654
|
+
description: "K线周期,默认 daily",
|
|
655
|
+
},
|
|
656
|
+
count: {
|
|
657
|
+
type: "number",
|
|
658
|
+
description: "分析K线条数,默认 60",
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
required: ["symbol"],
|
|
662
|
+
},
|
|
663
|
+
async execute(_id, { symbol, period = "daily", count = 60 }) {
|
|
664
|
+
const result = await py("volume_analysis.py", [
|
|
665
|
+
"analyze",
|
|
666
|
+
symbol,
|
|
667
|
+
"--period",
|
|
668
|
+
period,
|
|
669
|
+
"--count",
|
|
670
|
+
String(count),
|
|
671
|
+
]);
|
|
672
|
+
return asText(result.stdout);
|
|
673
|
+
},
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
// --- Search Intelligence ---
|
|
677
|
+
|
|
678
|
+
pi.registerTool({
|
|
679
|
+
name: "search_stock_news",
|
|
680
|
+
description:
|
|
681
|
+
"多引擎股票新闻搜索(支持 Tavily/Brave/SerpAPI)。需配置对应 API Key 环境变量",
|
|
682
|
+
parameters: {
|
|
683
|
+
type: "object",
|
|
684
|
+
properties: {
|
|
685
|
+
query: {
|
|
686
|
+
type: "string",
|
|
687
|
+
description: "搜索关键词",
|
|
688
|
+
},
|
|
689
|
+
count: {
|
|
690
|
+
type: "number",
|
|
691
|
+
description: "返回结果数量,默认 10",
|
|
692
|
+
},
|
|
693
|
+
},
|
|
694
|
+
required: ["query"],
|
|
695
|
+
},
|
|
696
|
+
async execute(_id, { query, count = 10 }) {
|
|
697
|
+
const result = await py("search_intel.py", [
|
|
698
|
+
"search",
|
|
699
|
+
query,
|
|
700
|
+
"--count",
|
|
701
|
+
String(count),
|
|
702
|
+
]);
|
|
703
|
+
return asText(result.stdout);
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
pi.registerTool({
|
|
708
|
+
name: "search_comprehensive_intel",
|
|
709
|
+
description:
|
|
710
|
+
"股票综合情报搜索 — 从6个维度(新闻/公告/行情分析/风险/业绩/行业)搜索综合信息",
|
|
711
|
+
parameters: {
|
|
712
|
+
type: "object",
|
|
713
|
+
properties: {
|
|
714
|
+
symbol: {
|
|
715
|
+
type: "string",
|
|
716
|
+
description: "股票代码",
|
|
717
|
+
},
|
|
718
|
+
name: {
|
|
719
|
+
type: "string",
|
|
720
|
+
description: "股票名称(可选,提升搜索准确度)",
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
required: ["symbol"],
|
|
724
|
+
},
|
|
725
|
+
async execute(_id, { symbol, name }) {
|
|
726
|
+
const result = await py("search_intel.py", [
|
|
727
|
+
"comprehensive",
|
|
728
|
+
symbol,
|
|
729
|
+
...(name ? ["--name", name] : []),
|
|
730
|
+
]);
|
|
731
|
+
return asText(result.stdout);
|
|
732
|
+
},
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
pi.registerTool({
|
|
736
|
+
name: "get_social_sentiment",
|
|
737
|
+
description:
|
|
738
|
+
"获取股票社交媒体情绪数据(Reddit/X/Polymarket)。主要支持美股。需配置 SENTIMENT_API_KEY",
|
|
739
|
+
parameters: {
|
|
740
|
+
type: "object",
|
|
741
|
+
properties: {
|
|
742
|
+
symbol: {
|
|
743
|
+
type: "string",
|
|
744
|
+
description: "股票代码(如 AAPL)",
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
required: ["symbol"],
|
|
748
|
+
},
|
|
749
|
+
async execute(_id, { symbol }) {
|
|
750
|
+
const result = await py("search_intel.py", ["sentiment", symbol]);
|
|
751
|
+
return asText(result.stdout);
|
|
752
|
+
},
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
pi.registerTool({
|
|
756
|
+
name: "get_trending_sentiment",
|
|
757
|
+
description:
|
|
758
|
+
"获取社交媒体热门趋势(Reddit/X/Polymarket热门股票讨论)。数据缓存10分钟。适用于发现市场热点",
|
|
759
|
+
parameters: {
|
|
760
|
+
type: "object",
|
|
761
|
+
properties: {},
|
|
762
|
+
},
|
|
763
|
+
async execute() {
|
|
764
|
+
const result = await py("search_intel.py", ["trending"]);
|
|
765
|
+
return asText(result.stdout);
|
|
766
|
+
},
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
pi.registerTool({
|
|
770
|
+
name: "extract_article",
|
|
771
|
+
description:
|
|
772
|
+
"网页文章全文提取 — 输入URL,提取文章标题、正文(最多3000字)、作者、发布日期等。适用于深度阅读搜索结果中的新闻/研报",
|
|
773
|
+
parameters: {
|
|
774
|
+
type: "object",
|
|
775
|
+
properties: {
|
|
776
|
+
url: {
|
|
777
|
+
type: "string",
|
|
778
|
+
description: "文章URL",
|
|
779
|
+
},
|
|
780
|
+
},
|
|
781
|
+
required: ["url"],
|
|
782
|
+
},
|
|
783
|
+
async execute(_id, { url }) {
|
|
784
|
+
const result = await py("search_intel.py", ["extract", url]);
|
|
785
|
+
return asText(result.stdout);
|
|
786
|
+
},
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
pi.registerTool({
|
|
790
|
+
name: "screen_risk",
|
|
791
|
+
description:
|
|
792
|
+
"风险专项筛查 — 7维度风险检测(估值极端/技术预警/解禁到期/内部人减持/业绩预警/监管处罚/行业政策),返回风险评级和一票否决标记",
|
|
793
|
+
parameters: {
|
|
794
|
+
type: "object",
|
|
795
|
+
properties: {
|
|
796
|
+
symbol: {
|
|
797
|
+
type: "string",
|
|
798
|
+
description: "股票代码(如 600519)",
|
|
799
|
+
},
|
|
800
|
+
name: {
|
|
801
|
+
type: "string",
|
|
802
|
+
description: "股票名称(可选,提升新闻搜索准确度)",
|
|
803
|
+
},
|
|
804
|
+
},
|
|
805
|
+
required: ["symbol"],
|
|
806
|
+
},
|
|
807
|
+
async execute(_id, { symbol, name }) {
|
|
808
|
+
const result = await py("risk_screening.py", [
|
|
809
|
+
"screen",
|
|
810
|
+
symbol,
|
|
811
|
+
...(name ? ["--name", name] : []),
|
|
812
|
+
]);
|
|
813
|
+
return asText(result.stdout);
|
|
814
|
+
},
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
pi.registerTool({
|
|
818
|
+
name: "detect_market_regime",
|
|
819
|
+
description:
|
|
820
|
+
"市场状态检测 — 分析大盘指数判断当前市场阶段(上涨趋势/下跌趋势/横盘震荡/高波动/板块热点),并推荐适合的分析策略",
|
|
821
|
+
parameters: {
|
|
822
|
+
type: "object",
|
|
823
|
+
properties: {
|
|
824
|
+
market: {
|
|
825
|
+
type: "string",
|
|
826
|
+
enum: ["A", "HK", "US"],
|
|
827
|
+
description: "市场代码,默认 A",
|
|
828
|
+
},
|
|
829
|
+
},
|
|
830
|
+
},
|
|
831
|
+
async execute(_id, { market }) {
|
|
832
|
+
const m = market || "A";
|
|
833
|
+
const result = await py("market_regime.py", ["detect", m]);
|
|
834
|
+
return asText(result.stdout);
|
|
835
|
+
},
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
pi.registerTool({
|
|
839
|
+
name: "get_market_review",
|
|
840
|
+
description:
|
|
841
|
+
"大盘复盘 — 获取市场日度复盘数据,包含指数、涨跌统计、板块排名、新闻、市场温度与策略建议",
|
|
842
|
+
parameters: {
|
|
843
|
+
type: "object",
|
|
844
|
+
properties: {
|
|
845
|
+
market: {
|
|
846
|
+
type: "string",
|
|
847
|
+
enum: ["A", "HK", "US", "all"],
|
|
848
|
+
description: "市场代码,默认 A。all 表示所有市场",
|
|
849
|
+
},
|
|
850
|
+
},
|
|
851
|
+
},
|
|
852
|
+
async execute(_id, { market }) {
|
|
853
|
+
const m = market || "A";
|
|
854
|
+
const result = await py("market_review.py", ["review", "--market", m]);
|
|
855
|
+
return asText(result.stdout);
|
|
856
|
+
},
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
pi.registerTool({
|
|
860
|
+
name: "run_watchlist_analysis",
|
|
861
|
+
description:
|
|
862
|
+
"批量自选股分析 — 对多只股票并行采集行情/技术/资金/风险等数据,返回汇总结果。适用于每日定时分析自选股列表",
|
|
863
|
+
parameters: {
|
|
864
|
+
type: "object",
|
|
865
|
+
properties: {
|
|
866
|
+
symbols: {
|
|
867
|
+
type: "string",
|
|
868
|
+
description: "逗号分隔的股票代码列表,如 600519,000001,300750",
|
|
869
|
+
},
|
|
870
|
+
workers: {
|
|
871
|
+
type: "number",
|
|
872
|
+
description: "并发数,默认 3(建议不超过5,避免API限流)",
|
|
873
|
+
},
|
|
874
|
+
},
|
|
875
|
+
required: ["symbols"],
|
|
876
|
+
},
|
|
877
|
+
async execute(_id, { symbols, workers = 3 }) {
|
|
878
|
+
const result = await py("watchlist.py", [
|
|
879
|
+
"analyze",
|
|
880
|
+
symbols,
|
|
881
|
+
"--workers",
|
|
882
|
+
String(workers),
|
|
883
|
+
]);
|
|
884
|
+
return asText(result.stdout);
|
|
885
|
+
},
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
pi.registerTool({
|
|
889
|
+
name: "detect_anomaly",
|
|
890
|
+
description:
|
|
891
|
+
"异常/事件检测 — 一键扫描股票当前所有异动信号(MACD金叉死叉、RSI超买超卖、20日突破、放量异动、涨跌停、布林突破、KDJ极值、资金异动等),返回结构化异常列表",
|
|
892
|
+
parameters: {
|
|
893
|
+
type: "object",
|
|
894
|
+
properties: {
|
|
895
|
+
symbol: {
|
|
896
|
+
type: "string",
|
|
897
|
+
description: "股票代码(如 600519、AAPL、00700.HK)",
|
|
898
|
+
},
|
|
899
|
+
},
|
|
900
|
+
required: ["symbol"],
|
|
901
|
+
},
|
|
902
|
+
async execute(_id, { symbol }) {
|
|
903
|
+
const result = await py("anomaly_detect.py", ["detect", symbol]);
|
|
904
|
+
return asText(result.stdout);
|
|
905
|
+
},
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
// --- Diagnostics & Capabilities ---
|
|
909
|
+
|
|
910
|
+
pi.registerTool({
|
|
911
|
+
name: "diagnose_data_sources",
|
|
912
|
+
description:
|
|
913
|
+
"数据源诊断 — 检查当前环境可用的数据 provider(akshare/tushare/yfinance/finnhub/longbridge/alphavantage),输出每个市场的可用链路、缺失 env、warnings。用于让 agent 自解释为何拿不到数据",
|
|
914
|
+
parameters: {
|
|
915
|
+
type: "object",
|
|
916
|
+
properties: {
|
|
917
|
+
market: {
|
|
918
|
+
type: "string",
|
|
919
|
+
enum: ["A", "HK", "US", "JP", "KR", "TW", "all"],
|
|
920
|
+
description: "市场,默认 all",
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
},
|
|
924
|
+
async execute(_id, { market = "all" }) {
|
|
925
|
+
const result = await py("diagnostics.py", ["check", "--market", market]);
|
|
926
|
+
return asText(result.stdout);
|
|
927
|
+
},
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
pi.registerTool({
|
|
931
|
+
name: "get_market_capabilities",
|
|
932
|
+
description:
|
|
933
|
+
"市场能力边界 — 返回指定市场支持/不支持的工具列表,避免 agent 对港股调 get_chip_distribution 或对美股调 get_capital_flow 后编造数据",
|
|
934
|
+
parameters: {
|
|
935
|
+
type: "object",
|
|
936
|
+
properties: {
|
|
937
|
+
market: { type: "string", enum: ["A", "HK", "US", "JP", "KR", "TW"], description: "市场代码" },
|
|
938
|
+
symbol: { type: "string", description: "股票代码(自动识别市场,与 market 二选一)" },
|
|
939
|
+
},
|
|
940
|
+
},
|
|
941
|
+
async execute(_id, { market, symbol }) {
|
|
942
|
+
const args = symbol
|
|
943
|
+
? ["get", "--symbol", symbol]
|
|
944
|
+
: ["get", "--market", market || "A"];
|
|
945
|
+
const result = await py("capabilities.py", args);
|
|
946
|
+
return asText(result.stdout);
|
|
947
|
+
},
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
// --- Report Rendering ---
|
|
951
|
+
|
|
952
|
+
pi.registerTool({
|
|
953
|
+
name: "render_stock_report",
|
|
954
|
+
description:
|
|
955
|
+
"股票分析报告渲染 — 将结构化 JSON(符合 schemas/report_schema.json)通过 j2 模板渲染为 Markdown。style: brief|full。仅渲染,不保存不推送",
|
|
956
|
+
parameters: {
|
|
957
|
+
type: "object",
|
|
958
|
+
properties: {
|
|
959
|
+
report: {
|
|
960
|
+
type: "object",
|
|
961
|
+
description: "结构化股票报告,字段参考 schemas/report_schema.json",
|
|
962
|
+
},
|
|
963
|
+
template: {
|
|
964
|
+
type: "string",
|
|
965
|
+
enum: ["brief", "full"],
|
|
966
|
+
description: "模板类型,默认 full",
|
|
967
|
+
},
|
|
968
|
+
},
|
|
969
|
+
required: ["report"],
|
|
970
|
+
},
|
|
971
|
+
async execute(_id, { report, template = "full" }) {
|
|
972
|
+
const b64 = Buffer.from(JSON.stringify(report), "utf-8").toString("base64");
|
|
973
|
+
const result = await py("report_renderer.py", [
|
|
974
|
+
"stock",
|
|
975
|
+
"--template",
|
|
976
|
+
template,
|
|
977
|
+
"--input-b64",
|
|
978
|
+
b64,
|
|
979
|
+
]);
|
|
980
|
+
return asText(result.stdout);
|
|
981
|
+
},
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
pi.registerTool({
|
|
985
|
+
name: "render_market_report",
|
|
986
|
+
description:
|
|
987
|
+
"大盘复盘报告渲染 — 将结构化 JSON(符合 schemas/market_review_schema.json)通过 j2 模板渲染为 Markdown",
|
|
988
|
+
parameters: {
|
|
989
|
+
type: "object",
|
|
990
|
+
properties: {
|
|
991
|
+
report: { type: "object", description: "结构化市场复盘" },
|
|
992
|
+
template: { type: "string", enum: ["full"], description: "模板类型,默认 full" },
|
|
993
|
+
},
|
|
994
|
+
required: ["report"],
|
|
995
|
+
},
|
|
996
|
+
async execute(_id, { report, template = "full" }) {
|
|
997
|
+
const b64 = Buffer.from(JSON.stringify(report), "utf-8").toString("base64");
|
|
998
|
+
const result = await py("report_renderer.py", [
|
|
999
|
+
"market",
|
|
1000
|
+
"--template",
|
|
1001
|
+
template,
|
|
1002
|
+
"--input-b64",
|
|
1003
|
+
b64,
|
|
1004
|
+
]);
|
|
1005
|
+
return asText(result.stdout);
|
|
1006
|
+
},
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
// --- Watchlist / Position / Alert Context ---
|
|
1010
|
+
|
|
1011
|
+
pi.registerTool({
|
|
1012
|
+
name: "build_watchlist_context",
|
|
1013
|
+
description:
|
|
1014
|
+
"自选股上下文包 — 对多只股票输出评分/趋势/异常/风险/建议 next_tools 的 agent 友好摘要。宿主 agent 决定如何写日报或深入分析",
|
|
1015
|
+
parameters: {
|
|
1016
|
+
type: "object",
|
|
1017
|
+
properties: {
|
|
1018
|
+
symbols: { type: "string", description: "逗号分隔的股票代码列表" },
|
|
1019
|
+
include_market_review: {
|
|
1020
|
+
type: "boolean",
|
|
1021
|
+
description: "是否附带各市场复盘,默认 false",
|
|
1022
|
+
},
|
|
1023
|
+
workers: { type: "number", description: "并发数,默认 3" },
|
|
1024
|
+
},
|
|
1025
|
+
required: ["symbols"],
|
|
1026
|
+
},
|
|
1027
|
+
async execute(_id, { symbols, include_market_review = false, workers = 3 }) {
|
|
1028
|
+
const result = await py("watchlist_context.py", [
|
|
1029
|
+
"build",
|
|
1030
|
+
symbols,
|
|
1031
|
+
"--workers",
|
|
1032
|
+
String(workers),
|
|
1033
|
+
...(include_market_review ? ["--include-market-review"] : []),
|
|
1034
|
+
]);
|
|
1035
|
+
return asText(result.stdout);
|
|
1036
|
+
},
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
pi.registerTool({
|
|
1040
|
+
name: "analyze_position_context",
|
|
1041
|
+
description:
|
|
1042
|
+
"持仓上下文分析 — 输入成本/仓位/止损止盈,结合现价和技术位输出浮盈亏、离止损距离、风险级别、操作建议。无状态、不存账户",
|
|
1043
|
+
parameters: {
|
|
1044
|
+
type: "object",
|
|
1045
|
+
properties: {
|
|
1046
|
+
symbol: { type: "string", description: "股票代码" },
|
|
1047
|
+
cost: { type: "number", description: "成本价" },
|
|
1048
|
+
quantity: { type: "number", description: "持仓数量" },
|
|
1049
|
+
stop_loss: { type: "number", description: "止损价(可选)" },
|
|
1050
|
+
take_profit: { type: "number", description: "止盈价(可选)" },
|
|
1051
|
+
},
|
|
1052
|
+
required: ["symbol", "cost", "quantity"],
|
|
1053
|
+
},
|
|
1054
|
+
async execute(_id, { symbol, cost, quantity, stop_loss, take_profit }) {
|
|
1055
|
+
const result = await py("position_context.py", [
|
|
1056
|
+
"analyze",
|
|
1057
|
+
symbol,
|
|
1058
|
+
"--cost",
|
|
1059
|
+
String(cost),
|
|
1060
|
+
"--quantity",
|
|
1061
|
+
String(quantity),
|
|
1062
|
+
...(stop_loss !== undefined ? ["--stop-loss", String(stop_loss)] : []),
|
|
1063
|
+
...(take_profit !== undefined ? ["--take-profit", String(take_profit)] : []),
|
|
1064
|
+
]);
|
|
1065
|
+
return asText(result.stdout);
|
|
1066
|
+
},
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
pi.registerTool({
|
|
1070
|
+
name: "check_alert_rules",
|
|
1071
|
+
description:
|
|
1072
|
+
"无状态告警规则检查 — 传入规则数组,返回当前是否触发。规则类型:price_below/price_above/change_pct_above/change_pct_below/volume_ratio_above/anomaly/risk_veto/risk_level_at_least。不做调度不存历史",
|
|
1073
|
+
parameters: {
|
|
1074
|
+
type: "object",
|
|
1075
|
+
properties: {
|
|
1076
|
+
symbol: { type: "string", description: "股票代码" },
|
|
1077
|
+
rules: {
|
|
1078
|
+
type: "array",
|
|
1079
|
+
description: "规则列表,每项 { type, value }",
|
|
1080
|
+
items: {
|
|
1081
|
+
type: "object",
|
|
1082
|
+
properties: {
|
|
1083
|
+
type: { type: "string" },
|
|
1084
|
+
value: {},
|
|
1085
|
+
},
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
},
|
|
1089
|
+
required: ["symbol", "rules"],
|
|
1090
|
+
},
|
|
1091
|
+
async execute(_id, { symbol, rules }) {
|
|
1092
|
+
const b64 = Buffer.from(JSON.stringify(rules), "utf-8").toString("base64");
|
|
1093
|
+
const result = await py("alert_rules.py", ["check", symbol, "--rules-b64", b64]);
|
|
1094
|
+
return asText(result.stdout);
|
|
1095
|
+
},
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1098
|
+
pi.registerTool({
|
|
1099
|
+
name: "parse_stock_list",
|
|
1100
|
+
description:
|
|
1101
|
+
"自选股/文本导入解析 — 从自然语言、CSV、Markdown 表格提取股票,自动识别 A 股 6 位代码、港股 xxxxx.HK、美股 ticker、日股 xxxx.T、韩股 xxxxxx.KS/KQ、台股 xxxx.TW,并调用 name_resolver 处理中文股票名",
|
|
1102
|
+
parameters: {
|
|
1103
|
+
type: "object",
|
|
1104
|
+
properties: {
|
|
1105
|
+
text: { type: "string", description: "待解析的文本" },
|
|
1106
|
+
},
|
|
1107
|
+
required: ["text"],
|
|
1108
|
+
},
|
|
1109
|
+
async execute(_id, { text }) {
|
|
1110
|
+
const b64 = Buffer.from(String(text), "utf-8").toString("base64");
|
|
1111
|
+
const result = await py("import_parser.py", ["parse", "--text-b64", b64]);
|
|
1112
|
+
return asText(result.stdout);
|
|
1113
|
+
},
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
// --- Skill Discovery ---
|
|
1117
|
+
|
|
1118
|
+
pi.on("resources_discover", () => ({
|
|
1119
|
+
skillPaths: [
|
|
1120
|
+
`${baseDir}/skills/stock-analysis/SKILL.md`,
|
|
1121
|
+
`${baseDir}/skills/stock-screener/SKILL.md`,
|
|
1122
|
+
`${baseDir}/skills/strategy-backtest/SKILL.md`,
|
|
1123
|
+
`${baseDir}/skills/bull-trend/SKILL.md`,
|
|
1124
|
+
`${baseDir}/skills/shrink-pullback/SKILL.md`,
|
|
1125
|
+
`${baseDir}/skills/ma-crossover/SKILL.md`,
|
|
1126
|
+
`${baseDir}/skills/volume-breakout/SKILL.md`,
|
|
1127
|
+
`${baseDir}/skills/bottom-volume/SKILL.md`,
|
|
1128
|
+
`${baseDir}/skills/dragon-head/SKILL.md`,
|
|
1129
|
+
`${baseDir}/skills/chan-theory/SKILL.md`,
|
|
1130
|
+
`${baseDir}/skills/wave-theory/SKILL.md`,
|
|
1131
|
+
`${baseDir}/skills/box-oscillation/SKILL.md`,
|
|
1132
|
+
`${baseDir}/skills/emotion-cycle/SKILL.md`,
|
|
1133
|
+
`${baseDir}/skills/one-yang-three-yin/SKILL.md`,
|
|
1134
|
+
`${baseDir}/skills/wisburg-research/SKILL.md`,
|
|
1135
|
+
`${baseDir}/skills/market-review/SKILL.md`,
|
|
1136
|
+
`${baseDir}/skills/event-driven/SKILL.md`,
|
|
1137
|
+
`${baseDir}/skills/expectation-repricing/SKILL.md`,
|
|
1138
|
+
`${baseDir}/skills/growth-quality/SKILL.md`,
|
|
1139
|
+
`${baseDir}/skills/hot-theme/SKILL.md`,
|
|
1140
|
+
],
|
|
1141
|
+
}));
|
|
1142
|
+
};
|