@v587d/capital-generation 2.32.0 → 2.32.1
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 +24 -0
- package/README.md +2 -7
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/sources/ftshare-rest.js +1 -1
- package/lib/sources/tencent-http.js +210 -53
- 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,30 @@
|
|
|
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.32.1] - 2026-11-29
|
|
11
|
+
|
|
12
|
+
同步上游 `a-stock-data` v3.10.5:腾讯逐笔换用成交明细接口,修掉旧接口的静默缺量;宏观日历补 `importance = 0` 口径。
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **`tencent_ticks` 静默缺量(数据正确性)**:腾讯同一天的成交明细有多份、分笔与编号略有差异,旧接口(70 笔一页)页与页之间会混用不同副本,重发几笔又缺几笔。实测 2026-11-27 的 000001.SZ:旧实现 4,729 笔、连续竞价段成交额 2,553,523,018 元,腾讯快照 2,605,535,117 元——**少 2.0%(52,012,099 元)却返回成功**;因为成交额核对此前只在「快照日期是上海当天且已收盘」时执行,隔日/周末取上一交易日时被跳过。
|
|
17
|
+
现在改走 `web.ifzq.gtimg.cn/appstock/app/dealinfo/getMingxiV2`(一批 100 笔、按序号从最新往前翻),腾讯各副本只在**整秒分界**处按内容拼接、接不上重取(最多 5 次);批内序号/时间倒退、接口不认 `id`、明细交易日与行情快照不一致都会响亮失败。
|
|
18
|
+
- 成交额核对:容差改为 **`min(笔数 + 1 元, 0.1% + 1000 元)`**,并对**所有已收盘的交易日**生效(不再只限当天),旧接口那种「隔日静默缺 2%」会被拦住;连续竞价段缺号仍失败,盘后定价段缺号仍写入 `missing_seq`。
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- `tencent_ticks` 的 `seq` 改为**本次调用从 0 起重新编的号**,不再等于腾讯某一份明细的原始序号;同一交易日两次调用的笔数可能差几笔(副本分笔不同)。`volume` 仍是手(含科创板),`amount` 仍是元。
|
|
23
|
+
- 同一批里时间戳倒退不再容忍:2.31.8 的容错是为旧分页接口的「时间戳原地更正」;新接口按副本序号翻页、按秒拼接,一秒的倒退无法与另一份对账,只能失败。
|
|
24
|
+
- `ftshare_financial_calendar` 描述更新(无行为变化):`importance` 实测为字符串 `"0"`..`"4"` + 空串,`"0"` = 见闻没评级、本层原样返回 0、不按等级过滤;空串仍归一为 null。补一条 `"0" → 0` 回归;顺带注明日历覆盖随日期滚动回填。
|
|
25
|
+
|
|
26
|
+
### Notes
|
|
27
|
+
|
|
28
|
+
- 上游对照:`a-stock-data` v3.10.5(2026-11-28,#66)只改 §1.4 腾讯逐笔与 §11.6 宏观日历,层/端点/来源数不变;复核记录见 `docs/design/a-stock-data-upstream-review-2026-11.md` §10。
|
|
29
|
+
- 实机验收:000001.SZ / 600519.SH / 300750.SZ / 688981.SH / 159915.SZ 各取 2026-11-27 全天,7.4–9.1 秒;`seq` 连续、时间单调、`missing_seq=0`;成交额与快照差 0 / ±3 / +239 元,均在容差内。日历 2026-11-01..11-28 十个三天窗 816 行,`importance` 为 `"0"` 的 2 条均原样保留。
|
|
30
|
+
- 回归:`npm test` **2029 pass / 0 fail / 1 skipped**;`npm run contract:probe -- --only tencent_ticks` **PASS(8,050ms,预算 30s)**。
|
|
31
|
+
- 工具面变化需要**重建并重启 dsh 进程**(`lib/` 已重建)。
|
|
32
|
+
- 版本:根包 + 四个随包嵌套包 + `LOCAL_FETCH_CLIENT_VERSION` / `WIND_CLIENT_VERSION` 同步 2.32.1。
|
|
33
|
+
|
|
10
34
|
## [2.32.0] - 2026-11-28
|
|
11
35
|
|
|
12
36
|
分析层升级:高级分析师给出的每个数可以沿 `Claim → Calculation → ModuleRun → Snapshot → StagedInput → ContentHash`
|
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.32.
|
|
6
|
+
<a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.32.1-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
|
|
|
@@ -16,16 +16,11 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
|
|
|
16
16
|
> [!IMPORTANT]
|
|
17
17
|
> 本项目仍在探索中,不提供代交易服务,不保证数据完整、及时或准确,也不承诺投资回报。请自行核对来源并承担投资风险。
|
|
18
18
|
|
|
19
|
-
## 「🎉 CapGen 投研自动化」 已上线,欢迎试用并提 issue 💕 [快速了解](#capgen-automation)
|
|
20
|
-
|
|
21
|
-
## 「🎉 高级分析师」 已上线,欢迎试用并提 issue 💕 [快速了解](#senior-analyst)
|
|
22
|
-
|
|
23
19
|
## 「🎉 2.32.0 更新要点」
|
|
24
20
|
|
|
25
21
|
- **结论可以回放了**:高级分析师的结论按「数据快照 → 模块运行 → 计算 → 结论」逐层留档,每个数字都能追到一次真实运行;同一份分析的多次提交会保留版本,能看到这次改了哪个结论、哪组假设或哪批数据。
|
|
26
22
|
- **历史模拟升级**:均线规则的样本内模拟按 A 股 T+1、涨跌停、停牌、整手与分段费用约束成交,附逐日成交账本、模拟等级与审计。它只说明历史样本里发生了什么,不代表策略可执行,也不预测收益。
|
|
27
23
|
- **新增事件研究**:按公告发布时间与交易日历对齐事件日,计算异常收益、累计异常收益与多事件平均结果,并披露有效样本、事件日聚集与替代解释。它只描述历史关联,不证明因果。
|
|
28
|
-
- **升级要做的事**:重启 dsh 进程后在插件页更新到本版;升级前创建的分析快照会变成只读(仍可回看),要继续分析请重建快照后重跑。分析层现在更严格,证据不足时会明确写「部分完成 / 证据不足」,不会为了凑结论而编数字。
|
|
29
24
|
|
|
30
25
|
## 快速上手
|
|
31
26
|
|
|
@@ -239,7 +234,7 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
|
|
|
239
234
|
- **配置在哪?** 打开「插件」→ 已安装的 **Capital Generation**,插件介绍下方就是「数据源 / 投研自动化 / 精选 Skills / 包含的组件 / 分析环境」五格,五把密钥都在第一格;第二格可指定任务统一使用的默认工作区,也能改自动检查间隔与最长运行时间等上限;第五格准备 Python 分析环境;不在 DSH 的普通「设置」页面,也不用点进任何一行组件。保存密钥后新建会话再试。
|
|
240
235
|
- **升级到 2.9.0 后,分析师和绘图专员去哪了?** 这一版把它们收进自动模式内部,不再出现在选择器与预设管理里,避免误开一个没有取数入口的空会话。旧会话仍能按原身份恢复;新任务直接用自动模式提出即可。
|
|
241
236
|
- **宿主更新后插件显示异常、三个模式消失?** 插件只支持**同一 minor** 的宿主(本版是 `>=0.2.2-rc.5 <0.2.3-0`):宿主跨到 0.2.3 及以上时,旧插件会被启动拒载(插件页显示「异常」)。先把宿主升到与插件同一条 minor,再在插件页更新插件;应急可用版本豁免(有崩溃风险,见 CHANGELOG 的 Migration)。日志里出现「宿主 dsh … 未逐项验证」说明你跑在同一 minor 的未验证补丁版上——能跑,但遇异常请先升级插件并把那行日志附在 issue 里。
|
|
242
|
-
- **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.32.
|
|
237
|
+
- **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.32.1` 或 `@2.32.1`。
|
|
243
238
|
- **刚发布的新版本装不到?** 桌面端取包时会跳过**刚发布不久**的版本(宿主侧包管理器的发布冷却策略,实测会静默装成上一个版本),国内镜像的同步也可能滞后一段时间。急着用最新代码,改用仓库地址安装最直接;但仓库地址安装的是 git 依赖,插件页不显示「版本」检查。
|
|
244
239
|
- **插件页的「版本」段怎么用?** 只有用包名从 npm 安装的版本才有;它只列比当前新的版本。回旧版要先卸载,再安装 `@v587d/capital-generation@版本号`(桌面端地址末尾加 `#v版本号`);旧版必须匹配当前 DSH 基线,对应关系见 [CHANGELOG 的 Migration](CHANGELOG.md)。
|
|
245
240
|
- **网页抓取失败?** 配置卡片中的「允许启动本地提取网页内容」默认开启:AnySearch 提取失败时可尝试本机直连。关闭后,本机直连的具名来源查询也不可用;请检查该开关和网络连接。
|
package/automation/package.json
CHANGED
package/chart-ui/package.json
CHANGED
package/config/package.json
CHANGED
|
@@ -2019,7 +2019,7 @@ function createRateSeriesSource(options) {
|
|
|
2019
2019
|
}
|
|
2020
2020
|
const SHIBOR_DESCRIPTION = '按日期区间获取 **SHIBOR(上海银行间同业拆放利率)** 日度值,一行一个交易日、八个期限一次给全(`on_rate_pct` 隔夜,`w1` / `w2` 一至两周,`m1` / `m3` / `m6` / `m9` 一至九个月,`y1_pct` 一年)。补的是货币市场基准:此前本仓没有任何拆借利率,要利率只能走 Wind EDB(按次计费)。⛔ 单位是**百分数原值**(实测 2026-10-15 隔夜 1.266 读作 1.266%)——依据只有量级(隔夜拆借不会是 1.266 个基点、也不会是 126.6%),**上游文档没有写这一列的单位**。历史起点实测在 **2006-10-08**(2006 全年给 63 行、首行就是它;2006-01-01..06-30 与 07-01..09-30、1999 / 2004 全年都是 0 行),早于起点是合法空,不要换年份重试。⛔ **周末、节假日与未发布日没有行**,上游也不插值、不补算、不前值填充——序列天然不连续,做时序前先声明对齐规则。列按可空声明:上游文档说某期限可能"源数据未发布",而实测 2020-01-02 起 1000 行里一个 null 都没有;⛔ 真要出现缺失,本层也**不补 0**。`start_date` / `end_date` 必填(实测缺参数 400、倒转 400、带横杠 400),`page_size` 上限 1000(1001 是响亮 400)。防改版:逐行核返回日期落在请求区间内。';
|
|
2021
2021
|
const HIBOR_DESCRIPTION = '按日期区间获取 **HIBOR(香港银行间同业拆放利率)** 日度值,一行一个交易日,十五个期限档(隔夜、一至两周、一至十二个月)。补的是港币资金面:此前本仓没有任何港币利率。⛔ 单位是**百分数原值**(实测 2026-10-08 隔夜 2.16821 读作 2.16821%)。⛔ **十五档里有七档实测整列为 null**:`m4` / `m5` / `m7` / `m8` / `m9` / `m10` / `m11` 在 2026-10-01..15 的 6 行里 6 / 6 全为 null,只有隔夜、一至两周、一至三月、六月、十二月有值——那是 HIBOR 实际公布的档位就这些,⛔ 不是缺数据,别补值也别把 null 读成 0。历史深度实测至少到 2010 年(2010 全年 249 行、首行 2010-01-04;2000-01-01..2001-12-31 两年 0 行),起点是滚动还是固定未核出。香港假日与未发布日没有行(上游声明不插值、不补算、不前值填充)。`start_date` / `end_date` 必填,`page_size` 上限 1000(实测 1001 → 响亮 400)。防改版:逐行核返回日期落在请求区间内。';
|
|
2022
|
-
const FINANCIAL_CALENDAR_DESCRIPTION = '按**最多 3 天的窗口**获取全球财经日历(华尔街见闻口径),一行一个事件。这块本仓**整块零覆盖**:此前既没有宏观数据发布时刻表,也没有"今天几点出 CPI"。⛔ **窗口上限是硬约束**:实测 `end_date` 比 `start_date` **晚四天及以上**才 400「时间范围不能超过3天」(2026-10-15..10-19 与 ..10-20 被拒,..10-18 那四天含首尾正常回 114 行),本层在参数层先拦;要更长区间请分段请求,本层**不替你循环取**——那会把一次取数变成 N 次出网却假装是一份 Dataset。⛔ **覆盖是滚动窗口**:实测 2026-08-03 / 09-01 / 09-15 / 10-05 / 10-12 / 10-19 / 10-26 各日都有事件(40 / 59 / 45 / 37 / 21 / 25 / 10 行),而 **2026-11-02 / 11-16 / 12-01 与 2026-01-05
|
|
2022
|
+
const FINANCIAL_CALENDAR_DESCRIPTION = '按**最多 3 天的窗口**获取全球财经日历(华尔街见闻口径),一行一个事件。这块本仓**整块零覆盖**:此前既没有宏观数据发布时刻表,也没有"今天几点出 CPI"。⛔ **窗口上限是硬约束**:实测 `end_date` 比 `start_date` **晚四天及以上**才 400「时间范围不能超过3天」(2026-10-15..10-19 与 ..10-20 被拒,..10-18 那四天含首尾正常回 114 行),本层在参数层先拦;要更长区间请分段请求,本层**不替你循环取**——那会把一次取数变成 N 次出网却假装是一份 Dataset。⛔ **覆盖是滚动窗口**:实测 2026-08-03 / 09-01 / 09-15 / 10-05 / 10-12 / 10-19 / 10-26 各日都有事件(40 / 59 / 45 / 37 / 21 / 25 / 10 行),而 **2026-11-02 / 11-16 / 12-01 与 2026-01-05 当时都是 `records` 空数组 + `total=0`**(2026-11-29 复测:11-02 / 11-16 已分别回填 30 / 43 行——覆盖随日期滚动回填,别把某天当永久空表),2020 / 2023 / 2024 / 2025 里的整天更是直接回 `data:null`——大约"过去 2.5 个月到未来 2 周",边界随日期前移;两种空都是合法空、不是失败,不要换日期重试。列口径:`event_time_ms` 与 `event_time_beijing` 是同一时刻的两种写法(上游 `event_time` 是**秒级** Unix **字符串**,实测 1791993600 → 北京 2026-10-15 00:00;⛔ 直接当毫秒会差三个数量级),`tab_type` 实测只有 `general` 与 `earnings` 两值,`region` 是中文地区名(实测单次 113 行里 14 个:中国 / 美国 / 欧元区 / 日本 / 香港 …;跨多次请求累计见过 28 个),`importance` 上游给**字符串数字**:实测 2026-11-01..11-28 的 816 行是 `"1"` 277 / `"2"` 337 / `"3"` 95 / `"4"` 54 / **`"0"` 2** / 空字符串 51——**`"0"` 是见闻没评级的条目**(上游 v3.10.5 #66 实测两条都是公司事件:小鹏 Q3 财报会、华为新品发布),本层原样返回 0,⛔ 不重映射成 null、也不按等级过滤(本能力没有 `min_importance` 参数);空字符串归一成 null,⛔ 不是 0。⛔ `actual_value` / `forecast_value` / `previous_value` **保持文本原样**:这些读数的单位随事件本身而变(指数、百分比、套…上游不给列级单位),本层不转数值、也不换算;缺失只有一种写法——**空字符串**(实测 19 份成功响应、1517 行里这三列加 `link` / `importance` 的空值全是 `""`,`null` 型字段 0 个),本层把它归一成 null。⛔ 财报类事件常给 `actual_value = "0"` 与 `forecast_value = "0"` 的占位(实测首行 赣锋锂业 earnings),那个 0 **不是"实际值为零"**。`link` 是原文链接(实测 113 行里 39 行为空)。`page_size` 真实上限实测 **500**(文档写 200;传 1000 → 回显 pageSize=500),实测最密的三天窗(2026-09-28..09-30)132 个事件、一页就给完;⛔ `page_size=0` 静默只回 1 行(实测),本层要求 ≥1。防改版:逐行核 `stat_date` 落在请求窗口内。';
|
|
2023
2023
|
const financialCalendarRow = {
|
|
2024
2024
|
type: 'object',
|
|
2025
2025
|
properties: {
|
|
@@ -4,11 +4,18 @@ import { isLikelyIndex, normalizeSecurityCodes, parseSecurityCode, requireTencen
|
|
|
4
4
|
// Shared core holds HK/US snapshots, smartbox and the one throttle chain; this file only defines
|
|
5
5
|
// capabilities and K-line/tick orchestration. Two throttles = no throttle.
|
|
6
6
|
import { QUOTE_URL, aShareQuoteTime, callIfzqHosts, fetchOffshoreIndexQuotes, fetchOffshoreQuotes, isRecord, normalizeHkCode, normalizeOffshoreIndexCode, normalizeUsCode, numberOrNull, offshoreQuoteTime, requiredNumber, resolveUsKlineSymbol, sourceError, US_QUOTE_FIELDS, tencentGetText as getText, } from './tencent-public-core.js';
|
|
7
|
-
const TICK_URL = 'https://
|
|
7
|
+
const TICK_URL = 'https://web.ifzq.gtimg.cn/appstock/app/dealinfo/getMingxiV2';
|
|
8
8
|
const KLINE_MINUTES = new Set(['m1', 'm5', 'm15', 'm30', 'm60']);
|
|
9
9
|
const KLINE_PERIODS = new Set(['day', 'week', 'month', 'm1', 'm5', 'm15', 'm30', 'm60']);
|
|
10
10
|
const KLINE_SPAN_DAYS = { day: 700, week: 3650, month: 18250 };
|
|
11
|
-
|
|
11
|
+
// Tencent serves the tick list from several copies that split/merge trades differently, so seq is only
|
|
12
|
+
// comparable inside one batch. Page backwards from the newest print and splice copies only at a whole
|
|
13
|
+
// second whose trades match byte for byte (upstream v3.10.5). Copies differ by 3-8 sequence numbers.
|
|
14
|
+
const TICK_BATCH = 100;
|
|
15
|
+
const TICK_OVERLAP = 20;
|
|
16
|
+
const TICK_ANCHOR = 5;
|
|
17
|
+
const TICK_RETRIES = 5;
|
|
18
|
+
const TICK_MAX_CALLS = 400;
|
|
12
19
|
const TICK_SESSION_END = '15:00:59';
|
|
13
20
|
const quoteOutput = {
|
|
14
21
|
type: 'array',
|
|
@@ -85,18 +92,18 @@ const ticksOutput = {
|
|
|
85
92
|
items: {
|
|
86
93
|
type: 'object',
|
|
87
94
|
properties: {
|
|
88
|
-
time: { type: 'string' },
|
|
89
|
-
seq: { type: 'integer' },
|
|
95
|
+
time: { type: 'string', description: '北京时间 HH:MM:SS' },
|
|
96
|
+
seq: { type: 'integer', description: '本次调用从 0 起重新编的序号;腾讯各份明细的原始编号不可比(连续竞价缺号会失败,盘后缺号见 missing_seq)' },
|
|
90
97
|
price: { type: 'number' },
|
|
91
|
-
change: { type: 'number' },
|
|
92
|
-
volume: { type: 'number' },
|
|
93
|
-
amount: { type: 'number' },
|
|
98
|
+
change: { type: 'number', description: '较上一笔的价差' },
|
|
99
|
+
volume: { type: 'number', description: '成交量,单位手(科创板也是手,与 tencent_kline 的 volume_unit 不同)' },
|
|
100
|
+
amount: { type: 'number', description: '成交额,单位元' },
|
|
94
101
|
side: { enum: ['B', 'S', 'M'] },
|
|
95
102
|
},
|
|
96
103
|
additionalProperties: true,
|
|
97
104
|
},
|
|
98
105
|
},
|
|
99
|
-
missing_seq: { type: 'array', items: { type: 'integer' } },
|
|
106
|
+
missing_seq: { type: 'array', items: { type: 'integer' }, description: '盘后定价段跳过的序号(按本能力的 seq 编号);末尾缺的从序号看不出来' },
|
|
100
107
|
},
|
|
101
108
|
required: ['date', 'code', 'tencent_symbol', 'rows', 'missing_seq'],
|
|
102
109
|
additionalProperties: true,
|
|
@@ -373,6 +380,170 @@ function parseSnapshot(text, symbol) {
|
|
|
373
380
|
const date = `${fields[30].slice(0, 4)}-${fields[30].slice(4, 6)}-${fields[30].slice(6, 8)}`;
|
|
374
381
|
return { date, clock: fields[30].slice(8), amount: requiredNumber(parts[2], 'amount') };
|
|
375
382
|
}
|
|
383
|
+
function tickTradeDate(value, symbol) {
|
|
384
|
+
const text = String(value ?? '').trim();
|
|
385
|
+
const match = /^(\d{4})(\d{2})(\d{2})$/.exec(text) ?? /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
|
|
386
|
+
if (!match)
|
|
387
|
+
throw sourceError(`Tencent ticks ${symbol} returned an unreadable trade date ${JSON.stringify(value)}`, 'tencent_invalid_response');
|
|
388
|
+
const date = `${match[1]}-${match[2]}-${match[3]}`;
|
|
389
|
+
const parsed = new Date(`${date}T00:00:00Z`);
|
|
390
|
+
if (Number.isNaN(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== date)
|
|
391
|
+
throw sourceError(`Tencent ticks ${symbol} returned an invalid trade date ${JSON.stringify(value)}`, 'tencent_invalid_response');
|
|
392
|
+
return date;
|
|
393
|
+
}
|
|
394
|
+
/** One page of the tick feed: up to 100 prints with source sequence <= cursor (newest page when cursor is null). */
|
|
395
|
+
async function fetchTickBatch(symbol, cursor, signal) {
|
|
396
|
+
const url = new URL(TICK_URL);
|
|
397
|
+
url.searchParams.set('code', symbol);
|
|
398
|
+
url.searchParams.set('limit', String(TICK_BATCH));
|
|
399
|
+
url.searchParams.set('direction', '1');
|
|
400
|
+
if (cursor !== null)
|
|
401
|
+
url.searchParams.set('id', String(cursor));
|
|
402
|
+
const text = await getText(url.toString(), signal);
|
|
403
|
+
let payload;
|
|
404
|
+
try {
|
|
405
|
+
payload = JSON.parse(text);
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
throw sourceError(`Tencent ticks ${symbol} returned non-JSON, probably an error page`, 'tencent_invalid_response');
|
|
409
|
+
}
|
|
410
|
+
// `code` must be the integer 0: the source sends JSON false for bad requests and false would pass `== 0`.
|
|
411
|
+
if (!isRecord(payload) || payload.code !== 0 || !isRecord(payload.data))
|
|
412
|
+
throw sourceError(`Tencent ticks ${symbol} returned an unexpected payload`, 'tencent_invalid_response');
|
|
413
|
+
const data = payload.data;
|
|
414
|
+
const items = data.data;
|
|
415
|
+
if (!Array.isArray(items) || !items.every((item) => typeof item === 'string'))
|
|
416
|
+
throw sourceError(`Tencent ticks ${symbol} data.data is not a string list`, 'tencent_invalid_response');
|
|
417
|
+
const rows = [];
|
|
418
|
+
for (const raw of [...items].reverse()) { // the endpoint lists the newest print first
|
|
419
|
+
const fields = raw.split('/');
|
|
420
|
+
if (fields.length !== 7 || !/^\d+$/.test(fields[0]) || !/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/.test(fields[1]) || !['B', 'S', 'M'].includes(fields[6])) {
|
|
421
|
+
throw sourceError(`Tencent ticks ${symbol} row shape changed: ${JSON.stringify(raw).slice(0, 80)}`, 'tencent_invalid_response');
|
|
422
|
+
}
|
|
423
|
+
const seq = Number(fields[0]);
|
|
424
|
+
if (!Number.isSafeInteger(seq))
|
|
425
|
+
throw sourceError(`Tencent ticks ${symbol} has an unusable sequence ${fields[0]}`, 'tencent_invalid_response');
|
|
426
|
+
rows.push({
|
|
427
|
+
seq,
|
|
428
|
+
time: fields[1],
|
|
429
|
+
price: requiredNumber(fields[2], 'price'),
|
|
430
|
+
change: requiredNumber(fields[3], 'change'),
|
|
431
|
+
volume: requiredNumber(fields[4], 'volume'),
|
|
432
|
+
amount: requiredNumber(fields[5], 'amount'),
|
|
433
|
+
side: fields[6],
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
for (let index = 1; index < rows.length; index += 1) {
|
|
437
|
+
if (rows[index].seq <= rows[index - 1].seq || rows[index].time < rows[index - 1].time) {
|
|
438
|
+
throw sourceError(`Tencent ticks ${symbol} batch has sequence or time going backwards`, 'tencent_invalid_response');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (cursor !== null && rows.length > 0 && rows[rows.length - 1].seq > cursor) {
|
|
442
|
+
throw sourceError(`Tencent ticks ${symbol} asked for sequences up to ${cursor} but got ${rows[rows.length - 1].seq}; the interface may have changed`, 'tencent_invalid_response');
|
|
443
|
+
}
|
|
444
|
+
return { day: rows.length === 0 ? null : tickTradeDate(data.date, symbol), rows };
|
|
445
|
+
}
|
|
446
|
+
function stageTicks(rows) {
|
|
447
|
+
return rows.map((row, index) => ({ ...row, step: index === 0 ? 1 : row.seq - rows[index - 1].seq }));
|
|
448
|
+
}
|
|
449
|
+
/** First whole-second boundary in a batch: index of the first print of a later second, or null if all prints share one second. */
|
|
450
|
+
function tickBoundary(rows) {
|
|
451
|
+
for (let index = 1; index < rows.length; index += 1)
|
|
452
|
+
if (rows[index].time > rows[index - 1].time)
|
|
453
|
+
return index;
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
/** End of the join anchor, exclusive: from the boundary, at least TICK_ANCHOR prints and cut at the next whole second. */
|
|
457
|
+
function tickAnchorEnd(rows, boundary) {
|
|
458
|
+
for (let index = boundary + TICK_ANCHOR; index < rows.length; index += 1)
|
|
459
|
+
if (rows[index].time > rows[index - 1].time)
|
|
460
|
+
return index;
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
function tickTradeKey(row) {
|
|
464
|
+
return `${row.time}/${row.price}/${row.change}/${row.volume}/${row.amount}/${row.side}`;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* How an older batch joins in front of `rows`: result is `batch.slice(0, start + count)` followed by
|
|
468
|
+
* `rows.slice(boundary + count)`. Joins only at a whole second whose prints are complete on both copies
|
|
469
|
+
* and identical outside seq; the batch must also carry a later second, so that second is complete too.
|
|
470
|
+
* Copies only split one print into adjacent seconds (#66), never inside a shared whole second.
|
|
471
|
+
*/
|
|
472
|
+
function tickJunction(rows, batch) {
|
|
473
|
+
const boundary = tickBoundary(rows);
|
|
474
|
+
if (boundary === null)
|
|
475
|
+
return null;
|
|
476
|
+
const end = tickAnchorEnd(rows, boundary);
|
|
477
|
+
if (end === null)
|
|
478
|
+
return null;
|
|
479
|
+
const count = end - boundary;
|
|
480
|
+
const start = batch.findIndex((row) => row.time >= rows[boundary].time);
|
|
481
|
+
if (start <= 0 || batch.length <= start + count)
|
|
482
|
+
return null;
|
|
483
|
+
if (batch[start + count].time <= rows[end - 1].time)
|
|
484
|
+
return null;
|
|
485
|
+
for (let offset = 0; offset < count; offset += 1) {
|
|
486
|
+
if (tickTradeKey(batch[start + offset]) !== tickTradeKey(rows[boundary + offset]))
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
return { boundary, start, count };
|
|
490
|
+
}
|
|
491
|
+
/** Walk the copies from the newest print back to source sequence 0 and renumber the joined list from 0. */
|
|
492
|
+
async function fetchTickDay(symbol, signal) {
|
|
493
|
+
const first = await fetchTickBatch(symbol, null, signal);
|
|
494
|
+
const day = first.day;
|
|
495
|
+
let rows = stageTicks(first.rows);
|
|
496
|
+
let edge = rows.length;
|
|
497
|
+
let edgeSeq = null;
|
|
498
|
+
let calls = 1;
|
|
499
|
+
while (rows.length > 0 && rows[0].seq > 0) {
|
|
500
|
+
const boundary = tickBoundary(rows);
|
|
501
|
+
const end = boundary === null ? null : tickAnchorEnd(rows, boundary);
|
|
502
|
+
if (end === null) {
|
|
503
|
+
throw sourceError(`Tencent ticks ${symbol} earliest row (${rows[0].time}) has sequence ${rows[0].seq}, not 0, and the rows behind it cannot form a whole-second anchor of ${TICK_ANCHOR}+ prints`, 'tencent_incomplete');
|
|
504
|
+
}
|
|
505
|
+
// Ask for the anchor's next print plus TICK_OVERLAP numbers in the newest copy's numbering, so a copy
|
|
506
|
+
// whose sequence is a few numbers off still returns the anchor (and any post-close sequence gap is covered).
|
|
507
|
+
const cursor = (end === edge ? (edgeSeq ?? rows[end].seq) : rows[end].seq) + TICK_OVERLAP;
|
|
508
|
+
let sawEarlier = false;
|
|
509
|
+
let junction = null;
|
|
510
|
+
let batch = [];
|
|
511
|
+
for (let attempt = 0; attempt <= TICK_RETRIES; attempt += 1) {
|
|
512
|
+
if (calls >= TICK_MAX_CALLS)
|
|
513
|
+
throw sourceError(`Tencent ticks ${symbol} still incomplete after ${TICK_MAX_CALLS} requests; the interface may have changed`, 'tencent_incomplete');
|
|
514
|
+
const fetched = await fetchTickBatch(symbol, cursor, signal);
|
|
515
|
+
calls += 1;
|
|
516
|
+
if (fetched.rows.length > 0 && fetched.day !== day)
|
|
517
|
+
throw sourceError(`Tencent ticks ${symbol} crossed trading day ${day} -> ${fetched.day} during fetch`, 'tencent_incomplete');
|
|
518
|
+
batch = fetched.rows;
|
|
519
|
+
const earliest = batch[0];
|
|
520
|
+
// A copy that restarts at 0 counts as earlier only when it shares the earliest second (auction prints).
|
|
521
|
+
const earlier = earliest !== undefined && (earliest.time < rows[0].time || (earliest.seq === 0 && earliest.time === rows[0].time));
|
|
522
|
+
sawEarlier = sawEarlier || earlier;
|
|
523
|
+
junction = earlier ? tickJunction(rows, batch) : null;
|
|
524
|
+
if (junction !== null)
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
if (junction === null) {
|
|
528
|
+
if (!sawEarlier)
|
|
529
|
+
throw sourceError(`Tencent ticks ${symbol} earliest row (${rows[0].time}) has sequence ${rows[0].seq}, not 0, and retries returned no earlier print: the copy is missing its start, retry later`, 'tencent_incomplete');
|
|
530
|
+
throw sourceError(`Tencent ticks ${symbol} cannot join any copy older than ${rows[0].time} (the copies differ in that segment), retry later`, 'tencent_incomplete');
|
|
531
|
+
}
|
|
532
|
+
const joined = junction;
|
|
533
|
+
const newer = stageTicks(batch.slice(0, joined.start + joined.count));
|
|
534
|
+
// The first row of the older tail keeps its step: its predecessor is the same print as the anchor's last row.
|
|
535
|
+
edge = joined.start + joined.count;
|
|
536
|
+
edgeSeq = batch[edge].seq;
|
|
537
|
+
rows = newer.concat(rows.slice(joined.boundary + joined.count));
|
|
538
|
+
}
|
|
539
|
+
const renumbered = [];
|
|
540
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
541
|
+
const step = index === 0 ? 1 : rows[index].step;
|
|
542
|
+
const seq = index === 0 ? 0 : renumbered[index - 1].seq + step;
|
|
543
|
+
renumbered.push({ ...rows[index], seq, gap: step - 1 });
|
|
544
|
+
}
|
|
545
|
+
return { day, rows: renumbered };
|
|
546
|
+
}
|
|
376
547
|
async function executeTicks(params, signal) {
|
|
377
548
|
const code = requireTencentSecurity(parseSecurityCode(params.code, 'code'), 'code');
|
|
378
549
|
if (isLikelyIndex(code))
|
|
@@ -381,58 +552,44 @@ async function executeTicks(params, signal) {
|
|
|
381
552
|
const before = parseSnapshot(await getText(`${QUOTE_URL}${symbol}`, signal, 'gbk'), symbol);
|
|
382
553
|
if (before.amount === 0)
|
|
383
554
|
throw new Error(`${symbol} has no turnover for ${before.date}`);
|
|
384
|
-
const rows =
|
|
555
|
+
const { day, rows } = await fetchTickDay(symbol, signal);
|
|
556
|
+
if (rows.length === 0)
|
|
557
|
+
throw new Error(`${symbol} returned no tick rows`);
|
|
558
|
+
if (day !== before.date)
|
|
559
|
+
throw sourceError(`Tencent ticks ${symbol} trade date ${day} does not match quote snapshot ${before.date}`, 'tencent_incomplete');
|
|
385
560
|
const missingSeq = [];
|
|
386
|
-
for (let
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
break;
|
|
395
|
-
const match = new RegExp(`^v_detail_data_${symbol}=\\[(\\d+),"([^"]*)"\\];?$`).exec(text);
|
|
396
|
-
if (!match || Number(match[1]) !== page)
|
|
397
|
-
throw sourceError(`Tencent ticks ${symbol} page ${page} shape changed`, 'tencent_invalid_response');
|
|
398
|
-
if (!match[2])
|
|
399
|
-
break;
|
|
400
|
-
for (const raw of match[2].split('|')) {
|
|
401
|
-
const fields = raw.split('/');
|
|
402
|
-
if (fields.length !== 7 || !/^\d{2}:\d{2}:\d{2}$/.test(fields[1]) || !['B', 'S', 'M'].includes(fields[6]))
|
|
403
|
-
throw sourceError(`Tencent ticks ${symbol} page ${page} row shape changed`, 'tencent_invalid_response');
|
|
404
|
-
const row = {
|
|
405
|
-
time: fields[1],
|
|
406
|
-
seq: integer(Number(fields[0]), 'source seq', 0, Number.MAX_SAFE_INTEGER),
|
|
407
|
-
price: requiredNumber(fields[2], 'price'),
|
|
408
|
-
change: requiredNumber(fields[3], 'change'),
|
|
409
|
-
volume: requiredNumber(fields[4], 'volume'),
|
|
410
|
-
amount: requiredNumber(fields[5], 'amount'),
|
|
411
|
-
side: fields[6],
|
|
412
|
-
};
|
|
413
|
-
const expected = rows.length === 0 ? 0 : Number(rows[rows.length - 1].seq) + 1;
|
|
414
|
-
// Sequence is authoritative: upstream can correct one timestamp backwards without reordering ticks.
|
|
415
|
-
if (row.seq < expected)
|
|
416
|
-
throw sourceError(`Tencent ticks ${symbol} sequence moved backwards`, 'tencent_invalid_response');
|
|
417
|
-
if (row.seq > expected) {
|
|
418
|
-
if (row.time <= TICK_SESSION_END)
|
|
419
|
-
throw sourceError(`Tencent ticks ${symbol} has missing continuous-session sequence ${expected}-${row.seq - 1}`, 'tencent_incomplete');
|
|
420
|
-
for (let seq = expected; seq < row.seq; seq += 1)
|
|
421
|
-
missingSeq.push(seq);
|
|
422
|
-
}
|
|
423
|
-
rows.push(row);
|
|
561
|
+
for (let index = 1; index < rows.length; index += 1) {
|
|
562
|
+
if (rows[index].time < rows[index - 1].time)
|
|
563
|
+
throw sourceError(`Tencent ticks ${symbol} time moved backwards at sequence ${rows[index].seq}`, 'tencent_invalid_response');
|
|
564
|
+
if (rows[index].gap > 0) {
|
|
565
|
+
if (rows[index].time <= TICK_SESSION_END)
|
|
566
|
+
throw sourceError(`Tencent ticks ${symbol} has missing continuous-session sequence ${rows[index - 1].seq + 1}-${rows[index].seq - 1}`, 'tencent_incomplete');
|
|
567
|
+
for (let seq = rows[index - 1].seq + 1; seq < rows[index].seq; seq += 1)
|
|
568
|
+
missingSeq.push(seq);
|
|
424
569
|
}
|
|
425
570
|
}
|
|
426
|
-
if (rows.length === 0)
|
|
427
|
-
throw new Error(`${symbol} returned no tick rows`);
|
|
428
571
|
const after = parseSnapshot(await getText(`${QUOTE_URL}${symbol}`, signal, 'gbk'), symbol);
|
|
429
572
|
if (after.date !== before.date)
|
|
430
573
|
throw sourceError(`Tencent ticks crossed trading day ${before.date} -> ${after.date}`, 'tencent_incomplete');
|
|
431
|
-
const
|
|
432
|
-
|
|
574
|
+
const sessionAmounts = rows.filter((row) => String(row.time) <= TICK_SESSION_END).map((row) => Number(row.amount));
|
|
575
|
+
const continuousAmount = sessionAmounts.reduce((sum, amount) => sum + amount, 0);
|
|
576
|
+
// Per-print amounts are rounded to yuan, so the slack is at most one yuan per print; a tiny turnover keeps
|
|
577
|
+
// the old 0.1% + 1000 yuan floor. A wrongly spliced print or two usually blows past this, unlike 0.1%.
|
|
578
|
+
// Only a closed day's snapshot can witness the joined prints: a past snapshot day is over, today needs 15:00+.
|
|
579
|
+
// Restricting this to "today" let an incomplete copy pass silently for every previous trading day.
|
|
580
|
+
const closed = after.date !== todayShanghai() || after.clock >= '150000';
|
|
581
|
+
const tolerance = Math.min(sessionAmounts.length + 1, before.amount * 0.001 + 1000);
|
|
582
|
+
if (closed && after.amount === before.amount && Math.abs(continuousAmount - before.amount) > tolerance) {
|
|
433
583
|
throw sourceError(`Tencent ticks ${symbol} amount ${continuousAmount} does not match quote ${before.amount}`, 'tencent_incomplete');
|
|
584
|
+
}
|
|
434
585
|
return {
|
|
435
|
-
data: {
|
|
586
|
+
data: {
|
|
587
|
+
date: before.date,
|
|
588
|
+
code: code.canonical,
|
|
589
|
+
tencent_symbol: symbol,
|
|
590
|
+
rows: rows.map((row) => ({ time: row.time, seq: row.seq, price: row.price, change: row.change, volume: row.volume, amount: row.amount, side: row.side })),
|
|
591
|
+
missing_seq: missingSeq,
|
|
592
|
+
},
|
|
436
593
|
schema: ticksOutput,
|
|
437
594
|
};
|
|
438
595
|
}
|
|
@@ -997,7 +1154,7 @@ export function createTencentSources() {
|
|
|
997
1154
|
capability: 'tencent_ticks',
|
|
998
1155
|
name: 'get_tencent_ticks',
|
|
999
1156
|
summary: '腾讯最近交易日分笔成交明细',
|
|
1000
|
-
description: '获取单只 SH/SZ 股票或 ETF 最近一个交易日的腾讯分笔成交。不是 Level-2 逐笔委托;约 3 秒一笔,volume
|
|
1157
|
+
description: '获取单只 SH/SZ 股票或 ETF 最近一个交易日的腾讯分笔成交。不是 Level-2 逐笔委托;约 3 秒一笔,volume 单位为手(科创板也是手,与 tencent_kline 按股/手分两套不同)、amount 单位为元,side 为 B/S/M。只有最近交易日,不支持历史、BJ 或指数。⛔ **seq 是本次调用从 0 起重新编的号**:腾讯后台的当日明细有多份、分笔略有不同(同一时刻有时一笔、有时拆成两笔),本能力从最新一笔往前翻、只在整秒分界处按内容拼接,所以同一交易日两次调用的笔数可能差几笔,不要把 seq 当交易所原始序号。明细自带的交易日与行情快照不一致会失败(开盘前腾讯可能还给着上一交易日)。收盘后(快照日期是上海当天且已收盘)会把连续竞价段成交额与腾讯行情快照核对,容差是「笔数 + 1」元(成交额很小时用 0.1% + 1000 元,取小的);连续竞价缺号或成交额对不上会失败;盘后定价段跳过的序号写入 missing_seq,末尾缺的从序号上看不出。',
|
|
1001
1158
|
inputSchema: { type: 'object', properties: { code: { type: 'string', description: '单只股票或 ETF 完整代码,如 000001.SZ 或 510300.SH' } }, required: ['code'], additionalProperties: false },
|
|
1002
1159
|
outputSchema: ticksOutput,
|
|
1003
1160
|
paginated: false,
|
|
@@ -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.32.
|
|
6
|
+
export declare const LOCAL_FETCH_CLIENT_VERSION = "2.32.1";
|
|
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.32.
|
|
7
|
+
export const LOCAL_FETCH_CLIENT_VERSION = '2.32.1';
|
|
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.32.
|
|
38
|
+
export declare const WIND_CLIENT_VERSION = "2.32.1";
|
|
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.32.
|
|
22
|
+
export const WIND_CLIENT_VERSION = '2.32.1';
|
|
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