@v587d/capital-generation 2.26.0 → 2.27.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 CHANGED
@@ -7,6 +7,64 @@
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.27.1] - 2026-11-18
11
+
12
+ 修掉「分时」块在收盘后必现的加载失败,以及失败态里那个看不出是按钮的「重试」。
13
+
14
+ ### Fixed
15
+
16
+ - **盘后一次"重述"把整块分时判死**:腾讯收盘后会补一根把当日成交额改低的收尾行(300803.SZ:15:29 那行比 15:28 少 263,680.82 元,成交量不变),而分时解析是**先**做"累计量不许倒退"的护栏、**再**按 15:00 截掉盘后行——护栏于是在一根永远不会上图的盘后行上抛错,整块图被判成坏数据。现在先截断再判断;累计量回退当作上游重述(语义是"这一分钟没有新成交"),delta 归零、累计取高水位继续累加;只剩**时间倒流**仍响亮失败(那才会让横轴回头)。
17
+ - **失败原因不再被吞掉**:面板此前只留宿主回执里的 `code`,`message`("上游没有及时回话"一类)在客户端被丢弃,用户只能看到一句「分时加载失败」。现在 `message` 随失败一起进状态,显示在标题下面;同一套失败态给「日K」复用。
18
+ - **「重试」改成真按钮**:原来用的 `.cwd-pill` 背景色与它所在空态盒同色,在 300px 高的虚线框里就是一段可点的文字。新 `.cwd-retry` 与右上角「刷新行情」同一套配方(34px 高 / 10px 圆角 / 12.5px / 主色描边 + 刷新图标 / 悬停、按下与焦点环),空态盒也从虚线改实底。
19
+ - **上游故障不再冒充"该市场没有数据"**:三个分时入口全挂时原本返回 `trend_unavailable`,面板会显示"该市场暂时没有分时数据"的空态(没有重试键),把可恢复的上游故障说成市场能力缺失。现在区分成 `trend_upstream_unavailable` / `kline_upstream_unavailable`(可重试),`*_unavailable` 只留给真正没有该市场数据的情况(港美股指数、场外美股等);报文读不懂与连不上也各有各的码。
20
+
21
+ ### Notes
22
+
23
+ - 五个包版本同步抬到 `2.27.1`;`LOCAL_FETCH_CLIENT_VERSION` 与 `WIND_CLIENT_VERSION` 随版本号更新。用户侧无需迁移。
24
+ - 宿主新增一行失败日志:`capital-watchlist: <route> <标的> → <错误码>`(只记上游与存储故障,代码格式错误、已移出清单这类调用方问题不记)——面板只有一句话,排障靠它。**这一行要重启 dsh 才会出现**(宿主半边没有热更新);前端半边刷新页面即生效。
25
+ - 回归:`test/trend-fixtures.mjs` 收了 300803.SZ 那根收盘后报文的原文,解析护栏用例据此断言盘后行不上图、回退不产生负量、日总量取报价口径;另有「失败原因整条链路」(回执 message → 面板文案)与重试按钮 `type="button"` 的断言。详见 `docs/design/watchlist-intraday-v0.1.md` §11.7。
26
+
27
+ ## [2.27.0] - 2026-11-18
28
+
29
+ 「自选股」行情工作台补上两张图:当日分时(价格、均价、昨收基准与成交量)和历史日 K(蜡烛、四条均线、成交量)。分时 A 股与港股走腾讯公开入口、美股走东财,日 K 三个市场都走腾讯(与 `get_kline` 同一套解析)。
30
+
31
+ ### Added
32
+
33
+ - **当日分时走势图**:工作台右栏原来的「当日分时 / 成交量」两块占位合成一块真实图表(块标题就叫「分时」,与下面的「日K」对齐)。
34
+ - 价格折线带渐变面积,收盘价高于昨收取红、低于昨收取绿;昨收虚线基准 + 左轴价格 / 右轴百分比双标尺;个股还画一条蓝色虚线均价(VWAP);成交量以柱状叠在价格区下方,按该分钟涨跌着色。
35
+ - 指针悬停给十字光标与浮动读数(时刻、价格与涨跌幅、均价、该分钟成交量)。
36
+ - 块头常驻交易日状态:盘中(标出最后一根的时刻与交易所时区)、当日收盘、上一交易日;盘中超过 10 个交易分钟没有新点会标「数据滞后」,不把静止的线当实时。
37
+ - 统计行给今开、最高、最低、均价、成交量(手/股)、成交额(万/亿换算)。
38
+ - **`GET /capital-watchlist/trend`**:宿主路由只接受自选清单里已存在的 code(身份取自存储,客户端不能自报市场),60 秒进程缓存 + 同码单飞 + 10 秒超时;`refresh=1` 跳过缓存,工作台的「刷新行情」会带上它。
39
+ - **历史日 K**:右栏分时下面再加一块,蜡烛按收盘高于开盘取红、低于取绿,叠 MA5/10/20/60(图例显示最后一天的均线值),下方同色成交量柱,横轴按月标刻度(第一格带年份),指针悬停给开高低收、涨跌幅与成交量。默认取前复权 120 根。
40
+ - **`GET /capital-watchlist/kline`**:与 `/trend` 同一道归属闸门(身份只取自存储),5 分钟进程缓存 + 同码单飞 + 15 秒超时;`refresh=1` 跳过缓存,工作台的「刷新行情」会带上它。
41
+ - **共享日线内核**:`fetchDailyBars()` 复用插件 `get_kline` 的取数与行解析(A 股 `fqkline`、港股 `hkfqkline`、美股 `usfqkline`),工作台不再有一份自己的 K 线解析。
42
+ - **共享分时内核**:新增 `src/sources/trend-series.ts`,A 股/港股用 `appstock/app/minute/query`(与现有报价同一条 120ms 节流链),美股用东财 `trends2`(与东财工具同一条全进程 1s 链);`scripts/smoke-trend.mjs` 用于手工实时核对。
43
+
44
+ ### Changed
45
+
46
+ - **横轴按交易时钟铺开,不按到货点数**:横坐标是交易分钟(午休压成零宽),所以开盘几分钟只有几个点时就只占最左一窄条,成交量柱按「一分钟一格」定宽;刻度是整段交易时间的半点网格(11:30 与 13:00 合成一个),还没有数据的那段照样有轴。
47
+ - **腾讯 ifzq 宿主轮换改为共享**:K 线的三个备选宿主与 120 秒冷却表从 `tencent-http.ts` 上提到 `tencent-public-core.ts`,K 线与分时共用一份故障转移;行为不变。
48
+ - **卡片高度改吃面板真实高度**:`--cwd-body-h` 那个 `clamp(520px, 78vh, 860px)` 换成「内层 flex + 卡片 `flex: 1 1 auto`」——猜小了详情列出滚动条、猜大了整页出滚动条,两头都试过;现在按面板实际高度给,上限 880px,两张图自然多拿到一截高度。
49
+ - **详情区压成三行**:「行情时间 / 标的类型」并到价格右边,「今开/最高/最低/均价/成交量/成交额」并进「当日分时」标题行,「MA5/10/20/60」并进「日K」标题行——三行合并省下的约 100px 全给两张图,同一窗口高度下每张图各高约 60px。
50
+ - **右栏两块图平分高度**:分时与日 K 都是可伸缩的图文块(`flex: 1 1 0` + 各自最小高度),图盒跟着块被压缩,窗口够高时不出滚动条,只有压到最小高度才滚动;分时块标题行多一个「收起 / 展开」,收起后只剩标题行,高度全让给日 K。
51
+ - **详情区瘦身**:「所属分组」那一格去掉(分组筛选器就是它的入口),meta 只剩「行情时间 / 标的类型」一行——两格图加一行报价要装进同一个卡片高度,靠删重复信息而不是缩字号。
52
+ - **日 K 的量纲跟着板块走**:688/689 的日线成交量上游给的是股数、主板与 ETF 给的是手(实测 688599 单日 2,900 万股 vs 600519 35,116 手),与分时那条一致;分时有成交额可以互证,日线没有,所以按板块判定。
53
+ - **数据口径的三处显式处理**:A 股 15:06–15:30 的收盘后补点整段丢弃(15:00 那根的累计量与快照逐位相等);港股 16:08 的收盘竞价点保留为最后一点,其余盘后点丢弃;东财给美股的时间戳是北京时间,按交易所时区换算后再画(09:30–16:00 是纽约时间)。
54
+ - **指数不画均价线**:指数点位没有成交量加权价,东财那一列是指数点位的钟均值,与个股 VWAP 不是一回事,统一给空。
55
+
56
+ ### Fixed
57
+
58
+ - **科创板成交量按股报,均价不再错成价格的百分之一**:688xxx 的分钟累计成交量上游给的是股数而不是手,乘 100 会得到「9.24 的票均价 0.09」。量纲改为由「累计成交额 ÷ 累计成交量」是否落在印出的价格上判定——主板与 ETF 仍是手,港股与美股仍是股;这样不用维护板块表(688 之后还有 689 CDR、北交所)也不会过时,成交量标签随之在「万股」与「万手」之间跟着数据走。
59
+ - **详情头与分时同源**:右栏的分时比清单刷新更新,此前大价格、涨跌幅和时间戳各取各的(清单停在 10:26、分时已到 10:29,同一只票两处差一跳)。现在选中行的价格、涨跌幅与时间都取自已加载的那份分时,清单里那一行也跟着同一份,一屏不会出现同一只票的两个数。时间只留一格「行情时间」——它说明上面那个数字是什么时候印出来的,美股带「美东」标签,A 股与港股本来就是本地钟;原来的「交易所时间」只是同一时刻的另一种叫法,删掉。
60
+
61
+ ### Notes
62
+
63
+ - 五个包版本同步抬到 `2.27.0`;`LOCAL_FETCH_CLIENT_VERSION` 与 `WIND_CLIENT_VERSION` 随版本号更新。
64
+ - 港美股**指数**没有日 K:腾讯的 K 线入口只认 5 位港股代码与美股票代码,不认指数(实测 `HSI.HK` 被代码校验拒绝、`IXIC.US` 回空节点),这两类在块里给空态说明,不发请求;A 股指数(`000001.SH`/`399001.SZ`)正常画。
65
+ - 场外美股(腾讯代码 `.PS`)与冷门美股指数没有分时源:接口直接给空态,不发请求、不画假走势;这条边界写在 `docs/design/watchlist-intraday-v0.1.md`。
66
+ - 分时是公开网页接口(腾讯、东财),与现有港美报价同一性质,零 key;不新增上游域名。**本版不做 5 日视图、不做列表行迷你走势、不把分时注册成模型工具。**
67
+
10
68
  ## [2.26.0] - 2026-11-17
11
69
 
12
70
  左侧栏新增「自选股」行情工作台;内置投研任务的指令改写成互不重叠的扫描边界,简报抽取同步收紧。
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.2-blue" alt="DSH@0.2.2-rc.2"></a>
6
- <a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.26.0-9cf" alt="Version"></a>
6
+ <a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.27.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
 
@@ -144,11 +144,13 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
144
144
  | :---: | :---: |
145
145
  | <a href="assets/chart-line-sidebar.png"><img src="assets/chart-line-sidebar.png" alt="侧栏折线图" width="400"></a> | <a href="assets/chart-candlestick-sidebar.png"><img src="assets/chart-candlestick-sidebar.png" alt="侧栏 K 线图" width="400"></a> |
146
146
 
147
- - **管理自选股:** 在 **自动模式、市场专家、资讯专家** 三种模式的会话中输入 `/` 或点击输入框旁的 `+`,从「指令」中打开「自选股」。
147
+ - **管理自选股:** 在 **自动模式、市场专家、资讯专家** 三种模式的会话中输入 `/` 或点击输入框旁的 `+`,从「指令」中打开「自选股」。左侧栏的「自选股」打开行情工作台:左边是行情列表,右边是选中标的的当日分时走势图(价格、均价、昨收基准与成交量,A 股、港股、美股都画;收盘后标明是当日收盘还是上一交易日,没有分时源的市场不画),下面接着历史日 K(蜡烛、MA5/10/20/60、成交量,A 股、港股、美股个股都有,A 股指数也有;港美股指数暂时没有日线)。
148
148
 
149
- | 管理自选股 | 标记持仓 |
150
- | :---: | :---: |
151
- | <a href="assets/watchlist-popup.png"><img src="assets/watchlist-popup.png" alt="管理自选股" width="400"></a> | <a href="assets/watchlist-more.png"><img src="assets/watchlist-more.png" alt="标记持仓" width="400"></a> |
149
+ <p align="center">
150
+ <a href="assets/watchlist.png">
151
+ <img src="assets/watchlist.png" alt="自选股行情工作台" width="800">
152
+ </a>
153
+ </p>
152
154
 
153
155
  - **精选 Skills:** 当前收录 8 个开源项目、共 70 个 Skill。默认不开启「智能装载 Skills」,逐项清单和勾选都在;打开后清单收起,按角色开放该角色全部方法,由模型按任务挑 1–2 条,运行期不再看勾选。两种状态都按角色分发:研究/组合方法归自动模式,估值/财务/风险/筛选归分析师,文档深读与核验归资讯专员;无需新建会话,下一轮就生效。
154
156
 
@@ -189,7 +191,7 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
189
191
  - **安装后找不到模式?** 确认插件出现在「插件」→ 已安装列表;Web / CLI profile 安装后要重启该 profile,并在新会话选择模式。选择器里应看到自动模式、行情专家、资讯专员;分析师和绘图专员是自动模式的内部角色,不会出现在这里。
190
192
  - **配置在哪?** 打开「插件」→ 已安装的 **Capital Generation**,插件介绍下方就是「数据源 / 投研自动化 / 精选 Skills / 包含的组件 / 分析环境」五格,五把密钥都在第一格;第二格可指定任务统一使用的默认工作区,也能改自动检查间隔与最长运行时间等上限;第五格准备 Python 分析环境;不在 DSH 的普通「设置」页面,也不用点进任何一行组件。保存密钥后新建会话再试。
191
193
  - **升级到 2.9.0 后,分析师和绘图专员去哪了?** 这一版把它们收进自动模式内部,不再出现在选择器与预设管理里,避免误开一个没有取数入口的空会话。旧会话仍能按原身份恢复;新任务直接用自动模式提出即可。
192
- - **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.26.0` 或 `@2.26.0`。
194
+ - **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.27.1` 或 `@2.27.1`。
193
195
  - **刚发布的新版本装不到?** 桌面端取包时会跳过**刚发布不久**的版本(宿主侧包管理器的发布冷却策略,实测会静默装成上一个版本),国内镜像的同步也可能滞后一段时间。急着用最新代码,改用仓库地址安装最直接;但仓库地址安装的是 git 依赖,插件页不显示「版本」检查。
194
196
  - **插件页的「版本」段怎么用?** 只有用包名从 npm 安装的版本才有;它只列比当前新的版本。回旧版要先卸载,再安装 `@v587d/capital-generation@版本号`(桌面端地址末尾加 `#v版本号`);旧版必须匹配当前 DSH 基线,对应关系见 [CHANGELOG 的 Migration](CHANGELOG.md)。
195
197
  - **网页抓取失败?** 配置卡片中的「允许启动本地提取网页内容」默认开启:AnySearch 提取失败时可尝试本机直连。关闭后,本机直连的具名来源查询也不可用;请检查该开关和网络连接。
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-automation",
3
- "version": "2.26.0",
3
+ "version": "2.27.1",
4
4
  "description": "CapGen 投研自动化:独立 host bundle(固定 capital_automation 域、单 scheduler owner、/capital-automation 路由与浏览器页面)。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-charts",
3
- "version": "2.26.0",
3
+ "version": "2.27.1",
4
4
  "description": "自动模式的图表前端组件(浏览器半边 + 序列旁路路由):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/config",
3
- "version": "2.26.0",
3
+ "version": "2.27.1",
4
4
  "description": "自动模式的取数凭据与偏好配置行:卡片坐在 @v587d/capital-generation 插件主页的「配置」段,点这一行本身没有表单。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,2 +1,22 @@
1
1
  import type { DataSource } from '../data-collector/hub.js';
2
+ /**
3
+ * One daily series for a UI pane: always day/qfq, one request per symbol, no paging.
4
+ * It runs the same executors and row parsers as `get_kline` (a second parser would drift), and it is
5
+ * the only place that knows the desk shows 万股 for 科创板 while the main board reports 手.
6
+ */
7
+ export declare function fetchDailyBars(input: {
8
+ thscode: string;
9
+ }, signal: AbortSignal, count?: number): Promise<{
10
+ thscode: string;
11
+ adjust: 'qfq';
12
+ bars: Array<{
13
+ date: string;
14
+ open: number;
15
+ high: number;
16
+ low: number;
17
+ close: number;
18
+ volume: number;
19
+ }>;
20
+ volume_unit: 'lot' | 'share';
21
+ }>;
2
22
  export declare function createTencentSources(): DataSource[];
@@ -3,20 +3,13 @@ import { getDataTimeContract } from '../time/tools.js';
3
3
  import { isLikelyIndex, normalizeSecurityCodes, parseSecurityCode, requireTencentSecurity } from './security-code.js';
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
- import { QUOTE_URL, aShareQuoteTime, fetchOffshoreIndexQuotes, fetchOffshoreQuotes, isRecord, normalizeHkCode, normalizeOffshoreIndexCode, normalizeUsCode, numberOrNull, offshoreQuoteTime, requiredNumber, resolveUsKlineSymbol, sourceError, US_QUOTE_FIELDS, tencentGetText as getText, } from './tencent-public-core.js';
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
7
  const TICK_URL = 'https://stock.gtimg.cn/data/index.php';
8
- const KLINE_HOSTS = [
9
- 'https://web.ifzq.gtimg.cn',
10
- 'https://proxy.finance.qq.com/ifzqgtimg',
11
- 'https://ifzq.gtimg.cn',
12
- ];
13
- const HOST_COOLDOWN_MS = 120_000;
14
8
  const KLINE_MINUTES = new Set(['m1', 'm5', 'm15', 'm30', 'm60']);
15
9
  const KLINE_PERIODS = new Set(['day', 'week', 'month', 'm1', 'm5', 'm15', 'm30', 'm60']);
16
10
  const KLINE_SPAN_DAYS = { day: 700, week: 3650, month: 18250 };
17
11
  const MAX_TICK_PAGES = 300;
18
12
  const TICK_SESSION_END = '15:00:59';
19
- const hostDownUntil = new Map();
20
13
  const quoteOutput = {
21
14
  type: 'array',
22
15
  items: {
@@ -115,20 +108,6 @@ function integer(value, name, min, max) {
115
108
  throw new Error(`parameter ${name} must be an integer from ${min} to ${max}`);
116
109
  return value;
117
110
  }
118
- function parseJson(text, context) {
119
- if (!text.trim())
120
- throw sourceError(`Tencent ${context} returned an empty response`, 'tencent_empty_response');
121
- let parsed;
122
- try {
123
- parsed = JSON.parse(text);
124
- }
125
- catch (error) {
126
- throw sourceError(`Tencent ${context} returned invalid JSON: ${error instanceof Error ? error.message : String(error)}`, 'tencent_invalid_response');
127
- }
128
- if (!isRecord(parsed))
129
- throw sourceError(`Tencent ${context} returned ${Array.isArray(parsed) ? 'an array' : typeof parsed}, expected an object`, 'tencent_invalid_response');
130
- return parsed;
131
- }
132
111
  function parseCodeParams(params, name = 'code') {
133
112
  const code = requireTencentSecurity(parseSecurityCode(params[name], name), name);
134
113
  return { code, canonical: code.canonical };
@@ -246,41 +225,8 @@ async function executeQuote(params, signal) {
246
225
  }
247
226
  return { data: rows, schema: quoteOutput };
248
227
  }
249
- function defaultParamRejection(payload) {
250
- return payload.msg === 'param error';
251
- }
252
- async function callKlineHosts(transport, signal) {
253
- const errors = [];
254
- const rejected = transport.isParamRejection ?? defaultParamRejection;
255
- for (const host of KLINE_HOSTS) {
256
- if ((hostDownUntil.get(host) ?? 0) > Date.now())
257
- continue;
258
- try {
259
- const url = `${host}${transport.path}?param=${encodeURIComponent(transport.param)}`;
260
- const payload = parseJson(await getText(url, signal), `${transport.label} ${host}`);
261
- if (rejected(payload)) {
262
- throw sourceError(`Tencent rejected the ${transport.label} parameter (${String(payload.msg ?? '') || `code ${String(payload.code)}`}): ${transport.param}`, 'tencent_invalid_param');
263
- }
264
- if (isRecord(payload.data) && !transport.isEmpty(payload.data))
265
- return payload.data;
266
- errors.push(`${host}: empty data`);
267
- hostDownUntil.set(host, Date.now() + HOST_COOLDOWN_MS);
268
- }
269
- catch (error) {
270
- // Cancellation and param failures rethrow before blacklist/rotation; see
271
- // `docs/dev/web-retriever.md` §4.2.
272
- if (error instanceof Error && error.name === 'AbortError')
273
- throw error;
274
- if (error.code === 'tencent_invalid_param')
275
- throw error;
276
- errors.push(`${host}: ${error instanceof Error ? error.message : String(error)}`);
277
- hostDownUntil.set(host, Date.now() + HOST_COOLDOWN_MS);
278
- }
279
- }
280
- throw sourceError(`Tencent ${transport.label} endpoints unavailable: ${errors.join('; ')}`, 'tencent_kline_unavailable');
281
- }
282
228
  async function callKline(path, param, signal) {
283
- return { data: await callKlineHosts({ path, param, label: 'K-line', isEmpty: (data) => Object.keys(data).length === 0 }, signal) };
229
+ return { data: await callIfzqHosts({ path, param, label: 'K-line', isEmpty: (data) => Object.keys(data).length === 0 }, signal) };
284
230
  }
285
231
  function addDays(date, days) {
286
232
  const value = new Date(`${date}T00:00:00Z`);
@@ -498,7 +444,7 @@ const offshoreKlinePaths = {
498
444
  us: { qfq: '/appstock/app/usfqkline/get', none: '/appstock/app/kline/kline' },
499
445
  };
500
446
  async function callOffshoreKline(path, param, symbol, signal) {
501
- const data = await callKlineHosts({
447
+ const data = await callIfzqHosts({
502
448
  path,
503
449
  param,
504
450
  label: `${symbol} K-line`,
@@ -761,7 +707,7 @@ function parseUsPrepostRow(data, symbol, requested) {
761
707
  }
762
708
  async function fetchUsPrepostRow(ticker, signal) {
763
709
  const symbol = await resolveUsKlineSymbol(ticker, signal);
764
- const data = await callKlineHosts({
710
+ const data = await callIfzqHosts({
765
711
  path: '/appstock/app/usfqkline/get',
766
712
  param: `${symbol},day,,,${US_PREPOST_BARS},qfq`,
767
713
  label: `${symbol} pre/post`,
@@ -963,6 +909,39 @@ function createSource(options) {
963
909
  execute: async (request, signal) => options.execute(normalize(request.params), signal),
964
910
  };
965
911
  }
912
+ /**
913
+ * One daily series for a UI pane: always day/qfq, one request per symbol, no paging.
914
+ * It runs the same executors and row parsers as `get_kline` (a second parser would drift), and it is
915
+ * the only place that knows the desk shows 万股 for 科创板 while the main board reports 手.
916
+ */
917
+ export async function fetchDailyBars(input, signal, count = 120) {
918
+ const thscode = typeof input.thscode === 'string' ? input.thscode.trim() : '';
919
+ const upper = thscode.toUpperCase();
920
+ const bars = (rows) => rows.map((row) => ({
921
+ date: String(row.date),
922
+ open: Number(row.open),
923
+ high: Number(row.high),
924
+ low: Number(row.low),
925
+ close: Number(row.close),
926
+ volume: Number(row.volume),
927
+ }));
928
+ if (upper.endsWith('.HK')) {
929
+ const params = normalizeOffshoreKline({ code: thscode, period: 'day', adjust: 'qfq', count }, 'hk');
930
+ const { data } = await executeOffshoreKline(params, signal, 'hk');
931
+ return { thscode, adjust: 'qfq', bars: bars(data).slice(-count), volume_unit: 'share' };
932
+ }
933
+ if (/^[A-Z][A-Z0-9.]{0,9}\.[A-Z]{1,3}$/u.test(upper) && !/\.(SH|SZ|BJ)$/u.test(upper)) {
934
+ const params = normalizeOffshoreKline({ code: thscode, period: 'day', adjust: 'qfq', count }, 'us');
935
+ const { data } = await executeOffshoreKline(params, signal, 'us');
936
+ return { thscode, adjust: 'qfq', bars: bars(data).slice(-count), volume_unit: 'share' };
937
+ }
938
+ const { data } = await executeKline({ code: thscode, period: 'day', adjust: 'qfq', count }, signal);
939
+ // 科创板 reports daily volume in shares (688599: 27-29M) while the main board reports 手 (600519: 35,116)
940
+ // — the same split as the minute endpoint, and daily rows carry no turnover column to cross-check.
941
+ const digits = thscode.slice(0, 6);
942
+ // The endpoint answers count+1 rows; the pane asks for a window, so hand it exactly that.
943
+ return { thscode, adjust: 'qfq', bars: bars(data).slice(-count), volume_unit: /^68[89]/u.test(digits) ? 'share' : 'lot' };
944
+ }
966
945
  export function createTencentSources() {
967
946
  return [
968
947
  createSource({
@@ -2,6 +2,14 @@ export declare const QUOTE_URL = "https://qt.gtimg.cn/q=";
2
2
  export declare const SMARTBOX_URL = "https://smartbox.gtimg.cn/s3/";
3
3
  export declare const TENCENT_MIN_INTERVAL_MS = 120;
4
4
  export declare const tencentThrottle: <T>(task: () => Promise<T>) => Promise<T>;
5
+ /**
6
+ * ifzq JSON hosts (K-line + intraday trend). One rotation and one cooldown table for both
7
+ * callers: a host that failed for K-lines must not be retried by the trend path 200ms later.
8
+ */
9
+ export declare const TENCENT_IFZQ_HOSTS: string[];
10
+ export declare const TENCENT_HOST_COOLDOWN_MS = 120000;
11
+ /** Shared by every ifzq caller; keyed by host URL. */
12
+ export declare const tencentHostDownUntil: Map<string, number>;
5
13
  export type JsonRecord = Record<string, unknown>;
6
14
  export declare function isRecord(value: unknown): value is JsonRecord;
7
15
  export declare function numberOrNull(value: unknown): number | null;
@@ -48,3 +56,26 @@ export interface SmartboxCandidate {
48
56
  export declare function parseSmartbox(text: string): SmartboxCandidate[];
49
57
  export declare const SMARTBOX_MARKETS: string[];
50
58
  export declare function fetchSmartbox(query: string, market: string, signal: AbortSignal): Promise<SmartboxCandidate[]>;
59
+ /** ifzq JSON body: empty / non-JSON / non-object must fail loudly with the host named. */
60
+ export declare function parseIfzqPayload(text: string, context: string): JsonRecord;
61
+ /** One ifzq request; `param=` is the K-line shape, `query` is for endpoints with their own names. */
62
+ export interface IfzqRequest {
63
+ path: string;
64
+ param?: string;
65
+ query?: string;
66
+ label: string;
67
+ /** Error code when every host is exhausted; K-line keeps its historical code. */
68
+ code?: string;
69
+ /** "Host gave nothing": whole data object for A-shares, symbol series for HK/US. */
70
+ isEmpty: (data: JsonRecord) => boolean;
71
+ /**
72
+ * Stop on first param rejection: another host will not fix it, and blacklisting all hosts for
73
+ * 120s spreads one bad call process-wide. HK/US returns `{"code":1,"msg":"bad params"}`.
74
+ */
75
+ isParamRejection?: (payload: JsonRecord) => boolean;
76
+ }
77
+ /**
78
+ * Rotate the shared ifzq hosts and return the first non-empty `data` object. Cancellation and
79
+ * param failures rethrow before blacklist/rotation; see `docs/dev/web-retriever.md` §4.2.
80
+ */
81
+ export declare function callIfzqHosts(request: IfzqRequest, signal: AbortSignal): Promise<JsonRecord>;
@@ -7,6 +7,18 @@ export const QUOTE_URL = 'https://qt.gtimg.cn/q=';
7
7
  export const SMARTBOX_URL = 'https://smartbox.gtimg.cn/s3/';
8
8
  export const TENCENT_MIN_INTERVAL_MS = 120;
9
9
  export const tencentThrottle = createRequestThrottle(TENCENT_MIN_INTERVAL_MS);
10
+ /**
11
+ * ifzq JSON hosts (K-line + intraday trend). One rotation and one cooldown table for both
12
+ * callers: a host that failed for K-lines must not be retried by the trend path 200ms later.
13
+ */
14
+ export const TENCENT_IFZQ_HOSTS = [
15
+ 'https://web.ifzq.gtimg.cn',
16
+ 'https://proxy.finance.qq.com/ifzqgtimg',
17
+ 'https://ifzq.gtimg.cn',
18
+ ];
19
+ export const TENCENT_HOST_COOLDOWN_MS = 120_000;
20
+ /** Shared by every ifzq caller; keyed by host URL. */
21
+ export const tencentHostDownUntil = new Map();
10
22
  export function isRecord(value) {
11
23
  return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
12
24
  }
@@ -324,3 +336,54 @@ export async function fetchSmartbox(query, market, signal) {
324
336
  const text = await tencentGetText(url, signal);
325
337
  return parseSmartbox(text);
326
338
  }
339
+ /** ifzq JSON body: empty / non-JSON / non-object must fail loudly with the host named. */
340
+ export function parseIfzqPayload(text, context) {
341
+ if (!text.trim())
342
+ throw sourceError(`Tencent ${context} returned an empty response`, 'tencent_empty_response');
343
+ let parsed;
344
+ try {
345
+ parsed = JSON.parse(text);
346
+ }
347
+ catch (error) {
348
+ throw sourceError(`Tencent ${context} returned invalid JSON: ${error instanceof Error ? error.message : String(error)}`, 'tencent_invalid_response');
349
+ }
350
+ if (!isRecord(parsed))
351
+ throw sourceError(`Tencent ${context} returned ${Array.isArray(parsed) ? 'an array' : typeof parsed}, expected an object`, 'tencent_invalid_response');
352
+ return parsed;
353
+ }
354
+ function ifzqParamRejected(payload) {
355
+ return payload.msg === 'param error';
356
+ }
357
+ /**
358
+ * Rotate the shared ifzq hosts and return the first non-empty `data` object. Cancellation and
359
+ * param failures rethrow before blacklist/rotation; see `docs/dev/web-retriever.md` §4.2.
360
+ */
361
+ export async function callIfzqHosts(request, signal) {
362
+ const errors = [];
363
+ const rejected = request.isParamRejection ?? ifzqParamRejected;
364
+ const link = request.query ?? `param=${encodeURIComponent(request.param ?? '')}`;
365
+ for (const host of TENCENT_IFZQ_HOSTS) {
366
+ if ((tencentHostDownUntil.get(host) ?? 0) > Date.now())
367
+ continue;
368
+ try {
369
+ const payload = parseIfzqPayload(await tencentGetText(`${host}${request.path}?${link}`, signal), `${request.label} ${host}`);
370
+ if (rejected(payload)) {
371
+ const detail = String(payload.msg ?? '') || `code ${String(payload.code)}`;
372
+ throw sourceError(`Tencent rejected the ${request.label} parameter (${detail})`, 'tencent_invalid_param');
373
+ }
374
+ if (isRecord(payload.data) && !request.isEmpty(payload.data))
375
+ return payload.data;
376
+ errors.push(`${host}: empty data`);
377
+ tencentHostDownUntil.set(host, Date.now() + TENCENT_HOST_COOLDOWN_MS);
378
+ }
379
+ catch (error) {
380
+ if (error instanceof Error && error.name === 'AbortError')
381
+ throw error;
382
+ if (error.code === 'tencent_invalid_param')
383
+ throw error;
384
+ errors.push(`${host}: ${error instanceof Error ? error.message : String(error)}`);
385
+ tencentHostDownUntil.set(host, Date.now() + TENCENT_HOST_COOLDOWN_MS);
386
+ }
387
+ }
388
+ throw sourceError(`Tencent ${request.label} endpoints unavailable: ${errors.join('; ')}`, request.code ?? 'tencent_kline_unavailable');
389
+ }
@@ -0,0 +1,53 @@
1
+ export type TrendMarket = 'a-share' | 'hk' | 'us';
2
+ export type TrendSource = 'tencent' | 'eastmoney';
3
+ export type TrendStatus = 'live' | 'closed' | 'previous';
4
+ export type TrendPoint = [time: string, price: number, avg: number | null, volume: number | null, amount: number | null];
5
+ export interface TrendTarget {
6
+ thscode: string;
7
+ source: TrendSource;
8
+ market: TrendMarket;
9
+ /** Tencent symbol (`sh600519`, `hk00700`), set on the Tencent branch. */
10
+ symbol?: string;
11
+ /** Eastmoney secid (`105.AAPL`), set on the US branch. */
12
+ secid?: string;
13
+ isIndex: boolean;
14
+ volumeUnit: 'lot' | 'share' | null;
15
+ currency: string | null;
16
+ }
17
+ export interface TrendSeries {
18
+ thscode: string;
19
+ source: TrendSource;
20
+ market: TrendMarket;
21
+ tz: string;
22
+ session_date: string | null;
23
+ session_status: TrendStatus;
24
+ /** Live but no point for >10 trading minutes: the desk says so instead of faking realtime. */
25
+ stale: boolean;
26
+ prev_close: number;
27
+ open: number | null;
28
+ high: number | null;
29
+ low: number | null;
30
+ last: number | null;
31
+ /** Day VWAP; null for indices (an index level has no traded price). */
32
+ avg: number | null;
33
+ volume: number | null;
34
+ amount: number | null;
35
+ volume_unit: 'lot' | 'share' | null;
36
+ currency: string | null;
37
+ points: TrendPoint[];
38
+ }
39
+ /**
40
+ * Storage identity → upstream request. `undefined` means the chart cannot be drawn at all
41
+ * (US OTC pink and exotic US indices): the caller must not spend a request to find out.
42
+ */
43
+ export declare function resolveTrendTarget(item: {
44
+ thscode?: unknown;
45
+ asset_type?: unknown;
46
+ }): TrendTarget | undefined;
47
+ /** Trading minutes elapsed up to a wall clock; lunch breaks never count as elapsed time. */
48
+ export declare function elapsedTradingMinutes(market: TrendMarket, minutes: number): number;
49
+ /** One entry point for both branches; `thscode` is filled by the caller, which owns identity. */
50
+ export declare function fetchTrendSeries(target: TrendTarget, options: {
51
+ signal: AbortSignal;
52
+ now?: number;
53
+ }): Promise<TrendSeries>;