@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 +58 -0
- package/README.md +8 -6
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/sources/tencent-http.d.ts +20 -0
- package/lib/sources/tencent-http.js +37 -58
- package/lib/sources/tencent-public-core.d.ts +31 -0
- package/lib/sources/tencent-public-core.js +63 -0
- package/lib/sources/trend-series.d.ts +53 -0
- package/lib/sources/trend-series.js +383 -0
- 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 +2 -1
- package/watchlist/client.js +65 -17
- package/watchlist/client.src.cjs +746 -52
- package/watchlist/index.js +171 -1
- package/watchlist/package.json +1 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intraday trend series for the host-plane watchlist: Tencent `appstock/app/minute/query` for
|
|
3
|
+
* A-shares and HK, Eastmoney `push2his .../trends2/get` for US. Leaf module — it only reuses the
|
|
4
|
+
* two existing throttle chains and the shared identity parser, so the host package can call it
|
|
5
|
+
* through `lib/` without pulling the data-collector hub in.
|
|
6
|
+
*
|
|
7
|
+
* The desk gets one shape for all markets; every judgement the sources disagree on (units,
|
|
8
|
+
* after-hours padding, closing auction, session clock) is made here and stated in the payload.
|
|
9
|
+
*/
|
|
10
|
+
import { sharedEastmoneyClient } from '../net/eastmoney-client.js';
|
|
11
|
+
import { parseSecurityCode } from './security-code.js';
|
|
12
|
+
import { callIfzqHosts, isRecord, numberOrNull, requiredNumber, sourceError } from './tencent-public-core.js';
|
|
13
|
+
const TZ = {
|
|
14
|
+
'a-share': 'Asia/Shanghai',
|
|
15
|
+
hk: 'Asia/Hong_Kong',
|
|
16
|
+
us: 'America/New_York',
|
|
17
|
+
};
|
|
18
|
+
/** Continuous sessions in exchange-local minutes; lunch breaks are two entries, not a gap to smooth. */
|
|
19
|
+
const SESSIONS = {
|
|
20
|
+
'a-share': [[570, 690], [780, 900]],
|
|
21
|
+
hk: [[570, 720], [780, 960]],
|
|
22
|
+
us: [[570, 960]],
|
|
23
|
+
};
|
|
24
|
+
/** Tencent returns after-hours padding past this minute (A-share 15:06–15:30, HK closing auction). */
|
|
25
|
+
const TENCENT_CUT = { 'a-share': '1500', hk: '1600', us: '1600' };
|
|
26
|
+
/** Tencent US minute trend answers one closing row with no date; that market goes to Eastmoney. */
|
|
27
|
+
const US_SECID_BY_VENUE = { OQ: '105', N: '106', AM: '107' };
|
|
28
|
+
const US_INDEX_SECID = {
|
|
29
|
+
IXIC: '100.NDX', NDX: '100.NDX',
|
|
30
|
+
INX: '100.SPX', SPX: '100.SPX',
|
|
31
|
+
DJI: '100.DJIA', DJIA: '100.DJIA',
|
|
32
|
+
};
|
|
33
|
+
const TREND_CURRENCY = {
|
|
34
|
+
'a-share': 'CNY',
|
|
35
|
+
'fund-etf': 'CNY',
|
|
36
|
+
'a-share-index': null,
|
|
37
|
+
'hk-stock': 'HKD',
|
|
38
|
+
'hk-index': null,
|
|
39
|
+
'us-stock': 'USD',
|
|
40
|
+
'us-index': null,
|
|
41
|
+
};
|
|
42
|
+
const HK_KEY = /^(?:\d{5}|[A-Z][A-Z0-9.]{1,9})\.HK$/u;
|
|
43
|
+
const US_KEY = /^([A-Z][A-Z0-9.]{0,9})\.([A-Z]{1,3})$/u;
|
|
44
|
+
/**
|
|
45
|
+
* Storage identity → upstream request. `undefined` means the chart cannot be drawn at all
|
|
46
|
+
* (US OTC pink and exotic US indices): the caller must not spend a request to find out.
|
|
47
|
+
*/
|
|
48
|
+
export function resolveTrendTarget(item) {
|
|
49
|
+
const thscode = typeof item.thscode === 'string' ? item.thscode.trim() : '';
|
|
50
|
+
const assetType = typeof item.asset_type === 'string' ? item.asset_type : '';
|
|
51
|
+
if (thscode.length === 0)
|
|
52
|
+
return undefined;
|
|
53
|
+
const currency = TREND_CURRENCY[assetType] ?? null;
|
|
54
|
+
if (assetType === 'a-share' || assetType === 'a-share-index' || assetType === 'fund-etf') {
|
|
55
|
+
let code;
|
|
56
|
+
try {
|
|
57
|
+
code = parseSecurityCode(thscode, 'thscode');
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
// Storage keys are canonical (`600519.SH`); a bare or lowercase code must not reach upstream.
|
|
63
|
+
if (code.canonical !== thscode)
|
|
64
|
+
return undefined;
|
|
65
|
+
return {
|
|
66
|
+
thscode,
|
|
67
|
+
source: 'tencent',
|
|
68
|
+
market: 'a-share',
|
|
69
|
+
symbol: code.tencentSymbol,
|
|
70
|
+
isIndex: assetType === 'a-share-index',
|
|
71
|
+
volumeUnit: 'lot',
|
|
72
|
+
currency,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (assetType === 'hk-stock' || assetType === 'hk-index') {
|
|
76
|
+
if (!HK_KEY.test(thscode))
|
|
77
|
+
return undefined;
|
|
78
|
+
return {
|
|
79
|
+
thscode,
|
|
80
|
+
source: 'tencent',
|
|
81
|
+
market: 'hk',
|
|
82
|
+
symbol: `hk${thscode.slice(0, -3)}`,
|
|
83
|
+
isIndex: assetType === 'hk-index',
|
|
84
|
+
volumeUnit: assetType === 'hk-index' ? null : 'share',
|
|
85
|
+
currency,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (assetType === 'us-index') {
|
|
89
|
+
if (!thscode.endsWith('.US'))
|
|
90
|
+
return undefined;
|
|
91
|
+
const secid = US_INDEX_SECID[thscode.slice(0, -3)];
|
|
92
|
+
if (secid === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
return { thscode, source: 'eastmoney', market: 'us', secid, isIndex: true, volumeUnit: null, currency: null };
|
|
95
|
+
}
|
|
96
|
+
if (assetType === 'us-stock') {
|
|
97
|
+
const match = US_KEY.exec(thscode);
|
|
98
|
+
if (match === null)
|
|
99
|
+
return undefined;
|
|
100
|
+
const marketId = US_SECID_BY_VENUE[match[2]];
|
|
101
|
+
if (marketId === undefined)
|
|
102
|
+
return undefined;
|
|
103
|
+
return { thscode, source: 'eastmoney', market: 'us', secid: `${marketId}.${match[1]}`, isIndex: false, volumeUnit: 'share', currency };
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
/** Trading minutes elapsed up to a wall clock; lunch breaks never count as elapsed time. */
|
|
108
|
+
export function elapsedTradingMinutes(market, minutes) {
|
|
109
|
+
let total = 0;
|
|
110
|
+
for (const [start, end] of SESSIONS[market]) {
|
|
111
|
+
total += Math.min(Math.max(minutes - start, 0), end - start);
|
|
112
|
+
}
|
|
113
|
+
return total;
|
|
114
|
+
}
|
|
115
|
+
function sessionLength(market) {
|
|
116
|
+
return SESSIONS[market].reduce((sum, [start, end]) => sum + (end - start), 0);
|
|
117
|
+
}
|
|
118
|
+
function zonedClock(ms, timeZone) {
|
|
119
|
+
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
120
|
+
timeZone,
|
|
121
|
+
year: 'numeric',
|
|
122
|
+
month: '2-digit',
|
|
123
|
+
day: '2-digit',
|
|
124
|
+
hour: '2-digit',
|
|
125
|
+
minute: '2-digit',
|
|
126
|
+
hourCycle: 'h23',
|
|
127
|
+
}).formatToParts(new Date(ms));
|
|
128
|
+
const pick = (type) => Number(parts.find((part) => part.type === type)?.value);
|
|
129
|
+
const date = `${pick('year')}-${String(pick('month')).padStart(2, '0')}-${String(pick('day')).padStart(2, '0')}`;
|
|
130
|
+
return { date, minutes: pick('hour') * 60 + pick('minute') };
|
|
131
|
+
}
|
|
132
|
+
/** The desk must never present yesterday's line as today's; the clock lives here, not in the browser. */
|
|
133
|
+
function sessionState(market, sessionDate, lastTime, now) {
|
|
134
|
+
if (sessionDate === null)
|
|
135
|
+
return { status: 'previous', stale: false };
|
|
136
|
+
const clock = zonedClock(now, TZ[market]);
|
|
137
|
+
if (clock.date !== sessionDate)
|
|
138
|
+
return { status: 'previous', stale: false };
|
|
139
|
+
const elapsed = elapsedTradingMinutes(market, clock.minutes);
|
|
140
|
+
if (elapsed <= 0 || elapsed >= sessionLength(market))
|
|
141
|
+
return { status: 'closed', stale: false };
|
|
142
|
+
const elapsedAtLast = elapsedTradingMinutes(market, Number(lastTime.slice(0, 2)) * 60 + Number(lastTime.slice(3, 5)));
|
|
143
|
+
return { status: 'live', stale: elapsed - elapsedAtLast > 10 };
|
|
144
|
+
}
|
|
145
|
+
/** Wall-clock offset of a time zone at one instant, in minutes (DST-aware). */
|
|
146
|
+
function zoneOffsetMinutes(instant, timeZone) {
|
|
147
|
+
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
148
|
+
timeZone,
|
|
149
|
+
year: 'numeric',
|
|
150
|
+
month: '2-digit',
|
|
151
|
+
day: '2-digit',
|
|
152
|
+
hour: '2-digit',
|
|
153
|
+
minute: '2-digit',
|
|
154
|
+
hourCycle: 'h23',
|
|
155
|
+
}).formatToParts(new Date(instant));
|
|
156
|
+
const pick = (type) => Number(parts.find((part) => part.type === type)?.value);
|
|
157
|
+
const wall = Date.UTC(pick('year'), pick('month') - 1, pick('day'), pick('hour'), pick('minute'));
|
|
158
|
+
return Math.round((wall - instant) / 60_000);
|
|
159
|
+
}
|
|
160
|
+
function hhmm(value, field) {
|
|
161
|
+
const match = /^(\d{2}):(\d{2})$/u.exec(value);
|
|
162
|
+
if (match === null)
|
|
163
|
+
throw sourceError(`trend ${field} is not HH:MM: ${JSON.stringify(value)}`, 'trend_parse_failed');
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Units per share lot in Tencent's A-share minute payload: the main board and ETFs count 手 (100),
|
|
168
|
+
* 科创板 counts shares. Turnover is 元 either way, so the unit is whichever makes amount/volume land
|
|
169
|
+
* on the printed price; the two candidates are a hundredfold apart, so "nearer" needs no threshold —
|
|
170
|
+
* and unlike a board table (688 today, 689 CDR, 北交所 tomorrow) it cannot go stale.
|
|
171
|
+
*/
|
|
172
|
+
function trendLotSize(target, rows) {
|
|
173
|
+
if (target.market !== 'a-share' || target.isIndex)
|
|
174
|
+
return 1;
|
|
175
|
+
const tail = rows[rows.length - 1];
|
|
176
|
+
if (tail === undefined || tail.cumVolume <= 0 || tail.cumAmount <= 0)
|
|
177
|
+
return 100;
|
|
178
|
+
const perUnit = tail.cumAmount / tail.cumVolume;
|
|
179
|
+
return Math.abs(perUnit - tail.price) <= Math.abs(perUnit / 100 - tail.price) ? 1 : 100;
|
|
180
|
+
}
|
|
181
|
+
/** Tencent A-share/HK minute trend: one row per minute with cumulative volume/amount. */
|
|
182
|
+
async function fetchTencentTrend(target, signal, now) {
|
|
183
|
+
const symbol = target.symbol ?? '';
|
|
184
|
+
const payload = await callIfzqHosts({
|
|
185
|
+
path: '/appstock/app/minute/query',
|
|
186
|
+
query: `code=${encodeURIComponent(symbol)}`,
|
|
187
|
+
label: 'minute trend',
|
|
188
|
+
code: 'tencent_minute_unavailable',
|
|
189
|
+
isEmpty: (data) => !isRecord(data[symbol]),
|
|
190
|
+
}, signal);
|
|
191
|
+
const node = payload[symbol];
|
|
192
|
+
if (!isRecord(node))
|
|
193
|
+
throw sourceError(`Tencent minute trend ${symbol} has no symbol node`, 'trend_parse_failed');
|
|
194
|
+
const series = node.data;
|
|
195
|
+
const quote = node.qt;
|
|
196
|
+
if (!isRecord(series) || !Array.isArray(series.data))
|
|
197
|
+
throw sourceError(`Tencent minute trend ${symbol} has no data array`, 'trend_parse_failed');
|
|
198
|
+
if (!isRecord(quote) || !Array.isArray(quote[symbol]))
|
|
199
|
+
throw sourceError(`Tencent minute trend ${symbol} has no qt array`, 'trend_parse_failed');
|
|
200
|
+
const qt = quote[symbol];
|
|
201
|
+
const rawDate = String(series.date ?? '');
|
|
202
|
+
if (!/^\d{8}$/u.test(rawDate))
|
|
203
|
+
throw sourceError(`Tencent minute trend ${symbol} has an unreadable date ${JSON.stringify(series.date)}`, 'trend_parse_failed');
|
|
204
|
+
const last = requiredNumber(qt[3], 'last');
|
|
205
|
+
const prevClose = requiredNumber(qt[4], 'prev_close');
|
|
206
|
+
const rawOpen = numberOrNull(qt[5]);
|
|
207
|
+
const open = rawOpen !== null && rawOpen > 0 ? rawOpen : null;
|
|
208
|
+
const quoteVolume = numberOrNull(qt[6]);
|
|
209
|
+
if (prevClose <= 0)
|
|
210
|
+
throw sourceError(`Tencent minute trend ${symbol} has a non-positive previous close`, 'trend_parse_failed');
|
|
211
|
+
const high = numberOrNull(qt[33]);
|
|
212
|
+
const low = numberOrNull(qt[34]);
|
|
213
|
+
const rows = [];
|
|
214
|
+
for (const raw of series.data) {
|
|
215
|
+
if (typeof raw !== 'string')
|
|
216
|
+
throw sourceError(`Tencent minute trend ${symbol} row is not a string`, 'trend_parse_failed');
|
|
217
|
+
const fields = raw.trim().split(/\s+/u);
|
|
218
|
+
if (fields.length !== 4)
|
|
219
|
+
throw sourceError(`Tencent minute trend ${symbol} row shape changed: ${JSON.stringify(raw)}`, 'trend_parse_failed');
|
|
220
|
+
const [stamp, priceText, volumeText, amountText] = fields;
|
|
221
|
+
if (!/^\d{4}$/u.test(stamp))
|
|
222
|
+
throw sourceError(`Tencent minute trend ${symbol} row time is not HHMM: ${JSON.stringify(stamp)}`, 'trend_parse_failed');
|
|
223
|
+
const price = requiredNumber(priceText, 'price');
|
|
224
|
+
const cumVolume = requiredNumber(volumeText, 'cumulative volume');
|
|
225
|
+
const cumAmount = requiredNumber(amountText, 'cumulative amount');
|
|
226
|
+
if (price <= 0)
|
|
227
|
+
throw sourceError(`Tencent minute trend ${symbol} returned a non-positive price at ${stamp}`, 'trend_parse_failed');
|
|
228
|
+
rows.push({ time: `${stamp.slice(0, 2)}:${stamp.slice(2)}`, price, cumVolume, cumAmount });
|
|
229
|
+
}
|
|
230
|
+
if (rows.length === 0)
|
|
231
|
+
throw sourceError(`Tencent minute trend ${symbol} returned no points`, 'trend_unavailable');
|
|
232
|
+
// Cut the after-hours padding, then keep the HK closing-auction print as the real close.
|
|
233
|
+
const cut = `${TENCENT_CUT[target.market].slice(0, 2)}:${TENCENT_CUT[target.market].slice(2)}`;
|
|
234
|
+
const kept = rows.filter((row) => row.time <= cut);
|
|
235
|
+
if (target.market === 'hk') {
|
|
236
|
+
// HK stocks print the closing auction a few minutes later (16:08); HK indices also carry an
|
|
237
|
+
// evening quote at 18:31 that is not part of the session, so only the near miss is kept.
|
|
238
|
+
const auction = rows.find((row) => row.time > cut && row.time <= '16:10');
|
|
239
|
+
if (auction !== undefined)
|
|
240
|
+
kept.push(auction);
|
|
241
|
+
}
|
|
242
|
+
if (kept.length === 0)
|
|
243
|
+
throw sourceError(`Tencent minute trend ${symbol} had every point after ${cut}`, 'trend_unavailable');
|
|
244
|
+
const lot = trendLotSize(target, kept);
|
|
245
|
+
const points = [];
|
|
246
|
+
let previousKeptVolume = 0;
|
|
247
|
+
let previousKeptAmount = 0;
|
|
248
|
+
let previousTime = '';
|
|
249
|
+
for (const row of kept) {
|
|
250
|
+
if (previousTime !== '' && row.time < previousTime) {
|
|
251
|
+
throw sourceError(`Tencent minute trend ${symbol} time moved backwards at ${row.time}`, 'trend_parse_failed');
|
|
252
|
+
}
|
|
253
|
+
previousTime = row.time;
|
|
254
|
+
// Tencent restates the running totals when a print settles (300803.SZ 2026-11-18: the final row
|
|
255
|
+
// carried 0.04% less turnover than the row before it). A restatement is not corruption: it means
|
|
256
|
+
// "no new trade", so the delta clamps to zero and the running total keeps its high-water mark.
|
|
257
|
+
const volume = Math.max(0, row.cumVolume - previousKeptVolume);
|
|
258
|
+
const amount = Math.max(0, row.cumAmount - previousKeptAmount);
|
|
259
|
+
previousKeptVolume = Math.max(previousKeptVolume, row.cumVolume);
|
|
260
|
+
previousKeptAmount = Math.max(previousKeptAmount, row.cumAmount);
|
|
261
|
+
const shares = row.cumVolume * lot;
|
|
262
|
+
const avg = target.isIndex || shares <= 0 ? null : row.cumAmount / shares;
|
|
263
|
+
points.push([row.time, row.price, avg, volume, amount]);
|
|
264
|
+
}
|
|
265
|
+
const sessionDate = `${rawDate.slice(0, 4)}-${rawDate.slice(4, 6)}-${rawDate.slice(6)}`;
|
|
266
|
+
const state = sessionState(target.market, sessionDate, points[points.length - 1][0], now);
|
|
267
|
+
const tail = points[points.length - 1];
|
|
268
|
+
return {
|
|
269
|
+
thscode: target.thscode,
|
|
270
|
+
source: 'tencent',
|
|
271
|
+
market: target.market,
|
|
272
|
+
tz: TZ[target.market],
|
|
273
|
+
session_date: sessionDate,
|
|
274
|
+
session_status: state.status,
|
|
275
|
+
stale: state.stale,
|
|
276
|
+
prev_close: prevClose,
|
|
277
|
+
open,
|
|
278
|
+
high: high ?? points.reduce((best, point) => Math.max(best, point[1]), points[0][1]),
|
|
279
|
+
low: low ?? points.reduce((best, point) => Math.min(best, point[1]), points[0][1]),
|
|
280
|
+
last,
|
|
281
|
+
avg: tail[2],
|
|
282
|
+
// Quote volume and the last cumulative amount are the day's totals (the 15:00 point matches the
|
|
283
|
+
// quote exactly); `tail[3]` / `tail[4]` are one minute and must not be reported as the whole day.
|
|
284
|
+
volume: quoteVolume !== null && quoteVolume > 0 ? quoteVolume : previousKeptVolume,
|
|
285
|
+
amount: previousKeptAmount > 0 ? previousKeptAmount : null,
|
|
286
|
+
volume_unit: target.market === 'a-share' && !target.isIndex ? (lot === 100 ? 'lot' : 'share') : target.volumeUnit,
|
|
287
|
+
currency: target.currency,
|
|
288
|
+
points,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/** Eastmoney US trend: per-minute OHLC + volume/amount/avg, previous close included. */
|
|
292
|
+
async function fetchEastmoneyTrend(target, signal, now) {
|
|
293
|
+
const secid = target.secid ?? '';
|
|
294
|
+
const url = new URL('https://push2his.eastmoney.com/api/qt/stock/trends2/get');
|
|
295
|
+
url.searchParams.set('secid', secid);
|
|
296
|
+
url.searchParams.set('fields1', 'f1,f2,f3,f4,f5,f6,f7,f8');
|
|
297
|
+
url.searchParams.set('fields2', 'f51,f52,f53,f54,f55,f56,f57,f58');
|
|
298
|
+
url.searchParams.set('iscr', '0');
|
|
299
|
+
url.searchParams.set('ndays', '1');
|
|
300
|
+
const payload = await sharedEastmoneyClient().fetchJson(url.toString(), { signal });
|
|
301
|
+
if (!isRecord(payload) || !isRecord(payload.data))
|
|
302
|
+
throw sourceError(`Eastmoney trend ${secid} returned no data`, 'trend_unavailable');
|
|
303
|
+
const data = payload.data;
|
|
304
|
+
const prevClose = requiredNumber(data.preClose ?? data.prePrice, 'prev_close');
|
|
305
|
+
if (prevClose <= 0)
|
|
306
|
+
throw sourceError(`Eastmoney trend ${secid} has a non-positive previous close`, 'trend_parse_failed');
|
|
307
|
+
if (!Array.isArray(data.trends) || data.trends.length === 0)
|
|
308
|
+
throw sourceError(`Eastmoney trend ${secid} returned no points`, 'trend_unavailable');
|
|
309
|
+
// Eastmoney timestamps are Beijing time even for US rows (22:30–05:00 for a 09:30–16:00 ET
|
|
310
|
+
// session); the desk must show the exchange clock, so shift every row by the ET offset once.
|
|
311
|
+
let offsetMinutes = null;
|
|
312
|
+
let sessionDate = null;
|
|
313
|
+
let open = null;
|
|
314
|
+
let high = null;
|
|
315
|
+
let low = null;
|
|
316
|
+
const points = [];
|
|
317
|
+
let previousTime = '';
|
|
318
|
+
for (const raw of data.trends) {
|
|
319
|
+
if (typeof raw !== 'string')
|
|
320
|
+
throw sourceError(`Eastmoney trend ${secid} row is not a string`, 'trend_parse_failed');
|
|
321
|
+
const fields = raw.split(',');
|
|
322
|
+
if (fields.length !== 8)
|
|
323
|
+
throw sourceError(`Eastmoney trend ${secid} row shape changed: ${JSON.stringify(raw)}`, 'trend_parse_failed');
|
|
324
|
+
const stamp = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})$/u.exec(fields[0]);
|
|
325
|
+
if (stamp === null)
|
|
326
|
+
throw sourceError(`Eastmoney trend ${secid} row time is unreadable: ${JSON.stringify(fields[0])}`, 'trend_parse_failed');
|
|
327
|
+
const instant = Date.UTC(Number(stamp[1]), Number(stamp[2]) - 1, Number(stamp[3]), Number(stamp[4]) - 8, Number(stamp[5]));
|
|
328
|
+
offsetMinutes ??= zoneOffsetMinutes(instant, TZ[target.market]);
|
|
329
|
+
const local = new Date(instant + offsetMinutes * 60_000);
|
|
330
|
+
const time = hhmm(`${String(local.getUTCHours()).padStart(2, '0')}:${String(local.getUTCMinutes()).padStart(2, '0')}`, 'time');
|
|
331
|
+
if (previousTime !== '' && time < previousTime)
|
|
332
|
+
throw sourceError(`Eastmoney trend ${secid} time moved backwards at ${time}`, 'trend_parse_failed');
|
|
333
|
+
previousTime = time;
|
|
334
|
+
sessionDate ??= local.toISOString().slice(0, 10);
|
|
335
|
+
const barOpen = requiredNumber(fields[1], 'open');
|
|
336
|
+
const price = requiredNumber(fields[2], 'close');
|
|
337
|
+
const barHigh = requiredNumber(fields[3], 'high');
|
|
338
|
+
const barLow = requiredNumber(fields[4], 'low');
|
|
339
|
+
if (price <= 0)
|
|
340
|
+
throw sourceError(`Eastmoney trend ${secid} returned a non-positive price at ${time}`, 'trend_parse_failed');
|
|
341
|
+
open ??= barOpen;
|
|
342
|
+
high = high === null ? barHigh : Math.max(high, barHigh);
|
|
343
|
+
low = low === null ? barLow : Math.min(low, barLow);
|
|
344
|
+
const volume = numberOrNull(fields[5]);
|
|
345
|
+
const amount = numberOrNull(fields[6]);
|
|
346
|
+
// Index rows carry amount 0 (no traded value); null keeps it out of the UI instead of showing 0.
|
|
347
|
+
const avg = target.isIndex ? null : numberOrNull(fields[7]);
|
|
348
|
+
points.push([time, price, avg, volume, amount === 0 ? null : amount]);
|
|
349
|
+
}
|
|
350
|
+
if (points.length === 0)
|
|
351
|
+
throw sourceError(`Eastmoney trend ${secid} returned no points`, 'trend_unavailable');
|
|
352
|
+
const state = sessionState(target.market, sessionDate, points[points.length - 1][0], now);
|
|
353
|
+
const tail = points[points.length - 1];
|
|
354
|
+
return {
|
|
355
|
+
thscode: target.thscode,
|
|
356
|
+
source: 'eastmoney',
|
|
357
|
+
market: target.market,
|
|
358
|
+
tz: TZ[target.market],
|
|
359
|
+
session_date: sessionDate,
|
|
360
|
+
session_status: state.status,
|
|
361
|
+
stale: state.stale,
|
|
362
|
+
prev_close: prevClose,
|
|
363
|
+
open,
|
|
364
|
+
high,
|
|
365
|
+
low,
|
|
366
|
+
last: tail[1],
|
|
367
|
+
avg: target.isIndex ? null : tail[2],
|
|
368
|
+
// `0` from an unreadable column is "no number", not a traded zero (index rows carry amount 0).
|
|
369
|
+
volume: points.some((point) => point[3] !== null) ? points.reduce((sum, point) => sum + (point[3] ?? 0), 0) : null,
|
|
370
|
+
amount: points.some((point) => point[4] !== null) ? points.reduce((sum, point) => sum + (point[4] ?? 0), 0) : null,
|
|
371
|
+
volume_unit: target.volumeUnit,
|
|
372
|
+
currency: target.currency,
|
|
373
|
+
points,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/** One entry point for both branches; `thscode` is filled by the caller, which owns identity. */
|
|
377
|
+
export async function fetchTrendSeries(target, options) {
|
|
378
|
+
const now = options.now ?? Date.now();
|
|
379
|
+
const series = target.source === 'tencent'
|
|
380
|
+
? await fetchTencentTrend(target, options.signal, now)
|
|
381
|
+
: await fetchEastmoneyTrend(target, options.signal, now);
|
|
382
|
+
return series;
|
|
383
|
+
}
|
|
@@ -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.
|
|
6
|
+
export declare const LOCAL_FETCH_CLIENT_VERSION = "2.27.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.
|
|
7
|
+
export const LOCAL_FETCH_CLIENT_VERSION = '2.27.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.
|
|
38
|
+
export declare const WIND_CLIENT_VERSION = "2.27.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.
|
|
22
|
+
export const WIND_CLIENT_VERSION = '2.27.1';
|
|
23
23
|
function errorText(error) {
|
|
24
24
|
return error instanceof Error ? error.message : String(error);
|
|
25
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v587d/capital-generation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.27.1",
|
|
4
4
|
"description": "Capital Generation:面向中国散户的 AI 投资助手插件(自动模式 Agent Preset)",
|
|
5
5
|
"icon": "assets/cg-icon.png",
|
|
6
6
|
"author": "v587d",
|
|
@@ -162,6 +162,7 @@
|
|
|
162
162
|
"python:verify": "node scripts/python-runtime.mjs verify",
|
|
163
163
|
"prepublishOnly": "npm run build",
|
|
164
164
|
"smoke:fuyao": "node scripts/smoke-fuyao.mjs",
|
|
165
|
+
"smoke:trend": "npm run build:watchlist-client && node scripts/smoke-trend.mjs",
|
|
165
166
|
"smoke:wind": "node scripts/smoke-wind.mjs",
|
|
166
167
|
"smoke:local-fetch": "node scripts/smoke-local-fetch.mjs",
|
|
167
168
|
"smoke:calendar": "node scripts/smoke-calendar.mjs",
|