@v587d/capital-generation 2.31.5 → 2.31.6
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/CHANGELOG.md +23 -0
- package/README.md +2 -2
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/data-collector/hub.d.ts +2 -0
- package/lib/data-collector/hub.js +58 -0
- package/lib/sources/eastmoney-http.js +3 -2
- package/lib/sources/sec-http.d.ts +2 -6
- package/lib/sources/sec-http.js +21 -16
- package/lib/sources/us-official-http.d.ts +2 -0
- package/lib/sources/us-official-http.js +19 -14
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +1 -1
- package/watchlist/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,29 @@
|
|
|
7
7
|
- **第三位(patch)**:不破坏既有工具 / 配置 / 会话的新增与修复(如 2.1.1、2.1.2)。
|
|
8
8
|
- **第二位(minor)**:有需要用户知晓的行为变更,且段内附迁移说明(如 2.1.0 的图表呈现通道重做、2.2.0 的数据源与检索来源扩容、2.4.0 的**必须换宿主版本**、2.9.0 的选择器收敛与质检前置——本插件自己的工具与数据契约没变,所以只抬第二位)。
|
|
9
9
|
|
|
10
|
+
## [2.31.6] - 2026-11-28
|
|
11
|
+
|
|
12
|
+
数据契约巡检加固:修复巡检假绿、SEC 日索引解析与路径、FINRA 多票结算日发现,并补齐 11 条新增能力的
|
|
13
|
+
输出护栏与真实 SEC fixture。SEC 五条仍保持巡检 shadow,等待可访问 SEC 的出口完成实时 idx 复核后转正。
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- 契约巡检同时校验生产 `validateOutput` 与 `output_schema`;required、额外字段、类型、nullable 与非有限数
|
|
18
|
+
不再漏报,已解析的上游结构错误统一归 `GUARD`,不再埋进 `TRANSPORT`。
|
|
19
|
+
- `sec_daily_filings` 使用 SEC 官方 `QTR{季}` 目录,支持跨两行的定宽表头,并接受 `YYYYMMDD` / `YYYY-MM-DD`
|
|
20
|
+
申报日;真实 2018 idx 摘录已写入回归 fixture。
|
|
21
|
+
- SEC 五条巡检样本补 `minRows` 与关键 identity;ticker、submissions、全文检索和 frames fixture 使用真实
|
|
22
|
+
报文摘录,补齐 instant / duration 两个分支。
|
|
23
|
+
- `finra_short_interest` 自动发现结算日时按全部 symbols 判定,不再因首票缺数误退到旧结算日。
|
|
24
|
+
- Treasury 1830 天区间上限在参数层执行;11 条新增能力的 `validateOutput` 完整执行各自 output schema。
|
|
25
|
+
- 契约巡检清单与设计文档解除 Git 忽略,CI checkout 可以读取转正 SOP 与证据。
|
|
26
|
+
|
|
27
|
+
### Notes
|
|
28
|
+
|
|
29
|
+
- `sec_filings` 明确保持 recent-only;更早历史在 `filings.files`,本能力不自动合并。
|
|
30
|
+
- 回归:`npm test` **1919 pass / 0 fail**;双出口复跑 6 条 active 均至少一个出口 PASS,SEC 直连仍 403。
|
|
31
|
+
- 版本:根包 + 四个随包嵌套包 + `LOCAL_FETCH_CLIENT_VERSION` / `WIND_CLIENT_VERSION` 同步 2.31.6。
|
|
32
|
+
|
|
10
33
|
## [2.31.5] - 2026-11-27
|
|
11
34
|
|
|
12
35
|
数据面扩容:新增 11 条 `data_collector` 能力(162 → 173),覆盖港美股财务、美债与 NY Fed 利率、
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green" alt="License"></a>
|
|
4
4
|
<a href="https://github.com/v587d/capital-generation"><img src="https://img.shields.io/badge/Financial%20Market-CN%20%7C%20HK%20%7C%20US-orange" alt="Market·CN+HK+US"></a>
|
|
5
5
|
<a href="https://github.com/deepseek-ai"><img src="https://img.shields.io/badge/DSH%20Baseline-0.2.2--rc.5-blue" alt="DSH@0.2.2-rc.5"></a>
|
|
6
|
-
<a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.31.
|
|
6
|
+
<a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.31.6-9cf" alt="Version"></a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/@v587d/capital-generation"><img src="https://img.shields.io/npm/v/%40v587d%2Fcapital-generation" alt="npm version"></a>
|
|
8
8
|
</p>
|
|
9
9
|
|
|
@@ -230,7 +230,7 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
|
|
|
230
230
|
- **配置在哪?** 打开「插件」→ 已安装的 **Capital Generation**,插件介绍下方就是「数据源 / 投研自动化 / 精选 Skills / 包含的组件 / 分析环境」五格,五把密钥都在第一格;第二格可指定任务统一使用的默认工作区,也能改自动检查间隔与最长运行时间等上限;第五格准备 Python 分析环境;不在 DSH 的普通「设置」页面,也不用点进任何一行组件。保存密钥后新建会话再试。
|
|
231
231
|
- **升级到 2.9.0 后,分析师和绘图专员去哪了?** 这一版把它们收进自动模式内部,不再出现在选择器与预设管理里,避免误开一个没有取数入口的空会话。旧会话仍能按原身份恢复;新任务直接用自动模式提出即可。
|
|
232
232
|
- **宿主更新后插件显示异常、三个模式消失?** 插件只支持**同一 minor** 的宿主(本版是 `>=0.2.2-rc.5 <0.2.3-0`):宿主跨到 0.2.3 及以上时,旧插件会被启动拒载(插件页显示「异常」)。先把宿主升到与插件同一条 minor,再在插件页更新插件;应急可用版本豁免(有崩溃风险,见 CHANGELOG 的 Migration)。日志里出现「宿主 dsh … 未逐项验证」说明你跑在同一 minor 的未验证补丁版上——能跑,但遇异常请先升级插件并把那行日志附在 issue 里。
|
|
233
|
-
- **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.31.
|
|
233
|
+
- **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.31.6` 或 `@2.31.6`。
|
|
234
234
|
- **刚发布的新版本装不到?** 桌面端取包时会跳过**刚发布不久**的版本(宿主侧包管理器的发布冷却策略,实测会静默装成上一个版本),国内镜像的同步也可能滞后一段时间。急着用最新代码,改用仓库地址安装最直接;但仓库地址安装的是 git 依赖,插件页不显示「版本」检查。
|
|
235
235
|
- **插件页的「版本」段怎么用?** 只有用包名从 npm 安装的版本才有;它只列比当前新的版本。回旧版要先卸载,再安装 `@v587d/capital-generation@版本号`(桌面端地址末尾加 `#v版本号`);旧版必须匹配当前 DSH 基线,对应关系见 [CHANGELOG 的 Migration](CHANGELOG.md)。
|
|
236
236
|
- **网页抓取失败?** 配置卡片中的「允许启动本地提取网页内容」默认开启:AnySearch 提取失败时可尝试本机直连。关闭后,本机直连的具名来源查询也不可用;请检查该开关和网络连接。
|
package/automation/package.json
CHANGED
package/chart-ui/package.json
CHANGED
package/config/package.json
CHANGED
|
@@ -55,6 +55,8 @@ export interface CapabilityDetail extends CapabilitySummary {
|
|
|
55
55
|
input_schema: object;
|
|
56
56
|
output_fields: string | null;
|
|
57
57
|
}
|
|
58
|
+
/** Validate the JSON Schema subset used by DataSource output contracts. */
|
|
59
|
+
export declare function outputSchemaIssues(schema: unknown, value: unknown, path?: string): string[];
|
|
58
60
|
export interface DataSource {
|
|
59
61
|
schema: SchemaDescriptor;
|
|
60
62
|
execute(request: DataRequest, signal: AbortSignal): Promise<{
|
|
@@ -39,6 +39,64 @@ function codePointLength(value) {
|
|
|
39
39
|
function isPlainRecord(value) {
|
|
40
40
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
41
41
|
}
|
|
42
|
+
/** Validate the JSON Schema subset used by DataSource output contracts. */
|
|
43
|
+
export function outputSchemaIssues(schema, value, path = '$') {
|
|
44
|
+
if (!isPlainRecord(schema) || Object.keys(schema).length === 0)
|
|
45
|
+
return [];
|
|
46
|
+
if (Array.isArray(schema.oneOf)) {
|
|
47
|
+
const matches = schema.oneOf.filter((branch) => outputSchemaIssues(branch, value, path).length === 0);
|
|
48
|
+
return matches.length === 1 ? [] : [`${path} must match exactly one oneOf branch (matched ${matches.length})`];
|
|
49
|
+
}
|
|
50
|
+
const type = schema.type;
|
|
51
|
+
if (typeof type === 'string' && !matchesOutputType(value, type))
|
|
52
|
+
return [`${path} must be ${type}`];
|
|
53
|
+
if (Array.isArray(schema.enum) && !schema.enum.includes(value))
|
|
54
|
+
return [`${path} must be one of ${schema.enum.join(', ')}`];
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
const issues = [];
|
|
57
|
+
if (isPlainRecord(schema.items)) {
|
|
58
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
59
|
+
if (!(index in value))
|
|
60
|
+
issues.push(`${path}[${index}] is an array hole`);
|
|
61
|
+
else
|
|
62
|
+
issues.push(...outputSchemaIssues(schema.items, value[index], `${path}[${index}]`));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return issues;
|
|
66
|
+
}
|
|
67
|
+
if (!isPlainRecord(value))
|
|
68
|
+
return [];
|
|
69
|
+
const properties = isPlainRecord(schema.properties) ? schema.properties : {};
|
|
70
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
71
|
+
const issues = [];
|
|
72
|
+
for (const key of required) {
|
|
73
|
+
if (typeof key !== 'string' || !Object.hasOwn(value, key) || value[key] === undefined)
|
|
74
|
+
issues.push(`${path}.${String(key)} is required`);
|
|
75
|
+
}
|
|
76
|
+
if (schema.additionalProperties === false) {
|
|
77
|
+
for (const key of Object.keys(value)) {
|
|
78
|
+
if (!Object.hasOwn(properties, key))
|
|
79
|
+
issues.push(`${path}.${key} is not declared`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const [key, child] of Object.entries(properties)) {
|
|
83
|
+
if (Object.hasOwn(value, key) && value[key] !== undefined)
|
|
84
|
+
issues.push(...outputSchemaIssues(child, value[key], `${path}.${key}`));
|
|
85
|
+
}
|
|
86
|
+
return issues;
|
|
87
|
+
}
|
|
88
|
+
function matchesOutputType(value, type) {
|
|
89
|
+
switch (type) {
|
|
90
|
+
case 'object': return isPlainRecord(value);
|
|
91
|
+
case 'array': return Array.isArray(value);
|
|
92
|
+
case 'string': return typeof value === 'string';
|
|
93
|
+
case 'number': return typeof value === 'number' && Number.isFinite(value);
|
|
94
|
+
case 'integer': return Number.isSafeInteger(value);
|
|
95
|
+
case 'boolean': return typeof value === 'boolean';
|
|
96
|
+
case 'null': return value === null;
|
|
97
|
+
default: return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
42
100
|
function inlineFieldText(value) {
|
|
43
101
|
if (typeof value !== 'string')
|
|
44
102
|
return undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildDataKey } from '../data-collector/hub.js';
|
|
1
|
+
import { buildDataKey, outputSchemaIssues } from '../data-collector/hub.js';
|
|
2
2
|
import { getDataTimeContract } from '../time/tools.js';
|
|
3
3
|
import { sharedEastmoneyClient, sharedEastmoneyThrottle, EastmoneyTransportError } from '../net/eastmoney-client.js';
|
|
4
4
|
import { normalizeEastmoneyAshareIdentity, normalizeEastmoneyBoardIdentity, normalizeEastmoneySecurityIdentity } from './security-identity.js';
|
|
@@ -1353,7 +1353,8 @@ async function executeBondList(params, signal) {
|
|
|
1353
1353
|
function createSource(options) {
|
|
1354
1354
|
const schema = { capability: options.capability, time_contract: getDataTimeContract(options.capability), name: options.name, source: `http:eastmoney.${options.capability}`, data_key: buildDataKey('eastmoney', 'http', options.capability), source_label: 'eastmoney', paginated: options.paginated === true, cacheMaxAgeMs: options.cacheMaxAgeMs, rowShape: options.rowShape, summary: options.summary, description: options.description, input_schema: options.inputSchema, output_schema: options.outputSchema };
|
|
1355
1355
|
const normalize = (params) => options.normalize(params);
|
|
1356
|
-
const
|
|
1356
|
+
const semanticGuard = options.validateOutput ?? ((data) => isRecord(data) && Array.isArray(data.item) && isRecord(data.pagination));
|
|
1357
|
+
const validateOutput = (data) => semanticGuard(data) && outputSchemaIssues(options.outputSchema, data).length === 0;
|
|
1357
1358
|
return { schema, normalizeParams: normalize, validateOutput, execute: async (request, signal) => options.execute(normalize(request.params), signal) };
|
|
1358
1359
|
}
|
|
1359
1360
|
const dateRangeInput = {
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
/** SEC EDGAR sources: ticker→CIK, submissions, daily index
|
|
2
|
-
*
|
|
3
|
-
* ⛔ Not wired into `createUsOfficialSources()` yet: SEC rate-limited this egress (Akamai 403
|
|
4
|
-
* "Request Rate Threshold Exceeded") while the code was written, so field mappings are still
|
|
5
|
-
* awaiting live-payload verification. Wire it in only after `npm run contract:probe -- --only sec`
|
|
6
|
-
* passes against real responses; a guard that rejects the official sample is a real incident (§10.2).
|
|
1
|
+
/** SEC EDGAR sources: ticker→CIK, submissions, daily index, full-text search and XBRL frames.
|
|
2
|
+
* Contract probes stay shadow until a live SEC egress passes; fixtures mirror official payloads.
|
|
7
3
|
*/
|
|
8
4
|
import type { DataSource } from '../data-collector/hub.js';
|
|
9
5
|
export declare function createSecSources(): DataSource[];
|
package/lib/sources/sec-http.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
/** SEC EDGAR sources: ticker→CIK, submissions, daily index
|
|
2
|
-
*
|
|
3
|
-
* ⛔ Not wired into `createUsOfficialSources()` yet: SEC rate-limited this egress (Akamai 403
|
|
4
|
-
* "Request Rate Threshold Exceeded") while the code was written, so field mappings are still
|
|
5
|
-
* awaiting live-payload verification. Wire it in only after `npm run contract:probe -- --only sec`
|
|
6
|
-
* passes against real responses; a guard that rejects the official sample is a real incident (§10.2).
|
|
1
|
+
/** SEC EDGAR sources: ticker→CIK, submissions, daily index, full-text search and XBRL frames.
|
|
2
|
+
* Contract probes stay shadow until a live SEC egress passes; fixtures mirror official payloads.
|
|
7
3
|
*/
|
|
8
|
-
import { buildDataKey } from '../data-collector/hub.js';
|
|
4
|
+
import { buildDataKey, outputSchemaIssues } from '../data-collector/hub.js';
|
|
9
5
|
import { getDataTimeContract } from '../time/tools.js';
|
|
10
6
|
import { createRequestThrottle } from '../net/throttle.js';
|
|
11
7
|
const SEC_WWW = 'https://www.sec.gov';
|
|
@@ -309,13 +305,18 @@ function normalizeDailyFilings(params) {
|
|
|
309
305
|
const form = params.form === undefined ? undefined : String(params.form).trim().toUpperCase();
|
|
310
306
|
return { filing_date, ...(form === undefined ? {} : { form }) };
|
|
311
307
|
}
|
|
312
|
-
/** `form.YYYYMMDD.idx`
|
|
308
|
+
/** `form.YYYYMMDD.idx` uses pipes or fixed-width columns; the fixed-width header may wrap. */
|
|
313
309
|
function parseDailyIndex(text, label) {
|
|
314
310
|
const lines = text.split(/\r?\n/);
|
|
315
|
-
const headerIndex = lines.findIndex((line) => /Form Type/i.test(line) && /
|
|
311
|
+
const headerIndex = lines.findIndex((line) => /Form Type/i.test(line) && /Company Name/i.test(line));
|
|
316
312
|
if (headerIndex < 0)
|
|
317
313
|
throw sourceError(`${label} has no header row`);
|
|
318
|
-
|
|
314
|
+
let separatorIndex = headerIndex;
|
|
315
|
+
while (separatorIndex < lines.length && !/^-{5,}/.test(lines[separatorIndex].trim()))
|
|
316
|
+
separatorIndex += 1;
|
|
317
|
+
if (separatorIndex >= lines.length)
|
|
318
|
+
throw sourceError(`${label} has no header separator`);
|
|
319
|
+
const header = lines.slice(headerIndex, separatorIndex).filter((line) => line.trim().length > 0).join(' ');
|
|
319
320
|
const pipe = header.includes('|');
|
|
320
321
|
const cellsOf = (line) => pipe
|
|
321
322
|
? line.split('|').map((cell) => cell.trim())
|
|
@@ -330,15 +331,19 @@ function parseDailyIndex(text, label) {
|
|
|
330
331
|
if ([formIndex, companyIndex, cikIndex, dateIndex, fileIndex].some((index) => index < 0))
|
|
331
332
|
throw sourceError(`${label} header columns changed: ${header}`);
|
|
332
333
|
const rows = [];
|
|
333
|
-
for (const line of lines.slice(
|
|
334
|
+
for (const line of lines.slice(separatorIndex + 1)) {
|
|
334
335
|
if (line.trim().length === 0 || /^-{5,}/.test(line.trim()))
|
|
335
336
|
continue;
|
|
336
337
|
const cells = cellsOf(line);
|
|
337
338
|
if (cells.length <= Math.max(formIndex, companyIndex, cikIndex, dateIndex, fileIndex))
|
|
338
339
|
throw sourceError(`${label} row has ${cells.length} cells: ${line.slice(0, 120)}`);
|
|
339
|
-
const
|
|
340
|
+
const rawDate = cells[dateIndex];
|
|
341
|
+
let filingDate = rawDate;
|
|
342
|
+
if (!DATE_PATTERN.test(filingDate) && /^\d{8}$/.test(filingDate)) {
|
|
343
|
+
filingDate = `${filingDate.slice(0, 4)}-${filingDate.slice(4, 6)}-${filingDate.slice(6, 8)}`;
|
|
344
|
+
}
|
|
340
345
|
if (!DATE_PATTERN.test(filingDate))
|
|
341
|
-
throw sourceError(`${label} row date is not YYYY-MM-DD: ${JSON.stringify(
|
|
346
|
+
throw sourceError(`${label} row date is not YYYYMMDD or YYYY-MM-DD: ${JSON.stringify(rawDate)}`);
|
|
342
347
|
const fileName = cells[fileIndex];
|
|
343
348
|
rows.push({
|
|
344
349
|
form_type: cells[formIndex],
|
|
@@ -357,7 +362,7 @@ async function executeDailyFilings(params, signal) {
|
|
|
357
362
|
const month = Number(filingDate.slice(5, 7));
|
|
358
363
|
const quarter = Math.floor((month - 1) / 3) + 1;
|
|
359
364
|
const compact = filingDate.replaceAll('-', '');
|
|
360
|
-
const url = `${SEC_WWW}/Archives/edgar/daily-index/${year}/
|
|
365
|
+
const url = `${SEC_WWW}/Archives/edgar/daily-index/${year}/QTR${quarter}/form.${compact}.idx`;
|
|
361
366
|
const text = await secText(url, signal, `SEC daily index ${filingDate}`);
|
|
362
367
|
const wantedForm = params.form === undefined ? undefined : String(params.form);
|
|
363
368
|
const rows = parseDailyIndex(text, `SEC daily index ${filingDate}`).filter((row) => wantedForm === undefined || row.form_type === wantedForm);
|
|
@@ -525,7 +530,7 @@ function createSecSource(options) {
|
|
|
525
530
|
return {
|
|
526
531
|
schema,
|
|
527
532
|
normalizeParams: (params) => options.normalize(params),
|
|
528
|
-
validateOutput: options.validateOutput,
|
|
533
|
+
validateOutput: (data) => options.validateOutput(data) && outputSchemaIssues(options.outputSchema, data).length === 0,
|
|
529
534
|
execute: async (request, signal) => options.execute(options.normalize(request.params), signal),
|
|
530
535
|
};
|
|
531
536
|
}
|
|
@@ -577,7 +582,7 @@ export function createSecSources() {
|
|
|
577
582
|
cacheMaxAgeMs: 21_600_000,
|
|
578
583
|
name: 'get_sec_daily_filings',
|
|
579
584
|
summary: 'SEC 日索引(某美东申报日的全部申报)',
|
|
580
|
-
description: '取 SEC EDGAR 某一天的**日索引**(`Archives/edgar/daily-index/{年}/
|
|
585
|
+
description: '取 SEC EDGAR 某一天的**日索引**(`Archives/edgar/daily-index/{年}/QTR{季}/form.{YYYYMMDD}.idx`,零 key):当天所有申报的 form、公司名、CIK、申报日与文件路径。`filing_date` 是**美东申报日**,必须是已发布的工作日;`form` 可选、精确过滤(如 8-K)。一行一条申报;全量日(不限 form)实测可达数千行,按 form 过滤后再用。`url` 指向 `https://www.sec.gov/Archives/{file_name}`(索引条目,不是正文)。⛔ 该日索引不存在(周末/假日/尚未发布)时上游 404,本层响亮失败并提示换工作日,不返回空数组冒充「没有申报」。idx 行格式按表头自适应(有 `|` 按竖线切,否则按 2+ 空格切;定宽表头可跨两行),申报日接受 `YYYYMMDD` 或 `YYYY-MM-DD` 并统一输出后者;表头列缺失、行宽不足、日期畸形都响亮失败。`filing_date` 是申报日,不是报告期。SEC 限速与 UA 同其它 sec_* 能力。',
|
|
581
586
|
inputSchema: {
|
|
582
587
|
type: 'object',
|
|
583
588
|
properties: {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** US official data sources (Treasury, NY Fed): zero-key public endpoints, one throttle per host,
|
|
2
2
|
* rows are plain arrays (no upstream pagination). SEC (same file family) is added separately. */
|
|
3
3
|
import type { DataSource } from '../data-collector/hub.js';
|
|
4
|
+
/** FINRA settles on the 15th and the last business day of each month; probe newest first. */
|
|
5
|
+
export declare function settlementCandidates(today?: string): string[];
|
|
4
6
|
export declare function createUsOfficialSources(): DataSource[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** US official data sources (Treasury, NY Fed): zero-key public endpoints, one throttle per host,
|
|
2
2
|
* rows are plain arrays (no upstream pagination). SEC (same file family) is added separately. */
|
|
3
|
-
import { buildDataKey } from '../data-collector/hub.js';
|
|
4
|
-
import { getDataTimeContract } from '../time/tools.js';
|
|
3
|
+
import { buildDataKey, outputSchemaIssues } from '../data-collector/hub.js';
|
|
4
|
+
import { dayDistance, getDataTimeContract } from '../time/tools.js';
|
|
5
5
|
import { createRequestThrottle } from '../net/throttle.js';
|
|
6
6
|
import { createSecSources } from './sec-http.js';
|
|
7
7
|
const TREASURY_CSV_URL = 'https://home.treasury.gov/resource-center/data-chart-center/interest-rates/daily-treasury-rates.csv';
|
|
@@ -79,6 +79,13 @@ function normalizeDateRange(params) {
|
|
|
79
79
|
throw new Error('start_date must not be later than end_date');
|
|
80
80
|
return { start_date, end_date };
|
|
81
81
|
}
|
|
82
|
+
function normalizeTreasury(params) {
|
|
83
|
+
const range = normalizeDateRange(params);
|
|
84
|
+
if (dayDistance(String(range.start_date), String(range.end_date)) > TREASURY_MAX_DAYS) {
|
|
85
|
+
throw new Error(`Treasury date range exceeds maximum ${TREASURY_MAX_DAYS} days`);
|
|
86
|
+
}
|
|
87
|
+
return range;
|
|
88
|
+
}
|
|
82
89
|
function createSource(options) {
|
|
83
90
|
const schema = {
|
|
84
91
|
capability: options.capability,
|
|
@@ -98,7 +105,7 @@ function createSource(options) {
|
|
|
98
105
|
return {
|
|
99
106
|
schema,
|
|
100
107
|
normalizeParams: (params) => options.normalize(params),
|
|
101
|
-
validateOutput: options.validateOutput,
|
|
108
|
+
validateOutput: (data) => options.validateOutput(data) && outputSchemaIssues(options.outputSchema, data).length === 0,
|
|
102
109
|
execute: async (request, signal) => options.execute(options.normalize(request.params), signal),
|
|
103
110
|
};
|
|
104
111
|
}
|
|
@@ -498,8 +505,7 @@ function normalizeShortInterest(params) {
|
|
|
498
505
|
return { symbols, ...(settlement_date === undefined ? {} : { settlement_date }) };
|
|
499
506
|
}
|
|
500
507
|
/** FINRA settles on the 15th and the last business day of each month; probe newest first. */
|
|
501
|
-
function settlementCandidates() {
|
|
502
|
-
const today = etToday();
|
|
508
|
+
export function settlementCandidates(today = etToday()) {
|
|
503
509
|
const [year, month] = today.split('-').map(Number);
|
|
504
510
|
const candidates = [];
|
|
505
511
|
for (let back = 0; back < 3; back += 1) {
|
|
@@ -552,17 +558,16 @@ async function fetchShortInterest(symbol, settlementDate, signal) {
|
|
|
552
558
|
}
|
|
553
559
|
async function executeShortInterest(params, signal) {
|
|
554
560
|
const symbols = params.symbols;
|
|
555
|
-
|
|
561
|
+
const settlementDate = params.settlement_date === undefined ? undefined : String(params.settlement_date);
|
|
556
562
|
if (settlementDate === undefined) {
|
|
557
563
|
for (const candidate of settlementCandidates()) {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
564
|
+
const rows = [];
|
|
565
|
+
for (const symbol of symbols)
|
|
566
|
+
rows.push(...await fetchShortInterest(symbol, candidate, signal));
|
|
567
|
+
if (rows.length > 0)
|
|
568
|
+
return { data: rows, schema: finraShortInterestRow };
|
|
563
569
|
}
|
|
564
|
-
|
|
565
|
-
throw sourceError('FINRA short interest has no published settlement date in the last 3 months', 'finra_not_published');
|
|
570
|
+
throw sourceError('FINRA short interest has no published settlement date in the last 3 months', 'finra_not_published');
|
|
566
571
|
}
|
|
567
572
|
const rows = [];
|
|
568
573
|
for (const symbol of symbols) {
|
|
@@ -581,7 +586,7 @@ export function createUsOfficialSources() {
|
|
|
581
586
|
inputSchema: dateRangeInput,
|
|
582
587
|
outputSchema: { type: 'array', items: treasuryRow },
|
|
583
588
|
allowed: ['start_date', 'end_date'],
|
|
584
|
-
normalize:
|
|
589
|
+
normalize: normalizeTreasury,
|
|
585
590
|
validateOutput: (data) => Array.isArray(data) && data.every((row) => isRecord(row) && typeof row.date === 'string'),
|
|
586
591
|
execute: executeTreasury,
|
|
587
592
|
}),
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Known limit: DNS resolves per request but the IP is not pinned to the connection,
|
|
4
4
|
* so a rebinding window remains (same trade-off as dsh-search-first).
|
|
5
5
|
*/
|
|
6
|
-
export declare const LOCAL_FETCH_CLIENT_VERSION = "2.31.
|
|
6
|
+
export declare const LOCAL_FETCH_CLIENT_VERSION = "2.31.6";
|
|
7
7
|
export declare const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
|
|
8
8
|
export type LocalFetchErrorCode = 'ABORTED' | 'TIMEOUT' | 'INVALID_URL' | 'BLOCKED_URL' | 'DNS' | 'REDIRECT' | 'HTTP' | 'TOO_LARGE' | 'UNSUPPORTED_CONTENT_TYPE';
|
|
9
9
|
export declare class LocalFetchError extends Error {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* so a rebinding window remains (same trade-off as dsh-search-first).
|
|
5
5
|
*/
|
|
6
6
|
import { htmlToMarkdown, stripInvisibleText } from './html-markdown.js';
|
|
7
|
-
export const LOCAL_FETCH_CLIENT_VERSION = '2.31.
|
|
7
|
+
export const LOCAL_FETCH_CLIENT_VERSION = '2.31.6';
|
|
8
8
|
export const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
|
|
9
9
|
export class LocalFetchError extends Error {
|
|
10
10
|
code;
|
|
@@ -35,7 +35,7 @@ export interface WindCallResult {
|
|
|
35
35
|
code?: WindErrorCode;
|
|
36
36
|
}
|
|
37
37
|
/** Must match `package.json` version; a test pins the two together. */
|
|
38
|
-
export declare const WIND_CLIENT_VERSION = "2.31.
|
|
38
|
+
export declare const WIND_CLIENT_VERSION = "2.31.6";
|
|
39
39
|
export interface WindClient {
|
|
40
40
|
callTool(toolName: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<WindCallResult>;
|
|
41
41
|
}
|
|
@@ -19,7 +19,7 @@ export const WIND_SERVER_ENDPOINTS = {
|
|
|
19
19
|
analytics_data: 'https://mcp.wind.com.cn/vserver_analytics_data/mcp/',
|
|
20
20
|
};
|
|
21
21
|
/** Must match `package.json` version; a test pins the two together. */
|
|
22
|
-
export const WIND_CLIENT_VERSION = '2.31.
|
|
22
|
+
export const WIND_CLIENT_VERSION = '2.31.6';
|
|
23
23
|
function errorText(error) {
|
|
24
24
|
return error instanceof Error ? error.message : String(error);
|
|
25
25
|
}
|
package/package.json
CHANGED
package/watchlist/package.json
CHANGED