@weaxs/openclaw-stock-analysis 0.2.5 → 0.2.7
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 +1 -1
- package/dist/index.js +322 -21
- package/index.ts +257 -16
- package/openclaw.plugin.json +11 -1
- package/package.json +1 -1
- package/schemas/market_review_schema.json +12 -5
- package/schemas/report_schema.json +68 -4
- package/scripts/cli-timeout.mjs +27 -0
- package/scripts/json-input.mjs +26 -0
- package/scripts/setup-python.mjs +6 -6
- package/skills/bull-trend/SKILL.md +34 -10
- package/skills/bull-trend/references/fat-tails.md +91 -0
- package/skills/bull-trend/scripts/tail_analysis.py +132 -0
- package/skills/event-driven/SKILL.md +6 -0
- package/skills/growth-quality/SKILL.md +6 -0
- package/skills/market-review/SKILL.md +2 -0
- package/skills/stock-analysis/SKILL.md +25 -5
- package/skills/stock-analysis/references/stateless-analysis.md +66 -0
- package/skills/stock-screener/SKILL.md +7 -1
- package/skills/strategy-backtest/SKILL.md +13 -0
- package/skills/wisburg-research/SKILL.md +2 -0
- package/templates/market_review/full.md.j2 +7 -0
- package/templates/stock_analysis/_evidence.md.j2 +11 -0
- package/templates/stock_analysis/brief.md.j2 +6 -1
- package/templates/stock_analysis/full.md.j2 +8 -3
- package/tools/_subproc.py +66 -11
- package/tools/alert_rules.py +32 -4
- package/tools/backtest.py +95 -18
- package/tools/capabilities.py +11 -0
- package/tools/cli_budgets.json +26 -0
- package/tools/gather.py +24 -16
- package/tools/lixinger.py +100 -0
- package/tools/market_regime.py +7 -3
- package/tools/market_review.py +37 -15
- package/tools/position_context.py +20 -2
- package/tools/report_renderer.py +2 -0
- package/tools/risk_screening.py +45 -17
- package/tools/screener.py +74 -24
- package/tools/sec_edgar.py +346 -0
- package/tools/sec_holders.py +263 -0
- package/tools/signal_tracker.py +218 -24
- package/tools/stateless_analysis.py +630 -0
- package/tools/stock_data.py +170 -32
- package/tools/technical.py +16 -2
- package/tools/value_data.py +159 -0
- package/tools/watchlist.py +24 -1
- package/tools/watchlist_context.py +25 -10
package/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { withJsonInput } from "../scripts/json-input.mjs";
|
|
2
|
+
import { commandTimeout } from "../scripts/cli-timeout.mjs";
|
|
1
3
|
import { existsSync } from "node:fs";
|
|
2
4
|
import * as cp from "node:child_process";
|
|
3
5
|
import { promisify } from "node:util";
|
|
@@ -11,8 +13,19 @@ type Executor = (bin: string, argv: string[]) => Promise<string>;
|
|
|
11
13
|
|
|
12
14
|
const defaultExecutor: Executor = async (bin, argv) => {
|
|
13
15
|
const exec = promisify(cp.execFile);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
try {
|
|
17
|
+
const { stdout } = await exec(bin, argv, { maxBuffer: 32 * 1024 * 1024, timeout: commandTimeout(argv[0], argv.slice(1)) });
|
|
18
|
+
return stdout;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
const stdout = (error as { stdout?: string }).stdout;
|
|
21
|
+
try {
|
|
22
|
+
const data = JSON.parse(stdout ?? "");
|
|
23
|
+
if (data && typeof data.error === "string") return stdout!;
|
|
24
|
+
} catch {
|
|
25
|
+
// A failed subprocess without JSON must not expose stderr or command arguments.
|
|
26
|
+
}
|
|
27
|
+
return JSON.stringify({ error: (error as { killed?: boolean }).killed ? "Python command timed out" : "Python command failed; check interpreter/dependencies" });
|
|
28
|
+
}
|
|
16
29
|
};
|
|
17
30
|
|
|
18
31
|
let executor: Executor = defaultExecutor;
|
|
@@ -42,6 +55,7 @@ export default definePluginEntry({
|
|
|
42
55
|
register(api) {
|
|
43
56
|
// OpenClaw executes a captured copy of the JS bundle; the venv stays in the installed plugin root.
|
|
44
57
|
const repoRoot = api.rootDir || fallbackRoot;
|
|
58
|
+
const runtimeToolsDir = existsSync(join(repoRoot, "tools")) ? join(repoRoot, "tools") : toolsDir;
|
|
45
59
|
const pythonBin = () => {
|
|
46
60
|
const venvPython = join(repoRoot, venvBin);
|
|
47
61
|
if (existsSync(venvPython)) return venvPython;
|
|
@@ -52,12 +66,239 @@ export default definePluginEntry({
|
|
|
52
66
|
return isWin ? "python" : "python3";
|
|
53
67
|
};
|
|
54
68
|
const runPy = (script: string, args: string[]) =>
|
|
55
|
-
executor(pythonBin(), [join(
|
|
69
|
+
executor(pythonBin(), [join(runtimeToolsDir, script), ...args]);
|
|
70
|
+
api.registerTool({
|
|
71
|
+
name: "compare_stocks",
|
|
72
|
+
description: "无状态同行指标比较:先用现有财务/行情工具取数,再传companies;仅相同unit/basis/period可排序,缺失不填零,不生成买卖综合分。",
|
|
73
|
+
parameters: Type.Object({
|
|
74
|
+
companies: Type.Array(Type.Object({
|
|
75
|
+
symbol: Type.String({"description": "唯一股票代码"}),
|
|
76
|
+
period: Type.String({"description": "统一可比期间;财务用报告期,估值用估值日"}),
|
|
77
|
+
metrics: Type.Array(Type.Object({
|
|
78
|
+
name: Type.String({"description": "指标名,如pe/roe/net_income"}),
|
|
79
|
+
value: Type.Union([Type.Number(), Type.Null()], {"description": "有限数值;缺失为null"}),
|
|
80
|
+
unit: Type.String({"description": "精确单位,如multiple/percent/fraction/CNY/USD"}),
|
|
81
|
+
basis: Type.String({"description": "口径,如TTM/annual/consolidated;区分累计与单季"}),
|
|
82
|
+
source: Type.Optional(Type.String({"description": "原始证据URL或字段路径"})),
|
|
83
|
+
}, {"additionalProperties": false}), {"description": "结构化指标,单位、口径明确,缺失不填零"}),
|
|
84
|
+
}, {"additionalProperties": false}), {"description": "2..30家公司,调用方确认可比性"}),
|
|
85
|
+
}, {"additionalProperties": false}),
|
|
86
|
+
async execute(_id, params) {
|
|
87
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
88
|
+
runPy("stateless_analysis.py", ["peers", "--input", path])));
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
api.registerTool({
|
|
93
|
+
name: "analyze_disclosure_changes",
|
|
94
|
+
description: "无状态公告财报比较:传新旧正文及指标,返回变更行号、来源与财务变化;负/零基数增长率为null。不下载PDF、不代替经济解读。",
|
|
95
|
+
parameters: Type.Object({
|
|
96
|
+
previous: Type.Object({
|
|
97
|
+
text: Type.String({"description": "已核实正文,最多200000字符;保留换行,PDF需宿主提取"}),
|
|
98
|
+
source: Type.String({"description": "原文URL或文档标识"}),
|
|
99
|
+
period: Type.String({"description": "报告期,如2025年度"}),
|
|
100
|
+
metrics: Type.Array(Type.Object({
|
|
101
|
+
name: Type.String({"description": "指标名,如pe/roe/net_income"}),
|
|
102
|
+
value: Type.Union([Type.Number(), Type.Null()], {"description": "有限数值;缺失为null"}),
|
|
103
|
+
unit: Type.String({"description": "精确单位,如multiple/percent/fraction/CNY/USD"}),
|
|
104
|
+
basis: Type.String({"description": "口径,如TTM/annual/consolidated;区分累计与单季"}),
|
|
105
|
+
source: Type.Optional(Type.String({"description": "原始证据URL或字段路径"})),
|
|
106
|
+
}, {"additionalProperties": false}), {"description": "结构化指标,单位、口径明确,缺失不填零"}),
|
|
107
|
+
}, {"additionalProperties": false}),
|
|
108
|
+
current: Type.Object({
|
|
109
|
+
text: Type.String({"description": "已核实正文,最多200000字符;保留换行,PDF需宿主提取"}),
|
|
110
|
+
source: Type.String({"description": "原文URL或文档标识"}),
|
|
111
|
+
period: Type.String({"description": "报告期,如2025年度"}),
|
|
112
|
+
metrics: Type.Array(Type.Object({
|
|
113
|
+
name: Type.String({"description": "指标名,如pe/roe/net_income"}),
|
|
114
|
+
value: Type.Union([Type.Number(), Type.Null()], {"description": "有限数值;缺失为null"}),
|
|
115
|
+
unit: Type.String({"description": "精确单位,如multiple/percent/fraction/CNY/USD"}),
|
|
116
|
+
basis: Type.String({"description": "口径,如TTM/annual/consolidated;区分累计与单季"}),
|
|
117
|
+
source: Type.Optional(Type.String({"description": "原始证据URL或字段路径"})),
|
|
118
|
+
}, {"additionalProperties": false}), {"description": "结构化指标,单位、口径明确,缺失不填零"}),
|
|
119
|
+
}, {"additionalProperties": false}),
|
|
120
|
+
max_changes: Type.Optional(Type.Number({"description": "变化上限1..100,默认30"})),
|
|
121
|
+
}, {"additionalProperties": false}),
|
|
122
|
+
async execute(_id, params) {
|
|
123
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
124
|
+
runPy("stateless_analysis.py", ["disclosure", "--input", path])));
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
api.registerTool({
|
|
129
|
+
name: "analyze_portfolio_risk",
|
|
130
|
+
description: "无状态现货多头组合风险:输入持仓、基准币种现金与汇率,返回集中度、币种/行业敞口、价格盈亏和止损情景。缺汇率报错;不保存账户。",
|
|
131
|
+
parameters: Type.Object({
|
|
132
|
+
positions: Type.Array(Type.Object({
|
|
133
|
+
symbol: Type.String({"description": "唯一代码,重复持仓先汇总"}),
|
|
134
|
+
quantity: Type.Number({"description": "正持仓数量"}),
|
|
135
|
+
price: Type.Number({"description": "正现价"}),
|
|
136
|
+
currency: Type.String({"description": "持仓币种,如CNY/USD/HKD"}),
|
|
137
|
+
cost: Type.Optional(Type.Number({"description": "同币种正成本价,可选"})),
|
|
138
|
+
stop_price: Type.Optional(Type.Number({"description": "同币种正止损价,可选"})),
|
|
139
|
+
sector: Type.Optional(Type.String({"description": "统一行业分类,可选"})),
|
|
140
|
+
as_of: Type.Optional(Type.String({"description": "实际估值时点,建议ISO8601"})),
|
|
141
|
+
}, {"additionalProperties": false}), {"description": "1..100个现货多头持仓"}),
|
|
142
|
+
base_currency: Type.String({"description": "基准币种"}),
|
|
143
|
+
cash: Type.Number({"description": "基准币种现金,非负"}),
|
|
144
|
+
fx_rates: Type.Optional(Type.Array(Type.Object({
|
|
145
|
+
currency: Type.String({"description": "唯一非基准币种"}),
|
|
146
|
+
rate: Type.Number({"description": "一单位该币种对应多少基准币种,正数"}),
|
|
147
|
+
}, {"additionalProperties": false}), {"description": "显式现价汇率;基准币种隐含1,不得重复"})),
|
|
148
|
+
histories: Type.Optional(Type.Array(Type.Object({
|
|
149
|
+
symbol: Type.String({"description": "对应唯一持仓股票"}),
|
|
150
|
+
prices: Type.Array(Type.Object({
|
|
151
|
+
date: Type.String({"description": "YYYY-MM-DD,唯一日期"}),
|
|
152
|
+
close: Type.Number({"description": "正有限收盘价"}),
|
|
153
|
+
}, {"additionalProperties": false}), {"description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"}),
|
|
154
|
+
}, {"additionalProperties": false}), {"description": "可选历史,共同日期本币价格收益相关性,不计汇率"})),
|
|
155
|
+
}, {"additionalProperties": false}),
|
|
156
|
+
async execute(_id, params) {
|
|
157
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
158
|
+
runPy("stateless_analysis.py", ["portfolio", "--input", path])));
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
api.registerTool({
|
|
163
|
+
name: "calculate_position_size",
|
|
164
|
+
description: "无状态多头仓位预算:同币种金额,按现金/风险预算/最大仓位/交易单位取最小数量,双边费用和滑点参与止损情景;不执行交易。",
|
|
165
|
+
parameters: Type.Object({
|
|
166
|
+
equity: Type.Number({"description": "总权益,正数"}),
|
|
167
|
+
cash: Type.Number({"description": "可用现金,0..equity"}),
|
|
168
|
+
entry_price: Type.Number({"description": "计划入场价,正数"}),
|
|
169
|
+
stop_price: Type.Number({"description": "正止损价,低于入场价"}),
|
|
170
|
+
risk_fraction: Type.Number({"description": "单笔风险占权益比例0..1,如0.01"}),
|
|
171
|
+
lot_size: Type.Number({"description": "正整数交易单位,用户确认,不猜港股每手数量"}),
|
|
172
|
+
max_position_fraction: Type.Optional(Type.Number({"description": "本次买入最大资金占比0..1,默认1;已有同股持仓先扣减额度"})),
|
|
173
|
+
fee_rate: Type.Optional(Type.Number({"description": "每边比例费用0..0.1,默认0;不含未提供税费/最低收费"})),
|
|
174
|
+
slippage_rate: Type.Optional(Type.Number({"description": "每边滑点0..0.1,默认0"})),
|
|
175
|
+
}, {"additionalProperties": false}),
|
|
176
|
+
async execute(_id, params) {
|
|
177
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
178
|
+
runPy("stateless_analysis.py", ["position_size", "--input", path])));
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
api.registerTool({
|
|
183
|
+
name: "analyze_event_study",
|
|
184
|
+
description: "无状态事件研究:提供同市场股票及基准完整价格、事件日期;事件前一交易日收盘为基点,计算交易日窗口收益差。缺窗口/基准为null,标注重叠,不推断因果。",
|
|
185
|
+
parameters: Type.Object({
|
|
186
|
+
prices: Type.Optional(Type.Array(Type.Object({
|
|
187
|
+
date: Type.String({"description": "YYYY-MM-DD,唯一日期"}),
|
|
188
|
+
close: Type.Number({"description": "正有限收盘价"}),
|
|
189
|
+
}, {"additionalProperties": false}), {"description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"})),
|
|
190
|
+
benchmark_prices: Type.Optional(Type.Array(Type.Object({
|
|
191
|
+
date: Type.String({"description": "YYYY-MM-DD,唯一日期"}),
|
|
192
|
+
close: Type.Number({"description": "正有限收盘价"}),
|
|
193
|
+
}, {"additionalProperties": false}), {"description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"})),
|
|
194
|
+
event_dates: Type.Array(Type.String({"description": "YYYY-MM-DD,盘后公告传下一交易日"}), {"description": "1..100个唯一事件日"}),
|
|
195
|
+
price_basis: Type.Optional(Type.String({"description": "仅显式prices模式必需;代码模式报告实际提供方标记,缺失为unknown,须核实"})),
|
|
196
|
+
horizons: Type.Optional(Type.Array(Type.Number({"description": "0=事件日,1=下一交易日;整数0..250"}), {"description": "1..20个窗口,默认0/1/5/10/20"})),
|
|
197
|
+
start_date: Type.Optional(Type.String({"description": "代码模式必需,YYYY-MM-DD,包含事件前基准日或训练窗口"})),
|
|
198
|
+
end_date: Type.Optional(Type.String({"description": "代码模式必需,YYYY-MM-DD,晚于start_date"})),
|
|
199
|
+
symbol: Type.Optional(Type.String({"description": "股票代码;与benchmark/start_date/end_date一起直接取数,和prices模式互斥"})),
|
|
200
|
+
benchmark: Type.Optional(Type.String({"description": "同市场基准代码;与symbol一起使用"})),
|
|
201
|
+
}, {"additionalProperties": false}),
|
|
202
|
+
async execute(_id, params) {
|
|
203
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
204
|
+
runPy("stateless_analysis.py", ["event_study", "--input", path])));
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
api.registerTool({
|
|
209
|
+
name: "validate_backtest",
|
|
210
|
+
description: "无状态回测稳健性:输入历史OHLCV和完整候选DSL;滚动训练选参数、后续不重叠窗口验证,列出全部样本内敏感性及跨标的结果。仅next_open,不自动优化或保存。",
|
|
211
|
+
parameters: Type.Object({
|
|
212
|
+
datasets: Type.Optional(Type.Array(Type.Object({
|
|
213
|
+
symbol: Type.String({"description": "唯一股票代码"}),
|
|
214
|
+
price_basis: Type.String({"description": "已核实复权/原始价格口径"}),
|
|
215
|
+
bars: Type.Array(Type.Object({
|
|
216
|
+
date: Type.String({"description": "YYYY-MM-DD"}),
|
|
217
|
+
open: Type.Number({"description": "有限OHLCV;价格为正、volume非负"}),
|
|
218
|
+
high: Type.Number({"description": "有限OHLCV;价格为正、volume非负"}),
|
|
219
|
+
low: Type.Number({"description": "有限OHLCV;价格为正、volume非负"}),
|
|
220
|
+
close: Type.Number({"description": "有限OHLCV;价格为正、volume非负"}),
|
|
221
|
+
volume: Type.Number({"description": "有限OHLCV;价格为正、volume非负"}),
|
|
222
|
+
}, {"additionalProperties": false}), {"description": "日期递增完整OHLCV,每组最多2000条,至少train_bars+test_bars"}),
|
|
223
|
+
}, {"additionalProperties": false}), {"description": "1..5个标的,复用get_kline取数"})),
|
|
224
|
+
strategies: Type.Array(Type.Object({
|
|
225
|
+
name: Type.String({"description": "唯一候选名"}),
|
|
226
|
+
strategy: Type.Object({}, {"additionalProperties": true, "description": "完整既有YAML DSL对应JSON,允许parameters引用;仅next_open"}),
|
|
227
|
+
}, {"additionalProperties": false}), {"description": "1..5个预先确定的候选,禁止测试结果回调参数"}),
|
|
228
|
+
train_bars: Type.Optional(Type.Number({"description": "训练交易日数30..1000,默认126"})),
|
|
229
|
+
test_bars: Type.Optional(Type.Number({"description": "测试交易日数30..1000,默认63"})),
|
|
230
|
+
capital: Type.Optional(Type.Number({"description": "每窗口初始资金,默认1000000"})),
|
|
231
|
+
start_date: Type.Optional(Type.String({"description": "代码模式必需,YYYY-MM-DD,包含事件前基准日或训练窗口"})),
|
|
232
|
+
end_date: Type.Optional(Type.String({"description": "代码模式必需,YYYY-MM-DD,晚于start_date"})),
|
|
233
|
+
symbols: Type.Optional(Type.Array(Type.String(), {"description": "1..5个唯一股票代码,配合start_date/end_date直接取数;和datasets互斥"})),
|
|
234
|
+
}, {"additionalProperties": false}),
|
|
235
|
+
async execute(_id, params) {
|
|
236
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
237
|
+
runPy("stateless_analysis.py", ["robustness", "--input", path])));
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
api.registerTool({
|
|
242
|
+
name: "compare_analysis_snapshots",
|
|
243
|
+
description: "无状态快照比较:传新旧JSON,返回JSON Pointer及新增/删除/变化/失效/恢复;不保存快照。数组整体比较,调用前按symbol对齐。",
|
|
244
|
+
parameters: Type.Object({
|
|
245
|
+
previous: Type.Object({}, {"additionalProperties": true, "description": "JSON对象,详见共享Skill与README"}),
|
|
246
|
+
current: Type.Object({}, {"additionalProperties": true, "description": "JSON对象,详见共享Skill与README"}),
|
|
247
|
+
}, {"additionalProperties": false}),
|
|
248
|
+
async execute(_id, params) {
|
|
249
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
250
|
+
runPy("stateless_analysis.py", ["snapshot", "--input", path])));
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
|
|
56
254
|
// --- Data Tools ---
|
|
57
255
|
|
|
256
|
+
api.registerTool({
|
|
257
|
+
name: "get_announcements",
|
|
258
|
+
description: "查询A股巨潮公告标题、日期、类型和原文PDF链接;按日期范围/类别筛选,默认近90天,top=1..500。第一版不提取正文,truncated提示截断。",
|
|
259
|
+
parameters: Type.Object({
|
|
260
|
+
symbol: Type.String({ description: "A股代码" }),
|
|
261
|
+
category: Type.Optional(Type.Union([Type.Literal("all"), Type.Literal("forecast"), Type.Literal("express"), Type.Literal("annual"), Type.Literal("interim"), Type.Literal("quarterly"), Type.Literal("reduction"), Type.Literal("issuance"), Type.Literal("inquiry"), Type.Literal("dividend")], { description: "公告类别,默认all" })),
|
|
262
|
+
start_date: Type.Optional(Type.String({ description: "开始日期YYYY-MM-DD,默认结束日期前90天" })),
|
|
263
|
+
end_date: Type.Optional(Type.String({ description: "结束日期YYYY-MM-DD,默认今天" })),
|
|
264
|
+
top: Type.Optional(Type.Number({ description: "最多条数1..500,默认50" })),
|
|
265
|
+
}),
|
|
266
|
+
async execute(_id, p) {
|
|
267
|
+
const out = await runPy("value_data.py", ["announcements", p.symbol, "--category", p.category ?? "all", "--start-date", p.start_date ?? "", "--end-date", p.end_date ?? "", "--top", String(p.top ?? 50)]);
|
|
268
|
+
return asText(out);
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
api.registerTool({
|
|
273
|
+
name: "get_us_holdings",
|
|
274
|
+
description: "查询SEC 13F:mode=auto默认有13F申报时查机构,否则按发行人CIK反查持仓机构;manager/issuer可显式指定。发行人通过官方13D/G精确映射CUSIP,扫描最新已发布13F窗口,处理重述/补充修订,返回实际报告期、截止日及映射覆盖。首次约100MB下载,后续缓存;无映射明确报错,不做名称猜测。需SEC_USER_AGENT含真实联系邮箱,不是实时或全部证券持仓。",
|
|
275
|
+
parameters: Type.Object({
|
|
276
|
+
cik: Type.String({ description: "机构或发行人CIK,1..10位数字,如0001067983/0000320193" }),
|
|
277
|
+
mode: Type.Optional(Type.Union([Type.Literal("auto"), Type.Literal("manager"), Type.Literal("issuer")], { description: "默认auto;manager查机构组合,issuer反查发行人持仓机构" })),
|
|
278
|
+
}),
|
|
279
|
+
async execute(_id, p) {
|
|
280
|
+
const out = await runPy("sec_edgar.py", ["holdings", p.cik, ...(p.mode ? ["--mode", p.mode] : [])]);
|
|
281
|
+
return asText(out);
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
api.registerTool({
|
|
286
|
+
name: "get_insider_trades",
|
|
287
|
+
description: "查询美股发行人近期Form 4/4-A内部人交易(SEC官方XML),保留人员职务、交易代码、买卖方向、数量、价格、脚注和衍生品标志。需SEC_USER_AGENT含真实联系邮箱;days按申报日期筛选,top限制文件数,修订勿重复计数。",
|
|
288
|
+
parameters: Type.Object({
|
|
289
|
+
symbol: Type.String({ description: "美股ticker或发行人CIK" }),
|
|
290
|
+
days: Type.Optional(Type.Number({ description: "申报日期窗口1..365天,默认90" })),
|
|
291
|
+
top: Type.Optional(Type.Number({ description: "最多解析Form 4文件数1..20,默认10" })),
|
|
292
|
+
}),
|
|
293
|
+
async execute(_id, p) {
|
|
294
|
+
const out = await runPy("sec_edgar.py", ["insider_trades", p.symbol, "--days", String(p.days ?? 90), "--top", String(p.top ?? 10)]);
|
|
295
|
+
return asText(out);
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
|
|
58
299
|
api.registerTool({
|
|
59
300
|
name: "get_valuation_history",
|
|
60
|
-
description: "查询A/HK股票历史
|
|
301
|
+
description: "查询A/HK股票历史PE-TTM/PB、当前正值分位和10/25/50/75/90分位Band,返回实际采样区间;亏损估值分位为null。years=1..10,按天缓存。HK配置LIXINGER_TOKEN时优先理杏仁非金融公司日历史,失败降级百度,不混接来源。",
|
|
61
302
|
parameters: Type.Object({
|
|
62
303
|
symbol: Type.String({ description: "A股代码或港股.HK代码" }),
|
|
63
304
|
years: Type.Optional(Type.Number({ description: "历史窗口年数1..10,默认5" })),
|
|
@@ -143,7 +384,7 @@ export default definePluginEntry({
|
|
|
143
384
|
api.registerTool({
|
|
144
385
|
name: "get_kline",
|
|
145
386
|
description:
|
|
146
|
-
"获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF。A股股票/ETF返回前复权价格,每条记录 adjusted=qfq;sh000xxx/sz399xxx 指数返回原始点位,adjusted=none。需要历史价格自行计算或画图时用;只问指标用 get_technical_analysis,只问现价用 get_quote",
|
|
387
|
+
"获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF。A股股票/ETF返回前复权价格,每条记录 adjusted=qfq;sh000xxx/sz399xxx 指数返回原始点位,adjusted=none。需要历史价格自行计算或画图时用;只问指标用 get_technical_analysis,只问现价用 get_quote。每条记录附 source、UTC fetched_at、data_as_of 和 adjusted;非A股复权口径可能为total_return/qfq/unknown,未知不能假定已复权。部分来源附 adjustment_factor(复权价格/原始价格);缺失不能猜测换算系数。",
|
|
147
388
|
parameters: Type.Object({
|
|
148
389
|
symbol: Type.String({
|
|
149
390
|
description: "股票代码,如 600519(A股)、00700.HK(港股)、AAPL(美股)、7203.T(日股)、005930.KS(韩股)、2330.TW(台股)",
|
|
@@ -171,7 +412,7 @@ export default definePluginEntry({
|
|
|
171
412
|
|
|
172
413
|
api.registerTool({
|
|
173
414
|
name: "get_quote",
|
|
174
|
-
description: "获取股票实时行情报价(现价、涨跌幅、量比等)。支持A股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale 标注;ETF 的 premium_discount_rate
|
|
415
|
+
description: "获取股票实时行情报价(现价、涨跌幅、量比等)。支持A股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale 标注;ETF 的 premium_discount_rate 为正=溢价、负=折价。返回 source、UTC fetched_at 和提供方 data_as_of(未知为null);as_of_basis区分提供方时间与交易日历推断,采集时间不等于行情时间。",
|
|
175
416
|
parameters: Type.Object({
|
|
176
417
|
symbol: Type.String({ description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" }),
|
|
177
418
|
}),
|
|
@@ -231,7 +472,7 @@ export default definePluginEntry({
|
|
|
231
472
|
|
|
232
473
|
api.registerTool({
|
|
233
474
|
name: "get_financials",
|
|
234
|
-
description: "获取股票财务摘要及历史趋势,按天缓存。A
|
|
475
|
+
description: "获取股票财务摘要及历史趋势,按天缓存。A股annual=true与periods=10取十年年报;港股可配置LIXINGER_TOKEN取非金融公司财务序列,保留币种/披露日/实际财年,历史比率单位percent。有效Yahoo顶层快照按整组保留,currency为财报币种、market_cap_currency为市值币种、snapshot_source标明来源;缺失值及report_date不混入历史数值/日期。缺token或无权限降级原有来源并标注不足,不补造缺失。估值历史用get_valuation_history,披露排期用get_earnings_calendar",
|
|
235
476
|
parameters: Type.Object({
|
|
236
477
|
symbol: Type.String({ description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" }),
|
|
237
478
|
annual: Type.Optional(Type.Boolean({description: "只取年度报告,默认false"})),
|
|
@@ -577,7 +818,7 @@ export default definePluginEntry({
|
|
|
577
818
|
api.registerTool({
|
|
578
819
|
name: "screen_stocks",
|
|
579
820
|
description:
|
|
580
|
-
"全市场股票筛选(AlphaSift L1 多因子硬筛 + 市场情绪调节)。按PE/PB/市值/换手率/涨跌幅/量比等因子过滤和评分,可用 l2
|
|
821
|
+
"全市场股票筛选(AlphaSift L1 多因子硬筛 + 市场情绪调节)。按PE/PB/市值/换手率/涨跌幅/量比等因子过滤和评分,可用 l2 开启质量/成长/动量/波动率/资金流增强。显式筛选条件缺少数据时报error,filters_applied只列实际执行的条件。候选factor_coverage列出可用/缺失因子、加权覆盖率和effective_weights;L1与L2均按可用因子归一化后排序,缺失/非有限值不按零分计;L2另返回effective_scores供结合市场系数复算final,按可用因子重归一化,高分不代表数据完整。选股预算按候选数量及采集批次计算,top须为正整数。",
|
|
581
822
|
parameters: Type.Object({
|
|
582
823
|
market: Type.Optional(
|
|
583
824
|
Type.Union(
|
|
@@ -613,7 +854,7 @@ export default definePluginEntry({
|
|
|
613
854
|
api.registerTool({
|
|
614
855
|
name: "run_backtest",
|
|
615
856
|
description:
|
|
616
|
-
"策略回测(AlphaEvo)。读取YAML策略定义,在历史数据上模拟交易,输出收益率/回撤/胜率等指标。只想知道单个技术信号的历史胜率用更轻量的 evaluate_signal",
|
|
857
|
+
"策略回测(AlphaEvo)。读取YAML策略定义,在历史数据上模拟交易,输出收益率/回撤/胜率等指标。只想知道单个技术信号的历史胜率用更轻量的 evaluate_signal。period为实际数据期间,requested_period保留请求期间,warnings提示覆盖差异;年化按实际期间计算。默认前日收盘信号、次日开盘成交;YAML simulation.execution=same_close可复现旧假设。execution返回模型、阻止成交次数和未模拟约束;零成交量及带历史限价的一字板不成交。",
|
|
617
858
|
parameters: Type.Object({
|
|
618
859
|
strategy: Type.String({ description: "策略YAML文件路径" }),
|
|
619
860
|
symbol: Type.String({ description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" }),
|
|
@@ -922,7 +1163,7 @@ export default definePluginEntry({
|
|
|
922
1163
|
api.registerTool({
|
|
923
1164
|
name: "screen_risk",
|
|
924
1165
|
description:
|
|
925
|
-
"A股风险专项筛查 — 检查估值、技术预警、解禁、减持、业绩预警、监管和行业政策,返回风险评级和 veto_buy
|
|
1166
|
+
"A股风险专项筛查 — 检查估值、技术预警、解禁、减持、业绩预警、监管和行业政策,返回风险评级和 veto_buy。新闻搜索命中是待核实线索,不是已证实风险。data_complete和warnings标明覆盖;数据不足时risk_level=unknown,risk_score或veto_buy可为null,不能视为低风险",
|
|
926
1167
|
parameters: Type.Object({
|
|
927
1168
|
symbol: Type.String({ description: "A股股票代码,如 600519" }),
|
|
928
1169
|
name: Type.Optional(
|
|
@@ -961,7 +1202,7 @@ export default definePluginEntry({
|
|
|
961
1202
|
api.registerTool({
|
|
962
1203
|
name: "get_market_review",
|
|
963
1204
|
description:
|
|
964
|
-
"大盘复盘 —
|
|
1205
|
+
"大盘复盘 — 获取市场日度复盘数据,包含指数、涨跌统计、板块排名、新闻、市场温度与策略建议。复盘类需求的首选,无需再分别调指数/统计/板块工具。数据不足时温度score及strategy_stance为null,信号unknown;warnings/data_quality说明限制",
|
|
965
1206
|
parameters: Type.Object({
|
|
966
1207
|
market: Type.Optional(
|
|
967
1208
|
Type.Union(
|
|
@@ -1086,7 +1327,7 @@ export default definePluginEntry({
|
|
|
1086
1327
|
api.registerTool({
|
|
1087
1328
|
name: "render_stock_report",
|
|
1088
1329
|
description:
|
|
1089
|
-
"股票分析报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 skill 提供的 report_schema 为准,不要自造字段。template: brief|full
|
|
1330
|
+
"股票分析报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 skill 提供的 report_schema 为准,不要自造字段。template: brief|full。全部分析完成后的最后一步调用。仅渲染,不保存不推送。report可包含evidence(path/label/value/source/as_of)与data_quality(flags/limitations),brief/full均展示证据和限制。",
|
|
1090
1331
|
parameters: Type.Object({
|
|
1091
1332
|
report: Type.Object({}, { additionalProperties: true, description: "结构化股票报告 JSON" }),
|
|
1092
1333
|
template: Type.Optional(
|
|
@@ -1146,7 +1387,7 @@ export default definePluginEntry({
|
|
|
1146
1387
|
api.registerTool({
|
|
1147
1388
|
name: "build_watchlist_context",
|
|
1148
1389
|
description:
|
|
1149
|
-
"自选股上下文包 — 对多只股票输出评分/趋势/异常/风险/建议 next_tools 的 agent 友好摘要。宿主 agent
|
|
1390
|
+
"自选股上下文包 — 对多只股票输出评分/趋势/异常/风险/建议 next_tools 的 agent 友好摘要。宿主 agent 决定如何写日报或深入分析。异动检查失败时anomaly_status=unavailable、anomaly_count=null,保留anomaly_error/warnings;汇总计入partial",
|
|
1150
1391
|
parameters: Type.Object({
|
|
1151
1392
|
symbols: Type.String({ description: "逗号分隔的股票代码列表" }),
|
|
1152
1393
|
include_market_review: Type.Optional(
|
|
@@ -1201,7 +1442,7 @@ export default definePluginEntry({
|
|
|
1201
1442
|
api.registerTool({
|
|
1202
1443
|
name: "check_alert_rules",
|
|
1203
1444
|
description:
|
|
1204
|
-
"无状态告警规则检查 — 传入规则数组,返回当前是否触发。规则类型:price_below/price_above/change_pct_above/change_pct_below/volume_ratio_above/anomaly/risk_veto/risk_level_at_least
|
|
1445
|
+
"无状态告警规则检查 — 传入规则数组,返回当前是否触发。规则类型:price_below/price_above/change_pct_above/change_pct_below/volume_ratio_above/anomaly/risk_veto/risk_level_at_least。不做调度不存历史。依赖数据不可用时evaluated条目含error,meta.warnings提示缺失,triggered=false不代表检查成功",
|
|
1205
1446
|
parameters: Type.Object({
|
|
1206
1447
|
symbol: Type.String({ description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" }),
|
|
1207
1448
|
rules: Type.Array(
|
|
@@ -1263,7 +1504,7 @@ export default definePluginEntry({
|
|
|
1263
1504
|
api.registerTool({
|
|
1264
1505
|
name: "evaluate_signals",
|
|
1265
1506
|
description:
|
|
1266
|
-
"评估到期信号:拉取记录日之后的日K,判定 target_hit/stop_hit/timeout 并计算收益,回写存储。记录建议用 record_signal,胜率复盘用 get_signal_summary",
|
|
1507
|
+
"评估到期信号:拉取记录日之后的日K,判定 target_hit/stop_hit/timeout 并计算收益,回写存储。记录建议用 record_signal,胜率复盘用 get_signal_summary。历史K线未覆盖记录日时skipped_no_data并保持未结算,不能用较新行情代替。原始信号价与复权K线须有可核实的adjustment_factor,缺失则skipped_price_basis保持未结算。CLI预算300秒,截止前返回并保存已完成结果;complete/deferred/warnings说明未处理记录,下次可重试",
|
|
1267
1508
|
parameters: Type.Object({
|
|
1268
1509
|
symbol: Type.Optional(
|
|
1269
1510
|
Type.String({ description: "股票代码(可选,只评估该股的信号)" })
|
|
@@ -1280,7 +1521,7 @@ export default definePluginEntry({
|
|
|
1280
1521
|
api.registerTool({
|
|
1281
1522
|
name: "get_signal_summary",
|
|
1282
1523
|
description:
|
|
1283
|
-
"信号胜率汇总(可按 source/symbol/status
|
|
1524
|
+
"信号胜率汇总(可按 source/symbol/status 过滤):胜率、平均收益、结果分布与明细。by_source附avg_return_pct、return_samples和sample_warning;仅观察性复盘,样本少不能认定策略有效。",
|
|
1284
1525
|
parameters: Type.Object({
|
|
1285
1526
|
source: Type.Optional(Type.String({ description: "按信号来源过滤(可选)" })),
|
|
1286
1527
|
symbol: Type.Optional(Type.String({ description: "按股票代码过滤(可选)" })),
|
package/openclaw.plugin.json
CHANGED
|
@@ -60,7 +60,17 @@
|
|
|
60
60
|
"get_earnings_calendar",
|
|
61
61
|
"get_shareholder_structure",
|
|
62
62
|
"get_etf_details",
|
|
63
|
-
"get_dividends"
|
|
63
|
+
"get_dividends",
|
|
64
|
+
"get_announcements",
|
|
65
|
+
"get_us_holdings",
|
|
66
|
+
"get_insider_trades",
|
|
67
|
+
"compare_stocks",
|
|
68
|
+
"analyze_disclosure_changes",
|
|
69
|
+
"analyze_portfolio_risk",
|
|
70
|
+
"calculate_position_size",
|
|
71
|
+
"analyze_event_study",
|
|
72
|
+
"validate_backtest",
|
|
73
|
+
"compare_analysis_snapshots"
|
|
64
74
|
]
|
|
65
75
|
},
|
|
66
76
|
"activation": {
|
package/package.json
CHANGED
|
@@ -18,17 +18,24 @@
|
|
|
18
18
|
"type": "object",
|
|
19
19
|
"description": "市场温度(来自 market_review.review)",
|
|
20
20
|
"properties": {
|
|
21
|
-
"score": { "type": "number", "minimum": 0, "maximum": 100 },
|
|
22
|
-
"level": { "type": "string", "enum": ["constructive", "neutral", "weak"] },
|
|
23
|
-
"signal": { "type": "string", "enum": ["green", "yellow", "red"] }
|
|
21
|
+
"score": { "type": ["number", "null"], "minimum": 0, "maximum": 100 },
|
|
22
|
+
"level": { "type": "string", "enum": ["constructive", "neutral", "weak", "unknown"] },
|
|
23
|
+
"signal": { "type": "string", "enum": ["green", "yellow", "red", "unknown"] }
|
|
24
24
|
},
|
|
25
25
|
"required": ["score", "signal"]
|
|
26
26
|
},
|
|
27
27
|
"strategy_stance": {
|
|
28
|
-
"type": "string",
|
|
29
|
-
"enum": ["offensive", "balanced", "defensive"],
|
|
28
|
+
"type": ["string", "null"],
|
|
29
|
+
"enum": ["offensive", "balanced", "defensive", null],
|
|
30
30
|
"description": "建议策略姿态"
|
|
31
31
|
},
|
|
32
|
+
"data_quality": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"properties": {
|
|
35
|
+
"flags": { "type": "array", "items": { "type": "string" } },
|
|
36
|
+
"limitations": { "type": "array", "items": { "type": "string" } }
|
|
37
|
+
}
|
|
38
|
+
},
|
|
32
39
|
"regime": {
|
|
33
40
|
"type": "object",
|
|
34
41
|
"description": "市场阶段(来自 detect_market_regime)",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"type": "object",
|
|
49
49
|
"description": "风险筛查结果(来自 screen_risk)",
|
|
50
50
|
"properties": {
|
|
51
|
-
"risk_level": { "type": "string", "enum": ["low", "medium", "high"] },
|
|
52
|
-
"risk_score": { "type": "integer", "minimum": 0, "maximum": 100 },
|
|
53
|
-
"veto_buy": { "type": "boolean" },
|
|
51
|
+
"risk_level": { "type": "string", "enum": ["low", "medium", "high", "unknown"] },
|
|
52
|
+
"risk_score": { "type": ["integer", "null"], "minimum": 0, "maximum": 100 },
|
|
53
|
+
"veto_buy": { "type": ["boolean", "null"] },
|
|
54
54
|
"flags": {
|
|
55
55
|
"type": "array",
|
|
56
56
|
"items": {
|
|
@@ -124,7 +124,71 @@
|
|
|
124
124
|
"action_checklist": { "type": "array", "items": { "type": "string" } }
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
|
-
"risk_warning": { "type": "array", "items": { "type": "string" } }
|
|
127
|
+
"risk_warning": { "type": "array", "items": { "type": "string" } },
|
|
128
|
+
"data_quality": {
|
|
129
|
+
"type": "object",
|
|
130
|
+
"properties": {
|
|
131
|
+
"flags": {
|
|
132
|
+
"type": "array",
|
|
133
|
+
"items": {
|
|
134
|
+
"type": "string",
|
|
135
|
+
"enum": [
|
|
136
|
+
"partial_data",
|
|
137
|
+
"stale_quote",
|
|
138
|
+
"conflicting_data",
|
|
139
|
+
"insufficient_sample"
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"limitations": {
|
|
144
|
+
"type": "array",
|
|
145
|
+
"items": {
|
|
146
|
+
"type": "string"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"required": [
|
|
151
|
+
"flags",
|
|
152
|
+
"limitations"
|
|
153
|
+
]
|
|
154
|
+
},
|
|
155
|
+
"evidence": {
|
|
156
|
+
"type": "array",
|
|
157
|
+
"items": {
|
|
158
|
+
"type": "object",
|
|
159
|
+
"properties": {
|
|
160
|
+
"path": {
|
|
161
|
+
"type": "string",
|
|
162
|
+
"description": "原始工具结果路径,例如 get_quote.price;已知返回对象中未提供的末级字段只能以 value=null 表示未知,其 source/as_of 可为 null,若填写必须来自父对象;不得跨越缺失对象或数组编造路径。"
|
|
163
|
+
},
|
|
164
|
+
"label": {
|
|
165
|
+
"type": "string",
|
|
166
|
+
"description": "读者可理解的指标名"
|
|
167
|
+
},
|
|
168
|
+
"value": {},
|
|
169
|
+
"source": {
|
|
170
|
+
"description": "引用已返回字段时,沿 path 继承最近父对象的 source(该键缺失时用 snapshot_source);子对象来源覆盖祖先,显式 null 保持未知。数组项和警告字符串同样继承,不能仅因叶子没有 source 就填 null;整条路径未提供来源时才填 null。",
|
|
171
|
+
"type": [
|
|
172
|
+
"string",
|
|
173
|
+
"null"
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
"as_of": {
|
|
177
|
+
"description": "引用已返回字段时,沿 path 继承最近父对象的 data_as_of,子对象值(包括显式 null)覆盖祖先;数组项同样继承。整条路径均缺失时为 null,保留完整时间与时区。report_date 是报告期,不能代替此时间。",
|
|
178
|
+
"type": [
|
|
179
|
+
"string",
|
|
180
|
+
"null"
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"required": [
|
|
185
|
+
"path",
|
|
186
|
+
"value",
|
|
187
|
+
"source",
|
|
188
|
+
"as_of"
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
}
|
|
128
192
|
},
|
|
129
193
|
"required": ["stock_name", "stock_code", "analysis_date", "sentiment_score",
|
|
130
194
|
"decision_type", "confidence", "core_conclusion"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import budgets from "../tools/cli_budgets.json" with { type: "json" };
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
|
|
4
|
+
// Hosts leave the CLI time to return its own structured failure.
|
|
5
|
+
export function commandTimeout(script, args) {
|
|
6
|
+
const key = `${basename(script)}:${args[0] ?? ""}`;
|
|
7
|
+
let budget = budgets[key] ?? budgets.default;
|
|
8
|
+
const option = (name, fallback) => args.includes(name) ? args[args.indexOf(name) + 1] ?? fallback : fallback;
|
|
9
|
+
const positiveInt = (value, fallback) => /^\d+$/.test(String(value)) && Number(value) > 0 ? Number(value) : fallback;
|
|
10
|
+
if (key === "screener.py:screen") {
|
|
11
|
+
budget += Math.ceil(positiveInt(option("--top", 20), 20) / budgets.l2_workers) * budgets.l2_batch;
|
|
12
|
+
} else if (key === "watchlist.py:analyze" || key === "watchlist_context.py:build") {
|
|
13
|
+
const count = String(args[1] ?? "").split(",").filter(s => s.trim()).length;
|
|
14
|
+
const workers = positiveInt(option("--workers", 3), 3);
|
|
15
|
+
budget += Math.ceil(count / workers) * budgets.watchlist_item;
|
|
16
|
+
if (key === "watchlist_context.py:build") {
|
|
17
|
+
budget += Math.ceil(count / Math.min(workers * 2, 6)) * budgets["anomaly_detect.py:detect"];
|
|
18
|
+
if (args.includes("--include-market-review")) budget += 3 * budgets["market_review.py:review"] + 30;
|
|
19
|
+
}
|
|
20
|
+
} else if (key === "market_review.py:review" && option("--market", "A") === "all") {
|
|
21
|
+
budget = 3 * budget + 30;
|
|
22
|
+
} else if (key === "technical.py:analyze" && args.includes("--periods")) {
|
|
23
|
+
const periods = String(option("--periods", "daily")).split(",").map(p => p.trim()).filter(Boolean);
|
|
24
|
+
budget *= new Set([option("--period", "daily"), ...periods]).size;
|
|
25
|
+
}
|
|
26
|
+
return budget * 1000 + 30_000;
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mkdtemp, writeFile, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
// Large reports/K-lines exceed Windows argv limits. Remove transport files even on failure.
|
|
6
|
+
export async function withJsonInput(input, execute) {
|
|
7
|
+
let directory;
|
|
8
|
+
let result;
|
|
9
|
+
try {
|
|
10
|
+
directory = await mkdtemp(join(tmpdir(), "stock-analysis-"));
|
|
11
|
+
const path = join(directory, "input.json");
|
|
12
|
+
await writeFile(path, JSON.stringify(input), { encoding: "utf8", mode: 0o600 });
|
|
13
|
+
result = await execute(path);
|
|
14
|
+
} catch {
|
|
15
|
+
result = JSON.stringify({ error: "Analysis command failed; check input and interpreter/dependencies" });
|
|
16
|
+
} finally {
|
|
17
|
+
if (directory) {
|
|
18
|
+
try {
|
|
19
|
+
await rm(directory, { recursive: true, force: true });
|
|
20
|
+
} catch {
|
|
21
|
+
result = JSON.stringify({ error: "Could not remove temporary analysis input" });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
package/scripts/setup-python.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -14,14 +14,14 @@ const venvDir = join(pkgDir, ".venv");
|
|
|
14
14
|
const venvPython = venvPythonPath(pkgDir);
|
|
15
15
|
const requirements = join(pkgDir, "tools", "requirements.txt");
|
|
16
16
|
|
|
17
|
-
function run(
|
|
18
|
-
|
|
17
|
+
function run(bin, args) {
|
|
18
|
+
execFileSync(bin, args, { stdio: "inherit", timeout: 1_800_000 });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function findPython() {
|
|
22
22
|
for (const name of ["python3", "python"]) {
|
|
23
23
|
try {
|
|
24
|
-
const ver =
|
|
24
|
+
const ver = execFileSync(name, ["--version"], { stdio: "pipe" }).toString().trim();
|
|
25
25
|
const match = ver.match(/(\d+)\.(\d+)/);
|
|
26
26
|
if (match && (parseInt(match[1]) > 3 || (parseInt(match[1]) === 3 && parseInt(match[2]) >= 10))) {
|
|
27
27
|
return name;
|
|
@@ -42,10 +42,10 @@ try {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (!existsSync(venvDir)) {
|
|
45
|
-
run(
|
|
45
|
+
run(python, ["-m", "venv", venvDir]);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
run(
|
|
48
|
+
run(venvPython, ["-m", "pip", "install", "-q", "-r", requirements]);
|
|
49
49
|
} catch (err) {
|
|
50
50
|
console.warn(
|
|
51
51
|
`\n[pi-stock-analysis] Python setup failed: ${err.message}\n` +
|