@weaxs/openclaw-stock-analysis 0.1.3
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 +70 -0
- package/index.ts +761 -0
- package/openclaw.plugin.json +47 -0
- package/package.json +46 -0
- package/schemas/report_schema.json +131 -0
- package/scripts/setup-python.mjs +52 -0
- package/skills/bottom-volume/SKILL.md +63 -0
- package/skills/bottom-volume/scripts/gather.py +15 -0
- package/skills/box-oscillation/SKILL.md +72 -0
- package/skills/box-oscillation/scripts/gather.py +15 -0
- package/skills/bull-trend/SKILL.md +60 -0
- package/skills/bull-trend/scripts/gather.py +15 -0
- package/skills/chan-theory/SKILL.md +71 -0
- package/skills/chan-theory/scripts/gather.py +15 -0
- package/skills/dragon-head/SKILL.md +69 -0
- package/skills/dragon-head/scripts/gather.py +15 -0
- package/skills/emotion-cycle/SKILL.md +65 -0
- package/skills/emotion-cycle/scripts/gather.py +15 -0
- package/skills/event-driven/SKILL.md +73 -0
- package/skills/event-driven/scripts/gather.py +15 -0
- package/skills/expectation-repricing/SKILL.md +72 -0
- package/skills/expectation-repricing/scripts/gather.py +15 -0
- package/skills/growth-quality/SKILL.md +74 -0
- package/skills/growth-quality/scripts/gather.py +15 -0
- package/skills/hot-theme/SKILL.md +74 -0
- package/skills/hot-theme/scripts/gather.py +15 -0
- package/skills/ma-crossover/SKILL.md +63 -0
- package/skills/ma-crossover/scripts/gather.py +15 -0
- package/skills/market-review/SKILL.md +70 -0
- package/skills/market-review/scripts/gather.py +16 -0
- package/skills/one-yang-three-yin/SKILL.md +74 -0
- package/skills/one-yang-three-yin/scripts/gather.py +15 -0
- package/skills/shrink-pullback/SKILL.md +59 -0
- package/skills/shrink-pullback/scripts/gather.py +15 -0
- package/skills/stock-analysis/SKILL.md +134 -0
- package/skills/stock-analysis/scripts/gather.py +15 -0
- package/skills/stock-screener/SKILL.md +68 -0
- package/skills/stock-screener/scripts/gather.py +15 -0
- package/skills/strategy-backtest/SKILL.md +129 -0
- package/skills/strategy-backtest/scripts/gather.py +16 -0
- package/skills/volume-breakout/SKILL.md +58 -0
- package/skills/volume-breakout/scripts/gather.py +15 -0
- package/skills/wave-theory/SKILL.md +67 -0
- package/skills/wave-theory/scripts/gather.py +15 -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/tools/__init__.py +0 -0
- package/tools/anomaly_detect.py +570 -0
- package/tools/backtest.py +643 -0
- package/tools/gather.py +152 -0
- package/tools/market_regime.py +247 -0
- package/tools/market_review.py +150 -0
- package/tools/name_resolver.py +131 -0
- package/tools/pattern.py +509 -0
- package/tools/requirements.txt +13 -0
- package/tools/risk_screening.py +318 -0
- package/tools/screener.py +213 -0
- package/tools/search_intel.py +455 -0
- package/tools/stock_data.py +1649 -0
- package/tools/technical.py +636 -0
- package/tools/trading_calendar.py +198 -0
- package/tools/volume_analysis.py +172 -0
- package/tools/watchlist.py +61 -0
package/index.ts
ADDED
|
@@ -0,0 +1,761 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import * as cp from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { Type } from "typebox";
|
|
7
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
8
|
+
|
|
9
|
+
// Indirected so tests can replace the executor without touching node:child_process.
|
|
10
|
+
type Executor = (bin: string, argv: string[]) => Promise<string>;
|
|
11
|
+
|
|
12
|
+
const defaultExecutor: Executor = async (bin, argv) => {
|
|
13
|
+
const exec = promisify(cp.execFile);
|
|
14
|
+
const { stdout } = await exec(bin, argv, { maxBuffer: 32 * 1024 * 1024 });
|
|
15
|
+
return stdout;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let executor: Executor = defaultExecutor;
|
|
19
|
+
export function __setExecutor(fn: Executor) {
|
|
20
|
+
executor = fn;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
// Published form: tools/ ships next to index.ts. Dev form: tools/ is at repo root.
|
|
25
|
+
const toolsDir = existsSync(join(here, "tools"))
|
|
26
|
+
? join(here, "tools")
|
|
27
|
+
: join(here, "..", "tools");
|
|
28
|
+
const repoRoot = dirname(toolsDir);
|
|
29
|
+
const isWin = process.platform === "win32";
|
|
30
|
+
const venvPython = join(repoRoot, ".venv", isWin ? "Scripts" : "bin", "python3");
|
|
31
|
+
|
|
32
|
+
function pythonBin(): string {
|
|
33
|
+
return existsSync(venvPython) ? venvPython : "python3";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function runPy(script: string, args: string[]): Promise<string> {
|
|
37
|
+
return executor(pythonBin(), [join(toolsDir, script), ...args]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function asText(text: string) {
|
|
41
|
+
return { content: [{ type: "text" as const, text }] };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default definePluginEntry({
|
|
45
|
+
id: "stock-analysis",
|
|
46
|
+
name: "Stock Analysis",
|
|
47
|
+
description:
|
|
48
|
+
"Stock analysis, screening, and strategy backtesting across A/HK/US markets",
|
|
49
|
+
register(api) {
|
|
50
|
+
// --- Data Tools ---
|
|
51
|
+
|
|
52
|
+
api.registerTool({
|
|
53
|
+
name: "get_kline",
|
|
54
|
+
description:
|
|
55
|
+
"获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)",
|
|
56
|
+
parameters: Type.Object({
|
|
57
|
+
symbol: Type.String({
|
|
58
|
+
description: "股票代码,如 600519(A股)、00700.HK(港股)、AAPL(美股)",
|
|
59
|
+
}),
|
|
60
|
+
period: Type.Optional(
|
|
61
|
+
Type.Union(
|
|
62
|
+
[Type.Literal("daily"), Type.Literal("weekly"), Type.Literal("monthly")],
|
|
63
|
+
{ description: "K线周期,默认 daily" }
|
|
64
|
+
)
|
|
65
|
+
),
|
|
66
|
+
count: Type.Optional(Type.Number({ description: "返回数据条数,默认 60" })),
|
|
67
|
+
}),
|
|
68
|
+
async execute(_id, params) {
|
|
69
|
+
const out = await runPy("stock_data.py", [
|
|
70
|
+
"kline",
|
|
71
|
+
params.symbol,
|
|
72
|
+
"--period",
|
|
73
|
+
params.period ?? "daily",
|
|
74
|
+
"--count",
|
|
75
|
+
String(params.count ?? 60),
|
|
76
|
+
]);
|
|
77
|
+
return asText(out);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
api.registerTool({
|
|
82
|
+
name: "get_quote",
|
|
83
|
+
description: "获取股票实时行情报价。支持A股、港股、美股",
|
|
84
|
+
parameters: Type.Object({
|
|
85
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
86
|
+
}),
|
|
87
|
+
async execute(_id, params) {
|
|
88
|
+
const out = await runPy("stock_data.py", ["quote", params.symbol]);
|
|
89
|
+
return asText(out);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
api.registerTool({
|
|
94
|
+
name: "get_capital_flow",
|
|
95
|
+
description:
|
|
96
|
+
"获取A股资金流向数据。detail=个股每日明细,summary=多日汇总+趋势,sector_flow=板块资金流排行",
|
|
97
|
+
parameters: Type.Object({
|
|
98
|
+
symbol: Type.Optional(
|
|
99
|
+
Type.String({ description: "A股股票代码(detail/summary模式必填),如 600519" })
|
|
100
|
+
),
|
|
101
|
+
mode: Type.Optional(
|
|
102
|
+
Type.Union(
|
|
103
|
+
[
|
|
104
|
+
Type.Literal("detail"),
|
|
105
|
+
Type.Literal("summary"),
|
|
106
|
+
Type.Literal("sector_flow"),
|
|
107
|
+
],
|
|
108
|
+
{ description: "模式:detail=每日明细(默认),summary=多日汇总,sector_flow=板块排行" }
|
|
109
|
+
)
|
|
110
|
+
),
|
|
111
|
+
}),
|
|
112
|
+
async execute(_id, params) {
|
|
113
|
+
const args = ["capital_flow"];
|
|
114
|
+
if (params.symbol) args.push(params.symbol);
|
|
115
|
+
args.push("--mode", params.mode ?? "detail");
|
|
116
|
+
const out = await runPy("stock_data.py", args);
|
|
117
|
+
return asText(out);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
api.registerTool({
|
|
122
|
+
name: "get_news",
|
|
123
|
+
description: "获取股票相关财经新闻",
|
|
124
|
+
parameters: Type.Object({
|
|
125
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
126
|
+
days: Type.Optional(
|
|
127
|
+
Type.Number({ description: "获取最近几天的新闻,默认 3" })
|
|
128
|
+
),
|
|
129
|
+
}),
|
|
130
|
+
async execute(_id, params) {
|
|
131
|
+
const out = await runPy("stock_data.py", [
|
|
132
|
+
"news",
|
|
133
|
+
params.symbol,
|
|
134
|
+
"--days",
|
|
135
|
+
String(params.days ?? 3),
|
|
136
|
+
]);
|
|
137
|
+
return asText(out);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
api.registerTool({
|
|
142
|
+
name: "get_financials",
|
|
143
|
+
description: "获取股票关键财务指标(PE/PB/市值/营收/净利润/ROE等)",
|
|
144
|
+
parameters: Type.Object({
|
|
145
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
146
|
+
}),
|
|
147
|
+
async execute(_id, params) {
|
|
148
|
+
const out = await runPy("stock_data.py", ["financials", params.symbol]);
|
|
149
|
+
return asText(out);
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// --- Analysis Tools ---
|
|
154
|
+
|
|
155
|
+
api.registerTool({
|
|
156
|
+
name: "get_technical_analysis",
|
|
157
|
+
description:
|
|
158
|
+
"获取股票技术面分析(MA/MACD/RSI/BOLL/KDJ/成交量等指标 + 100分综合评分 + 6级买卖信号 + 趋势/偏离度/支撑压力位)",
|
|
159
|
+
parameters: Type.Object({
|
|
160
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
161
|
+
period: Type.Optional(
|
|
162
|
+
Type.Union(
|
|
163
|
+
[Type.Literal("daily"), Type.Literal("weekly"), Type.Literal("monthly")],
|
|
164
|
+
{ description: "分析周期,默认 daily" }
|
|
165
|
+
)
|
|
166
|
+
),
|
|
167
|
+
count: Type.Optional(
|
|
168
|
+
Type.Number({ description: "用于计算指标的K线条数,默认 120" })
|
|
169
|
+
),
|
|
170
|
+
}),
|
|
171
|
+
async execute(_id, params) {
|
|
172
|
+
const out = await runPy("technical.py", [
|
|
173
|
+
"analyze",
|
|
174
|
+
params.symbol,
|
|
175
|
+
"--period",
|
|
176
|
+
params.period ?? "daily",
|
|
177
|
+
"--count",
|
|
178
|
+
String(params.count ?? 120),
|
|
179
|
+
]);
|
|
180
|
+
return asText(out);
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
api.registerTool({
|
|
185
|
+
name: "analyze_pattern",
|
|
186
|
+
description:
|
|
187
|
+
"K线形态识别 — 检测十字星、锤子线、吞没、启明星、黄昏星、双底、20日突破等12+种经典形态",
|
|
188
|
+
parameters: Type.Object({
|
|
189
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
190
|
+
period: Type.Optional(
|
|
191
|
+
Type.Union(
|
|
192
|
+
[Type.Literal("daily"), Type.Literal("weekly"), Type.Literal("monthly")],
|
|
193
|
+
{ description: "K线周期,默认 daily" }
|
|
194
|
+
)
|
|
195
|
+
),
|
|
196
|
+
days: Type.Optional(
|
|
197
|
+
Type.Number({ description: "分析的K线天数,默认 60" })
|
|
198
|
+
),
|
|
199
|
+
}),
|
|
200
|
+
async execute(_id, params) {
|
|
201
|
+
const out = await runPy("pattern.py", [
|
|
202
|
+
"analyze",
|
|
203
|
+
params.symbol,
|
|
204
|
+
"--period",
|
|
205
|
+
params.period ?? "daily",
|
|
206
|
+
"--days",
|
|
207
|
+
String(params.days ?? 60),
|
|
208
|
+
]);
|
|
209
|
+
return asText(out);
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// --- Market Tools ---
|
|
214
|
+
|
|
215
|
+
api.registerTool({
|
|
216
|
+
name: "get_market_indices",
|
|
217
|
+
description:
|
|
218
|
+
"获取主要市场指数行情。CN: 上证/深证/创业板/科创50/沪深300;HK: 恒生/国企/科技;US: 道琼斯/纳斯达克/标普500",
|
|
219
|
+
parameters: Type.Object({
|
|
220
|
+
region: Type.Optional(
|
|
221
|
+
Type.Union(
|
|
222
|
+
[Type.Literal("cn"), Type.Literal("hk"), Type.Literal("us")],
|
|
223
|
+
{ description: "市场区域,默认 cn" }
|
|
224
|
+
)
|
|
225
|
+
),
|
|
226
|
+
}),
|
|
227
|
+
async execute(_id, params) {
|
|
228
|
+
const out = await runPy("stock_data.py", [
|
|
229
|
+
"market_indices",
|
|
230
|
+
"--region",
|
|
231
|
+
params.region ?? "cn",
|
|
232
|
+
]);
|
|
233
|
+
return asText(out);
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
api.registerTool({
|
|
238
|
+
name: "get_sector_rankings",
|
|
239
|
+
description:
|
|
240
|
+
"获取A股行业板块涨跌幅排行(含领涨股、涨跌家数等)。支持查看涨幅榜/跌幅榜/双向",
|
|
241
|
+
parameters: Type.Object({
|
|
242
|
+
top: Type.Optional(
|
|
243
|
+
Type.Number({ description: "返回排名前N的板块,默认 10" })
|
|
244
|
+
),
|
|
245
|
+
direction: Type.Optional(
|
|
246
|
+
Type.Union(
|
|
247
|
+
[Type.Literal("top"), Type.Literal("bottom"), Type.Literal("both")],
|
|
248
|
+
{ description: "top=涨幅榜(默认),bottom=跌幅榜,both=双向" }
|
|
249
|
+
)
|
|
250
|
+
),
|
|
251
|
+
}),
|
|
252
|
+
async execute(_id, params) {
|
|
253
|
+
const out = await runPy("stock_data.py", [
|
|
254
|
+
"sector_rankings",
|
|
255
|
+
"--top",
|
|
256
|
+
String(params.top ?? 10),
|
|
257
|
+
"--direction",
|
|
258
|
+
params.direction ?? "top",
|
|
259
|
+
]);
|
|
260
|
+
return asText(out);
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
api.registerTool({
|
|
265
|
+
name: "get_stock_info",
|
|
266
|
+
description:
|
|
267
|
+
"获取股票基本信息(行业、板块、上市日期、总股本等)。A股返回板块/行业,HK/US返回行业/公司简介",
|
|
268
|
+
parameters: Type.Object({
|
|
269
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
270
|
+
}),
|
|
271
|
+
async execute(_id, params) {
|
|
272
|
+
const out = await runPy("stock_data.py", ["stock_info", params.symbol]);
|
|
273
|
+
return asText(out);
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
api.registerTool({
|
|
278
|
+
name: "get_chip_distribution",
|
|
279
|
+
description:
|
|
280
|
+
"获取A股筹码分布数据(获利比例、平均成本、90%/70%成本集中度)。仅支持A股",
|
|
281
|
+
parameters: Type.Object({
|
|
282
|
+
symbol: Type.String({ description: "A股股票代码,如 600519" }),
|
|
283
|
+
}),
|
|
284
|
+
async execute(_id, params) {
|
|
285
|
+
const out = await runPy("stock_data.py", [
|
|
286
|
+
"chip_distribution",
|
|
287
|
+
params.symbol,
|
|
288
|
+
]);
|
|
289
|
+
return asText(out);
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
api.registerTool({
|
|
294
|
+
name: "get_market_stats",
|
|
295
|
+
description:
|
|
296
|
+
"获取A股市场整体统计(涨跌家数、涨停跌停数、平均涨幅、涨跌Top5、总成交额)",
|
|
297
|
+
parameters: Type.Object({
|
|
298
|
+
market: Type.Optional(
|
|
299
|
+
Type.Union([Type.Literal("A")], { description: "市场,目前仅支持 A" })
|
|
300
|
+
),
|
|
301
|
+
}),
|
|
302
|
+
async execute(_id, params) {
|
|
303
|
+
const out = await runPy("stock_data.py", [
|
|
304
|
+
"market_stats",
|
|
305
|
+
"--market",
|
|
306
|
+
params.market ?? "A",
|
|
307
|
+
]);
|
|
308
|
+
return asText(out);
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
api.registerTool({
|
|
313
|
+
name: "get_fundamental_context",
|
|
314
|
+
description:
|
|
315
|
+
"获取A股深度基本面(估值PE/PB/PS + 成长性营收/净利增速 + 盈利能力ROE/毛利率 + 分红历史)",
|
|
316
|
+
parameters: Type.Object({
|
|
317
|
+
symbol: Type.String({ description: "A股股票代码,如 600519" }),
|
|
318
|
+
}),
|
|
319
|
+
async execute(_id, params) {
|
|
320
|
+
const out = await runPy("stock_data.py", [
|
|
321
|
+
"fundamental_context",
|
|
322
|
+
params.symbol,
|
|
323
|
+
]);
|
|
324
|
+
return asText(out);
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// --- Screener & Backtest ---
|
|
329
|
+
|
|
330
|
+
api.registerTool({
|
|
331
|
+
name: "screen_stocks",
|
|
332
|
+
description:
|
|
333
|
+
"全市场股票筛选(AlphaSift L1 多因子硬筛)。按PE/PB/市值/换手率/涨跌幅/量比等因子过滤和评分",
|
|
334
|
+
parameters: Type.Object({
|
|
335
|
+
market: Type.Optional(
|
|
336
|
+
Type.Union(
|
|
337
|
+
[Type.Literal("A"), Type.Literal("HK"), Type.Literal("US")],
|
|
338
|
+
{ description: "市场,默认 A" }
|
|
339
|
+
)
|
|
340
|
+
),
|
|
341
|
+
top: Type.Optional(
|
|
342
|
+
Type.Number({ description: "返回排名前N的股票,默认 20" })
|
|
343
|
+
),
|
|
344
|
+
config: Type.Optional(
|
|
345
|
+
Type.String({ description: "自定义筛选配置YAML文件路径(可选)" })
|
|
346
|
+
),
|
|
347
|
+
}),
|
|
348
|
+
async execute(_id, params) {
|
|
349
|
+
const args = [
|
|
350
|
+
"screen",
|
|
351
|
+
"--market",
|
|
352
|
+
params.market ?? "A",
|
|
353
|
+
"--top",
|
|
354
|
+
String(params.top ?? 20),
|
|
355
|
+
];
|
|
356
|
+
if (params.config) args.push("--config", params.config);
|
|
357
|
+
const out = await runPy("screener.py", args);
|
|
358
|
+
return asText(out);
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
api.registerTool({
|
|
363
|
+
name: "run_backtest",
|
|
364
|
+
description:
|
|
365
|
+
"策略回测(AlphaEvo)。读取YAML策略定义,在历史数据上模拟交易,输出收益率/回撤/胜率等指标",
|
|
366
|
+
parameters: Type.Object({
|
|
367
|
+
strategy: Type.String({ description: "策略YAML文件路径" }),
|
|
368
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
369
|
+
start: Type.Optional(
|
|
370
|
+
Type.String({ description: "回测起始日期,格式 YYYY-MM-DD" })
|
|
371
|
+
),
|
|
372
|
+
end: Type.Optional(
|
|
373
|
+
Type.String({ description: "回测结束日期,格式 YYYY-MM-DD" })
|
|
374
|
+
),
|
|
375
|
+
capital: Type.Optional(
|
|
376
|
+
Type.Number({ description: "初始资金,默认 1000000" })
|
|
377
|
+
),
|
|
378
|
+
}),
|
|
379
|
+
async execute(_id, params) {
|
|
380
|
+
const args = ["run", params.strategy, params.symbol];
|
|
381
|
+
if (params.start) args.push("--start", params.start);
|
|
382
|
+
if (params.end) args.push("--end", params.end);
|
|
383
|
+
args.push("--capital", String(params.capital ?? 1000000));
|
|
384
|
+
const out = await runPy("backtest.py", args);
|
|
385
|
+
return asText(out);
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
api.registerTool({
|
|
390
|
+
name: "evaluate_signal",
|
|
391
|
+
description:
|
|
392
|
+
"技术信号历史准确率评估 — 回溯历史数据,统计某个技术信号触发后N日的胜率和平均收益。支持9种信号:macd_golden_cross/macd_death_cross/rsi_oversold/rsi_overbought/breakout_20d/breakdown_20d/volume_surge/ma_golden_cross/ma_death_cross",
|
|
393
|
+
parameters: Type.Object({
|
|
394
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
395
|
+
signal: Type.Union(
|
|
396
|
+
[
|
|
397
|
+
Type.Literal("macd_golden_cross"),
|
|
398
|
+
Type.Literal("macd_death_cross"),
|
|
399
|
+
Type.Literal("rsi_oversold"),
|
|
400
|
+
Type.Literal("rsi_overbought"),
|
|
401
|
+
Type.Literal("breakout_20d"),
|
|
402
|
+
Type.Literal("breakdown_20d"),
|
|
403
|
+
Type.Literal("volume_surge"),
|
|
404
|
+
Type.Literal("ma_golden_cross"),
|
|
405
|
+
Type.Literal("ma_death_cross"),
|
|
406
|
+
],
|
|
407
|
+
{ description: "信号名称" }
|
|
408
|
+
),
|
|
409
|
+
forward_days: Type.Optional(
|
|
410
|
+
Type.String({ description: "逗号分隔的前瞻天数,默认 3,5,10" })
|
|
411
|
+
),
|
|
412
|
+
lookback: Type.Optional(
|
|
413
|
+
Type.Number({ description: "回溯K线条数,默认 250(约1年)" })
|
|
414
|
+
),
|
|
415
|
+
}),
|
|
416
|
+
async execute(_id, params) {
|
|
417
|
+
const out = await runPy("backtest.py", [
|
|
418
|
+
"evaluate_signal",
|
|
419
|
+
params.symbol,
|
|
420
|
+
params.signal,
|
|
421
|
+
"--forward",
|
|
422
|
+
params.forward_days ?? "3,5,10",
|
|
423
|
+
"--lookback",
|
|
424
|
+
String(params.lookback ?? 250),
|
|
425
|
+
]);
|
|
426
|
+
return asText(out);
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// --- Name Resolution ---
|
|
431
|
+
|
|
432
|
+
api.registerTool({
|
|
433
|
+
name: "resolve_stock_name",
|
|
434
|
+
description:
|
|
435
|
+
"股票名称智能解析 — 输入中文名(贵州茅台)、拼音(guizhou maotai/gzmt)、部分代码,返回匹配的股票代码。仅支持A股",
|
|
436
|
+
parameters: Type.Object({
|
|
437
|
+
query: Type.String({
|
|
438
|
+
description: "股票名称、拼音、拼音首字母或部分代码",
|
|
439
|
+
}),
|
|
440
|
+
top: Type.Optional(
|
|
441
|
+
Type.Number({ description: "返回匹配数量,默认 5" })
|
|
442
|
+
),
|
|
443
|
+
}),
|
|
444
|
+
async execute(_id, params) {
|
|
445
|
+
const out = await runPy("name_resolver.py", [
|
|
446
|
+
"resolve",
|
|
447
|
+
params.query,
|
|
448
|
+
"--top",
|
|
449
|
+
String(params.top ?? 5),
|
|
450
|
+
]);
|
|
451
|
+
return asText(out);
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// --- Trading Calendar ---
|
|
456
|
+
|
|
457
|
+
api.registerTool({
|
|
458
|
+
name: "check_trading_day",
|
|
459
|
+
description:
|
|
460
|
+
"查询某日是否为交易日。支持CN(A股)、HK(港股)、US(美股)三市场",
|
|
461
|
+
parameters: Type.Object({
|
|
462
|
+
market: Type.Union(
|
|
463
|
+
[Type.Literal("CN"), Type.Literal("HK"), Type.Literal("US")],
|
|
464
|
+
{ description: "市场" }
|
|
465
|
+
),
|
|
466
|
+
date: Type.Optional(
|
|
467
|
+
Type.String({ description: "日期(YYYY-MM-DD),不填则查今天" })
|
|
468
|
+
),
|
|
469
|
+
}),
|
|
470
|
+
async execute(_id, params) {
|
|
471
|
+
const args = ["check", params.market];
|
|
472
|
+
if (params.date) args.push("--date", params.date);
|
|
473
|
+
const out = await runPy("trading_calendar.py", args);
|
|
474
|
+
return asText(out);
|
|
475
|
+
},
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
api.registerTool({
|
|
479
|
+
name: "get_trading_days",
|
|
480
|
+
description: "获取最近/未来N个交易日列表。支持CN/HK/US三市场",
|
|
481
|
+
parameters: Type.Object({
|
|
482
|
+
market: Type.Union(
|
|
483
|
+
[Type.Literal("CN"), Type.Literal("HK"), Type.Literal("US")],
|
|
484
|
+
{ description: "市场" }
|
|
485
|
+
),
|
|
486
|
+
direction: Type.Optional(
|
|
487
|
+
Type.Union([Type.Literal("next"), Type.Literal("prev")], {
|
|
488
|
+
description: "next=未来交易日, prev=过去交易日",
|
|
489
|
+
})
|
|
490
|
+
),
|
|
491
|
+
count: Type.Optional(
|
|
492
|
+
Type.Number({ description: "返回天数,默认 5" })
|
|
493
|
+
),
|
|
494
|
+
date: Type.Optional(
|
|
495
|
+
Type.String({ description: "起始日期(YYYY-MM-DD),默认今天" })
|
|
496
|
+
),
|
|
497
|
+
}),
|
|
498
|
+
async execute(_id, params) {
|
|
499
|
+
const args = [
|
|
500
|
+
params.direction ?? "next",
|
|
501
|
+
params.market,
|
|
502
|
+
"--count",
|
|
503
|
+
String(params.count ?? 5),
|
|
504
|
+
];
|
|
505
|
+
if (params.date) args.push("--date", params.date);
|
|
506
|
+
const out = await runPy("trading_calendar.py", args);
|
|
507
|
+
return asText(out);
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
// --- Standalone MA Calculator ---
|
|
512
|
+
|
|
513
|
+
api.registerTool({
|
|
514
|
+
name: "calculate_ma",
|
|
515
|
+
description:
|
|
516
|
+
"独立均线计算器 — 支持任意周期MA(5/10/20/30/60/120/250或自定义)+ 偏离度 + 均线排列 + 金叉死叉检测",
|
|
517
|
+
parameters: Type.Object({
|
|
518
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
519
|
+
periods: Type.Optional(
|
|
520
|
+
Type.String({
|
|
521
|
+
description: "逗号分隔的MA周期列表,如 5,10,20,60,120,250",
|
|
522
|
+
})
|
|
523
|
+
),
|
|
524
|
+
kline_period: Type.Optional(
|
|
525
|
+
Type.Union(
|
|
526
|
+
[Type.Literal("daily"), Type.Literal("weekly"), Type.Literal("monthly")],
|
|
527
|
+
{ description: "K线周期,默认 daily" }
|
|
528
|
+
)
|
|
529
|
+
),
|
|
530
|
+
}),
|
|
531
|
+
async execute(_id, params) {
|
|
532
|
+
const out = await runPy("technical.py", [
|
|
533
|
+
"calculate_ma",
|
|
534
|
+
params.symbol,
|
|
535
|
+
"--periods",
|
|
536
|
+
params.periods ?? "5,10,20,30,60,120,250",
|
|
537
|
+
"--period",
|
|
538
|
+
params.kline_period ?? "daily",
|
|
539
|
+
"--count",
|
|
540
|
+
"300",
|
|
541
|
+
]);
|
|
542
|
+
return asText(out);
|
|
543
|
+
},
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
// --- Volume-Price Analysis ---
|
|
547
|
+
|
|
548
|
+
api.registerTool({
|
|
549
|
+
name: "get_volume_analysis",
|
|
550
|
+
description:
|
|
551
|
+
"独立量价分析 — 量价相关性、上涨/下跌日成交量对比、量能趋势、量价模式解读(放量上涨/缩量回调等)",
|
|
552
|
+
parameters: Type.Object({
|
|
553
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
554
|
+
period: Type.Optional(
|
|
555
|
+
Type.Union(
|
|
556
|
+
[Type.Literal("daily"), Type.Literal("weekly"), Type.Literal("monthly")],
|
|
557
|
+
{ description: "K线周期,默认 daily" }
|
|
558
|
+
)
|
|
559
|
+
),
|
|
560
|
+
count: Type.Optional(
|
|
561
|
+
Type.Number({ description: "分析K线条数,默认 60" })
|
|
562
|
+
),
|
|
563
|
+
}),
|
|
564
|
+
async execute(_id, params) {
|
|
565
|
+
const out = await runPy("volume_analysis.py", [
|
|
566
|
+
"analyze",
|
|
567
|
+
params.symbol,
|
|
568
|
+
"--period",
|
|
569
|
+
params.period ?? "daily",
|
|
570
|
+
"--count",
|
|
571
|
+
String(params.count ?? 60),
|
|
572
|
+
]);
|
|
573
|
+
return asText(out);
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// --- Search Intelligence ---
|
|
578
|
+
|
|
579
|
+
api.registerTool({
|
|
580
|
+
name: "search_stock_news",
|
|
581
|
+
description:
|
|
582
|
+
"多引擎股票新闻搜索(支持 Tavily/Brave/SerpAPI)。需配置对应 API Key 环境变量",
|
|
583
|
+
parameters: Type.Object({
|
|
584
|
+
query: Type.String({ description: "搜索关键词" }),
|
|
585
|
+
count: Type.Optional(
|
|
586
|
+
Type.Number({ description: "返回结果数量,默认 10" })
|
|
587
|
+
),
|
|
588
|
+
}),
|
|
589
|
+
async execute(_id, params) {
|
|
590
|
+
const out = await runPy("search_intel.py", [
|
|
591
|
+
"search",
|
|
592
|
+
params.query,
|
|
593
|
+
"--count",
|
|
594
|
+
String(params.count ?? 10),
|
|
595
|
+
]);
|
|
596
|
+
return asText(out);
|
|
597
|
+
},
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
api.registerTool({
|
|
601
|
+
name: "search_comprehensive_intel",
|
|
602
|
+
description:
|
|
603
|
+
"股票综合情报搜索 — 从6个维度(新闻/公告/行情分析/风险/业绩/行业)搜索综合信息",
|
|
604
|
+
parameters: Type.Object({
|
|
605
|
+
symbol: Type.String({ description: "股票代码" }),
|
|
606
|
+
name: Type.Optional(
|
|
607
|
+
Type.String({ description: "股票名称(可选,提升搜索准确度)" })
|
|
608
|
+
),
|
|
609
|
+
}),
|
|
610
|
+
async execute(_id, params) {
|
|
611
|
+
const args = ["comprehensive", params.symbol];
|
|
612
|
+
if (params.name) args.push("--name", params.name);
|
|
613
|
+
const out = await runPy("search_intel.py", args);
|
|
614
|
+
return asText(out);
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
api.registerTool({
|
|
619
|
+
name: "get_social_sentiment",
|
|
620
|
+
description:
|
|
621
|
+
"获取股票社交媒体情绪数据(Reddit/X/Polymarket)。主要支持美股。需配置 SENTIMENT_API_KEY",
|
|
622
|
+
parameters: Type.Object({
|
|
623
|
+
symbol: Type.String({ description: "股票代码(如 AAPL)" }),
|
|
624
|
+
}),
|
|
625
|
+
async execute(_id, params) {
|
|
626
|
+
const out = await runPy("search_intel.py", ["sentiment", params.symbol]);
|
|
627
|
+
return asText(out);
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
api.registerTool({
|
|
632
|
+
name: "get_trending_sentiment",
|
|
633
|
+
description:
|
|
634
|
+
"获取社交媒体热门趋势(Reddit/X/Polymarket热门股票讨论)。数据缓存10分钟。适用于发现市场热点",
|
|
635
|
+
parameters: Type.Object({}),
|
|
636
|
+
async execute() {
|
|
637
|
+
const out = await runPy("search_intel.py", ["trending"]);
|
|
638
|
+
return asText(out);
|
|
639
|
+
},
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
api.registerTool({
|
|
643
|
+
name: "extract_article",
|
|
644
|
+
description:
|
|
645
|
+
"网页文章全文提取 — 输入URL,提取文章标题、正文(最多3000字)、作者、发布日期等。适用于深度阅读搜索结果中的新闻/研报",
|
|
646
|
+
parameters: Type.Object({
|
|
647
|
+
url: Type.String({ description: "文章URL" }),
|
|
648
|
+
}),
|
|
649
|
+
async execute(_id, params) {
|
|
650
|
+
const out = await runPy("search_intel.py", ["extract", params.url]);
|
|
651
|
+
return asText(out);
|
|
652
|
+
},
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
api.registerTool({
|
|
656
|
+
name: "screen_risk",
|
|
657
|
+
description:
|
|
658
|
+
"风险专项筛查 — 7维度风险检测(估值极端/技术预警/解禁到期/内部人减持/业绩预警/监管处罚/行业政策),返回风险评级和一票否决标记",
|
|
659
|
+
parameters: Type.Object({
|
|
660
|
+
symbol: Type.String({ description: "股票代码(如 600519)" }),
|
|
661
|
+
name: Type.Optional(
|
|
662
|
+
Type.String({ description: "股票名称(可选,提升新闻搜索准确度)" })
|
|
663
|
+
),
|
|
664
|
+
}),
|
|
665
|
+
async execute(_id, params) {
|
|
666
|
+
const args = ["screen", params.symbol];
|
|
667
|
+
if (params.name) args.push("--name", params.name);
|
|
668
|
+
const out = await runPy("risk_screening.py", args);
|
|
669
|
+
return asText(out);
|
|
670
|
+
},
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
api.registerTool({
|
|
674
|
+
name: "detect_market_regime",
|
|
675
|
+
description:
|
|
676
|
+
"市场状态检测 — 分析大盘指数判断当前市场阶段(上涨趋势/下跌趋势/横盘震荡/高波动/板块热点),并推荐适合的分析策略",
|
|
677
|
+
parameters: Type.Object({
|
|
678
|
+
market: Type.Optional(
|
|
679
|
+
Type.Union(
|
|
680
|
+
[Type.Literal("A"), Type.Literal("HK"), Type.Literal("US")],
|
|
681
|
+
{ description: "市场代码,默认 A" }
|
|
682
|
+
)
|
|
683
|
+
),
|
|
684
|
+
}),
|
|
685
|
+
async execute(_id, params) {
|
|
686
|
+
const out = await runPy("market_regime.py", [
|
|
687
|
+
"detect",
|
|
688
|
+
params.market ?? "A",
|
|
689
|
+
]);
|
|
690
|
+
return asText(out);
|
|
691
|
+
},
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
api.registerTool({
|
|
695
|
+
name: "get_market_review",
|
|
696
|
+
description:
|
|
697
|
+
"大盘复盘 — 获取市场日度复盘数据,包含指数、涨跌统计、板块排名、新闻、市场温度与策略建议",
|
|
698
|
+
parameters: Type.Object({
|
|
699
|
+
market: Type.Optional(
|
|
700
|
+
Type.Union(
|
|
701
|
+
[
|
|
702
|
+
Type.Literal("A"),
|
|
703
|
+
Type.Literal("HK"),
|
|
704
|
+
Type.Literal("US"),
|
|
705
|
+
Type.Literal("all"),
|
|
706
|
+
],
|
|
707
|
+
{ description: "市场代码,默认 A。all 表示所有市场" }
|
|
708
|
+
)
|
|
709
|
+
),
|
|
710
|
+
}),
|
|
711
|
+
async execute(_id, params) {
|
|
712
|
+
const out = await runPy("market_review.py", [
|
|
713
|
+
"review",
|
|
714
|
+
"--market",
|
|
715
|
+
params.market ?? "A",
|
|
716
|
+
]);
|
|
717
|
+
return asText(out);
|
|
718
|
+
},
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
api.registerTool({
|
|
722
|
+
name: "run_watchlist_analysis",
|
|
723
|
+
description:
|
|
724
|
+
"批量自选股分析 — 对多只股票并行采集行情/技术/资金/风险等数据,返回汇总结果。适用于每日定时分析自选股列表",
|
|
725
|
+
parameters: Type.Object({
|
|
726
|
+
symbols: Type.String({
|
|
727
|
+
description: "逗号分隔的股票代码列表,如 600519,000001,300750",
|
|
728
|
+
}),
|
|
729
|
+
workers: Type.Optional(
|
|
730
|
+
Type.Number({
|
|
731
|
+
description: "并发数,默认 3(建议不超过5,避免API限流)",
|
|
732
|
+
})
|
|
733
|
+
),
|
|
734
|
+
}),
|
|
735
|
+
async execute(_id, params) {
|
|
736
|
+
const out = await runPy("watchlist.py", [
|
|
737
|
+
"analyze",
|
|
738
|
+
params.symbols,
|
|
739
|
+
"--workers",
|
|
740
|
+
String(params.workers ?? 3),
|
|
741
|
+
]);
|
|
742
|
+
return asText(out);
|
|
743
|
+
},
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
api.registerTool({
|
|
747
|
+
name: "detect_anomaly",
|
|
748
|
+
description:
|
|
749
|
+
"异常/事件检测 — 一键扫描股票当前所有异动信号(MACD金叉死叉、RSI超买超卖、20日突破、放量异动、涨跌停、布林突破、KDJ极值、资金异动等),返回结构化异常列表",
|
|
750
|
+
parameters: Type.Object({
|
|
751
|
+
symbol: Type.String({
|
|
752
|
+
description: "股票代码(如 600519、AAPL、00700.HK)",
|
|
753
|
+
}),
|
|
754
|
+
}),
|
|
755
|
+
async execute(_id, params) {
|
|
756
|
+
const out = await runPy("anomaly_detect.py", ["detect", params.symbol]);
|
|
757
|
+
return asText(out);
|
|
758
|
+
},
|
|
759
|
+
});
|
|
760
|
+
},
|
|
761
|
+
});
|