@v587d/capital-generation 2.24.0 → 2.26.0

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +9 -4
  3. package/THIRD_PARTY_NOTICES.md +20 -0
  4. package/automation/brief.js +21 -24
  5. package/automation/builtins.js +55 -54
  6. package/automation/client.js +11 -3
  7. package/automation/client.src.cjs +70 -8
  8. package/automation/package.json +1 -1
  9. package/chart-ui/package.json +1 -1
  10. package/config/client.js +21 -5
  11. package/config/client.src.cjs +264 -0
  12. package/config/package.json +1 -1
  13. package/cordis.patch.yml +9 -2
  14. package/lib/agents/role-tool-policy.d.ts +1 -1
  15. package/lib/agents/root-tool-policy.d.ts +3 -3
  16. package/lib/agents/root-tool-policy.js +2 -2
  17. package/lib/data-collector/catalog-taxonomy.js +4 -0
  18. package/lib/python-runtime/child-env.d.ts +11 -0
  19. package/lib/python-runtime/child-env.js +39 -0
  20. package/lib/python-runtime/errors.d.ts +8 -0
  21. package/lib/python-runtime/errors.js +34 -0
  22. package/lib/python-runtime/lock.d.ts +11 -0
  23. package/lib/python-runtime/lock.js +68 -0
  24. package/lib/python-runtime/manager.d.ts +61 -0
  25. package/lib/python-runtime/manager.js +517 -0
  26. package/lib/python-runtime/manifest.d.ts +5 -0
  27. package/lib/python-runtime/manifest.js +160 -0
  28. package/lib/python-runtime/paths.d.ts +20 -0
  29. package/lib/python-runtime/paths.js +156 -0
  30. package/lib/python-runtime/platform.d.ts +32 -0
  31. package/lib/python-runtime/platform.js +145 -0
  32. package/lib/python-runtime/pnpm.d.ts +24 -0
  33. package/lib/python-runtime/pnpm.js +115 -0
  34. package/lib/python-runtime/probe.d.ts +13 -0
  35. package/lib/python-runtime/probe.js +101 -0
  36. package/lib/python-runtime/routes.d.ts +6 -0
  37. package/lib/python-runtime/routes.js +152 -0
  38. package/lib/python-runtime/types.d.ts +105 -0
  39. package/lib/python-runtime/types.js +3 -0
  40. package/lib/python-runtime-entry.d.ts +10 -0
  41. package/lib/python-runtime-entry.js +60 -0
  42. package/lib/sources/eastmoney-http.js +346 -1
  43. package/lib/sources/tencent-http.js +248 -2
  44. package/lib/sources/tencent-public-core.js +1 -1
  45. package/lib/sources-entry.d.ts +1 -1
  46. package/lib/time/tools.js +2 -0
  47. package/lib/web-retriever/local-fetch.d.ts +1 -1
  48. package/lib/web-retriever/local-fetch.js +1 -1
  49. package/lib/web-retriever/sources.d.ts +16 -1
  50. package/lib/web-retriever/sources.js +133 -1
  51. package/lib/web-retriever/tools.js +41 -1
  52. package/lib/web-retriever/wind-client.d.ts +1 -1
  53. package/lib/web-retriever/wind-client.js +1 -1
  54. package/package.json +13 -1
  55. package/plugin-page/README.en.md +1 -7
  56. package/plugin-page/README.zh.md +1 -8
  57. package/preset/capital-generation/agent.patch.yml +12 -13
  58. package/preset/capital-generation/skills/capital-web-protocol/SKILL.md +10 -4
  59. package/python/worker.py +154 -0
  60. package/runtime/manifest.json +75 -0
  61. package/scripts/python-runtime.mjs +139 -0
  62. package/watchlist/client.js +83 -3
  63. package/watchlist/client.src.cjs +565 -1
  64. package/watchlist/package.json +1 -1
@@ -9,6 +9,30 @@ const EASTMONEY_UT = 'bd1d9ddb04089700cf9c27f6f7426281';
9
9
  const BOARD_TYPES = ['industry', 'concept', 'region'];
10
10
  const BOARD_FS = { industry: 'm:90+t:2', concept: 'm:90+t:3', region: 'm:90+t:1' };
11
11
  const SORT_FIELDS = { change_pct: 'f3', main_net_inflow: 'f62', amount: 'f6' };
12
+ const GLOBAL_SYMBOLS = {
13
+ SPX: { secid: '100.SPX', name: '标普500', market: 'us', currency: 'USD', unit: 'index_points', timeZone: 'America/New_York', volumeUnit: 'shares', amountUnit: null },
14
+ NDX: { secid: '100.NDX', name: '纳斯达克100', market: 'us', currency: 'USD', unit: 'index_points', timeZone: 'America/New_York', volumeUnit: 'shares', amountUnit: null },
15
+ DJIA: { secid: '100.DJIA', name: '道琼斯', market: 'us', currency: 'USD', unit: 'index_points', timeZone: 'America/New_York', volumeUnit: 'shares', amountUnit: null },
16
+ HSI: { secid: '100.HSI', name: '恒生指数', market: 'hk', currency: 'HKD', unit: 'index_points', timeZone: 'Asia/Hong_Kong', volumeUnit: 'shares', amountUnit: 'HKD' },
17
+ HSCEI: { secid: '100.HSCEI', name: '国企指数', market: 'hk', currency: 'HKD', unit: 'index_points', timeZone: 'Asia/Hong_Kong', volumeUnit: 'shares', amountUnit: 'HKD' },
18
+ N225: { secid: '100.N225', name: '日经225', market: 'jp', currency: 'JPY', unit: 'index_points', timeZone: 'Asia/Tokyo', volumeUnit: 'shares', amountUnit: null },
19
+ SXXP: { secid: '100.SXXP', name: '欧洲斯托克600', market: 'eu', currency: 'EUR', unit: 'index_points', timeZone: 'Europe/London', volumeUnit: 'shares', amountUnit: null },
20
+ FCHI: { secid: '100.FCHI', name: '法国CAC40', market: 'eu', currency: 'EUR', unit: 'index_points', timeZone: 'Europe/Paris', volumeUnit: 'shares', amountUnit: null },
21
+ FTSE: { secid: '100.FTSE', name: '英国富时100', market: 'eu', currency: 'GBP', unit: 'index_points', timeZone: 'Europe/London', volumeUnit: 'shares', amountUnit: null },
22
+ AS51: { secid: '100.AS51', name: '澳大利亚标普200', market: 'au', currency: 'AUD', unit: 'index_points', timeZone: 'Australia/Sydney', volumeUnit: 'shares', amountUnit: null },
23
+ HSAHP: { secid: '100.HSAHP', name: 'AH股溢价', market: 'cross', currency: null, unit: 'index_points', timeZone: 'Asia/Hong_Kong', volumeUnit: 'shares', amountUnit: null },
24
+ UDI: { secid: '100.UDI', name: '美元指数', market: 'fx', currency: null, unit: 'index_points', timeZone: 'America/New_York', volumeUnit: null, amountUnit: null },
25
+ USDCNH: { secid: '133.USDCNH', name: '美元兑离岸人民币', market: 'fx', currency: 'CNH', unit: 'CNH_per_USD', timeZone: 'Asia/Shanghai', volumeUnit: null, amountUnit: null },
26
+ US10Y: { secid: '171.US10Y', name: '美国10年期国债收益率', market: 'rates', currency: null, unit: 'percent', timeZone: 'America/New_York', volumeUnit: null, amountUnit: null },
27
+ US2Y: { secid: '171.US2Y', name: '美国2年期国债收益率', market: 'rates', currency: null, unit: 'percent', timeZone: 'America/New_York', volumeUnit: null, amountUnit: null },
28
+ CL00Y: { secid: '102.CL00Y', name: 'NYMEX原油', market: 'commodity', currency: 'USD', unit: 'USD_per_bbl', timeZone: 'America/New_York', volumeUnit: 'contracts', amountUnit: null },
29
+ GC00Y: { secid: '101.GC00Y', name: 'COMEX黄金', market: 'commodity', currency: 'USD', unit: 'USD_per_oz', timeZone: 'America/New_York', volumeUnit: 'contracts', amountUnit: null },
30
+ HG00Y: { secid: '101.HG00Y', name: 'COMEX铜', market: 'commodity', currency: 'USD', unit: 'USD_per_lb', timeZone: 'America/New_York', volumeUnit: 'contracts', amountUnit: null },
31
+ };
32
+ const GLOBAL_SYMBOL_NAMES = Object.keys(GLOBAL_SYMBOLS);
33
+ const GLOBAL_PERIODS = { day: 101, week: 102, month: 103 };
34
+ const MARKET_MARGIN_FILTER = { sse: '(SCDM="007")', szse: '(SCDM="001")', bse: '(SCDM="002")' };
35
+ const MARKET_MARGIN_CODE = { '007': 'sse', '001': 'szse', '002': 'bse' };
12
36
  const topBuySellRow = {
13
37
  type: 'object',
14
38
  properties: {
@@ -38,6 +62,48 @@ const datacenterOutput = (row) => ({
38
62
  required: ['item', 'pagination'],
39
63
  additionalProperties: true,
40
64
  });
65
+ const nullableNumber = { oneOf: [{ type: 'number' }, { type: 'null' }] };
66
+ const nullableString = { oneOf: [{ type: 'string' }, { type: 'null' }] };
67
+ const globalQuoteRow = {
68
+ type: 'object',
69
+ properties: {
70
+ symbol: { type: 'string' }, eastmoney_code: nullableString, eastmoney_market: { oneOf: [{ type: 'integer' }, { type: 'null' }] },
71
+ name: { type: 'string' }, market: { type: 'string' }, currency: nullableString, unit: { type: 'string' },
72
+ price: nullableNumber, prev_close: nullableNumber, change_amt: nullableNumber, change_pct: nullableNumber,
73
+ open: nullableNumber, high: nullableNumber, low: nullableNumber,
74
+ volume: nullableNumber, volume_unit: nullableString, amount: nullableNumber, amount_unit: nullableString,
75
+ quote_time: nullableString, quote_time_utc: nullableString, quote_time_ms: { oneOf: [{ type: 'integer' }, { type: 'null' }] },
76
+ quote_time_zone: { type: 'string' }, is_delayed: { oneOf: [{ type: 'boolean' }, { type: 'null' }] },
77
+ available: { type: 'boolean' }, reason: nullableString, source: { type: 'string' },
78
+ },
79
+ required: ['symbol', 'name', 'market', 'unit', 'quote_time_zone', 'available', 'source'],
80
+ additionalProperties: false,
81
+ };
82
+ const globalKlineRow = {
83
+ type: 'object',
84
+ properties: {
85
+ symbol: { type: 'string' }, name: { type: 'string' }, market: { type: 'string' }, currency: nullableString, unit: { type: 'string' },
86
+ trade_date: { type: 'string' }, open: { type: 'number' }, high: { type: 'number' }, low: { type: 'number' }, close: { type: 'number' },
87
+ volume: nullableNumber, volume_unit: nullableString, amount: nullableNumber, amount_unit: nullableString,
88
+ change_pct: nullableNumber, amplitude_pct: nullableNumber, source: { type: 'string' },
89
+ },
90
+ required: ['symbol', 'name', 'market', 'unit', 'trade_date', 'open', 'high', 'low', 'close', 'source'],
91
+ additionalProperties: false,
92
+ };
93
+ const marketMarginRow = {
94
+ type: 'object',
95
+ properties: {
96
+ trade_date: { type: 'string' }, trade_date_ms: { type: 'integer' },
97
+ market: { type: 'string' }, market_label: nullableString, eastmoney_market_code: { type: 'string' },
98
+ margin_balance: nullableNumber, short_balance: nullableNumber, total_balance: nullableNumber,
99
+ margin_buy: nullableNumber, margin_repay: nullableNumber, margin_net_buy: nullableNumber,
100
+ short_balance_volume: nullableNumber, short_sell_volume: nullableNumber,
101
+ short_repay_volume: nullableNumber, short_net_buy_volume: nullableNumber,
102
+ float_market_cap: nullableNumber, margin_balance_pct: nullableNumber, source: { type: 'string' },
103
+ },
104
+ required: ['trade_date', 'market', 'source'],
105
+ additionalProperties: false,
106
+ };
41
107
  const lockupRow = {
42
108
  type: 'object',
43
109
  properties: {
@@ -82,6 +148,10 @@ function numberOrNull(value) {
82
148
  const parsed = typeof value === 'number' ? value : Number(String(value).replaceAll(',', '').trim());
83
149
  return Number.isFinite(parsed) ? parsed : null;
84
150
  }
151
+ function rounded(value, digits = 4) {
152
+ const factor = 10 ** digits;
153
+ return Math.round(value * factor) / factor;
154
+ }
85
155
  function integer(value, name, min, max) {
86
156
  if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < min || value > max)
87
157
  throw new Error(`${name} must be an integer from ${min} to ${max}`);
@@ -189,6 +259,218 @@ function topFilter(params, ticker) {
189
259
  const code = ticker?.replace(/\.(SH|SZ|BJ)$/i, '');
190
260
  return code ? `${base}(SECURITY_CODE="${code}")` : base;
191
261
  }
262
+ function normalizeGlobalSymbol(value, name = 'symbol') {
263
+ if (typeof value !== 'string')
264
+ throw new Error(`${name} must be a string`);
265
+ const symbol = value.trim().toUpperCase();
266
+ if (!GLOBAL_SYMBOLS[symbol])
267
+ throw new Error(`${name} must be one of ${GLOBAL_SYMBOL_NAMES.join(', ')}`);
268
+ return symbol;
269
+ }
270
+ function normalizeGlobalSymbols(params) {
271
+ assertKnown(params, ['symbols']);
272
+ if (!Array.isArray(params.symbols) || params.symbols.length === 0)
273
+ throw new Error('symbols must be a non-empty array');
274
+ if (params.symbols.length > GLOBAL_SYMBOL_NAMES.length)
275
+ throw new Error(`symbols exceeds maximum ${GLOBAL_SYMBOL_NAMES.length}`);
276
+ return { symbols: [...new Set(params.symbols.map((value) => normalizeGlobalSymbol(value, 'symbols[]')))] };
277
+ }
278
+ function formatQuoteTime(ms, timeZone) {
279
+ const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', {
280
+ timeZone, year: 'numeric', month: '2-digit', day: '2-digit',
281
+ hour: '2-digit', minute: '2-digit', second: '2-digit', hourCycle: 'h23',
282
+ }).formatToParts(new Date(ms)).map((part) => [part.type, part.value]));
283
+ const hour = parts.hour === '24' ? '00' : parts.hour;
284
+ return `${parts.year}-${parts.month}-${parts.day} ${hour}:${parts.minute}:${parts.second}`;
285
+ }
286
+ function emptyGlobalQuoteRow(symbol, spec, reason) {
287
+ return {
288
+ symbol, eastmoney_code: null, eastmoney_market: null, name: spec.name, market: spec.market,
289
+ currency: spec.currency, unit: spec.unit,
290
+ price: null, prev_close: null, change_amt: null, change_pct: null, open: null, high: null, low: null,
291
+ volume: null, volume_unit: spec.volumeUnit, amount: null, amount_unit: spec.amountUnit,
292
+ quote_time: null, quote_time_utc: null, quote_time_ms: null, quote_time_zone: spec.timeZone,
293
+ is_delayed: null, available: false, reason, source: 'eastmoney',
294
+ };
295
+ }
296
+ function parseGlobalQuoteRow(raw, symbol, spec) {
297
+ const price = numberOrNull(raw.f2);
298
+ const seconds = numberOrNull(raw.f124);
299
+ const quoteMs = seconds !== null && seconds > 0 ? Math.round(seconds * 1000) : null;
300
+ const marketId = Number(raw.f13);
301
+ const volume = numberOrNull(raw.f5);
302
+ const amount = numberOrNull(raw.f6);
303
+ return {
304
+ symbol,
305
+ eastmoney_code: textOrNull(raw.f12),
306
+ eastmoney_market: Number.isSafeInteger(marketId) ? marketId : null,
307
+ name: textOrNull(raw.f14) ?? spec.name,
308
+ market: spec.market, currency: spec.currency, unit: spec.unit,
309
+ price,
310
+ prev_close: numberOrNull(raw.f18),
311
+ change_amt: numberOrNull(raw.f4),
312
+ change_pct: numberOrNull(raw.f3),
313
+ open: numberOrNull(raw.f17),
314
+ high: numberOrNull(raw.f15),
315
+ low: numberOrNull(raw.f16),
316
+ volume: spec.volumeUnit && volume !== null && volume > 0 ? volume : null,
317
+ volume_unit: spec.volumeUnit,
318
+ amount: spec.amountUnit && amount !== null && amount > 0 ? amount : null,
319
+ amount_unit: spec.amountUnit,
320
+ quote_time: quoteMs === null ? null : formatQuoteTime(quoteMs, spec.timeZone),
321
+ quote_time_utc: quoteMs === null ? null : new Date(quoteMs).toISOString(),
322
+ quote_time_ms: quoteMs,
323
+ quote_time_zone: spec.timeZone,
324
+ is_delayed: null,
325
+ available: price !== null,
326
+ reason: price === null ? 'no_price' : null,
327
+ source: 'eastmoney',
328
+ };
329
+ }
330
+ async function executeGlobalQuote(params, signal) {
331
+ const symbols = params.symbols;
332
+ const url = new URL('https://push2.eastmoney.com/api/qt/ulist.np/get');
333
+ url.searchParams.set('fltt', '2');
334
+ url.searchParams.set('secids', symbols.map((symbol) => GLOBAL_SYMBOLS[symbol].secid).join(','));
335
+ url.searchParams.set('fields', 'f12,f13,f14,f2,f3,f4,f5,f6,f15,f16,f17,f18,f124');
336
+ const payload = await getJson(url.toString(), signal, 'global quote');
337
+ if (Number(payload.rc) !== 0 || !isRecord(payload.data) || !Array.isArray(payload.data.diff) || !payload.data.diff.every(isRecord)) {
338
+ throw sourceError('Eastmoney global quote returned a non-list response', 'eastmoney_invalid_response');
339
+ }
340
+ const bySecid = new Map();
341
+ for (const raw of payload.data.diff)
342
+ bySecid.set(`${String(raw.f13 ?? '')}.${String(raw.f12 ?? '')}`, raw);
343
+ const rows = symbols.map((symbol) => {
344
+ const spec = GLOBAL_SYMBOLS[symbol];
345
+ const raw = bySecid.get(spec.secid);
346
+ return raw ? parseGlobalQuoteRow(raw, symbol, spec) : emptyGlobalQuoteRow(symbol, spec, 'symbol_not_returned');
347
+ });
348
+ if (!rows.some((row) => row.available === true)) {
349
+ throw sourceError('Eastmoney global quote returned none of the requested symbols', 'eastmoney_invalid_response');
350
+ }
351
+ return { data: rows, schema: globalQuoteRow };
352
+ }
353
+ function normalizeGlobalKline(params) {
354
+ assertKnown(params, ['symbol', 'period', 'start_date', 'end_date']);
355
+ const symbol = normalizeGlobalSymbol(params.symbol);
356
+ const period = params.period === undefined ? 'day' : String(params.period).toLowerCase();
357
+ if (!(period in GLOBAL_PERIODS))
358
+ throw new Error(`period must be one of ${Object.keys(GLOBAL_PERIODS).join(', ')}`);
359
+ const start_date = date(params.start_date, 'start_date');
360
+ const end_date = date(params.end_date, 'end_date');
361
+ if (start_date > end_date)
362
+ throw new Error('start_date must not be later than end_date');
363
+ return { symbol, period, start_date, end_date };
364
+ }
365
+ function parseGlobalKlineRow(line, symbol, spec, name, previousClose) {
366
+ const columns = line.split(',');
367
+ if (columns.length !== 8)
368
+ throw sourceError(`Eastmoney global kline row has ${columns.length} columns, expected 8`, 'eastmoney_invalid_response');
369
+ const tradeDate = dayValue(columns[0]);
370
+ if (tradeDate === null)
371
+ throw sourceError(`Eastmoney global kline row has invalid date ${columns[0]}`, 'eastmoney_invalid_response');
372
+ const [open, close, high, low, volume, amount, amplitude] = columns.slice(1).map(numberOrNull);
373
+ if ([open, close, high, low].some((value) => value === null)) {
374
+ throw sourceError(`Eastmoney global kline row has invalid OHLC for ${tradeDate}`, 'eastmoney_invalid_response');
375
+ }
376
+ const change = previousClose !== null && previousClose > 0
377
+ ? rounded(((close - previousClose) / previousClose) * 100, 4)
378
+ : null;
379
+ return {
380
+ symbol, name, market: spec.market, currency: spec.currency, unit: spec.unit, trade_date: tradeDate,
381
+ open: open, high: high, low: low, close: close,
382
+ volume: spec.volumeUnit && volume !== null && volume > 0 ? volume : null,
383
+ volume_unit: spec.volumeUnit,
384
+ amount: spec.amountUnit && amount !== null && amount > 0 ? amount : null,
385
+ amount_unit: spec.amountUnit,
386
+ change_pct: change,
387
+ amplitude_pct: amplitude,
388
+ source: 'eastmoney',
389
+ };
390
+ }
391
+ async function executeGlobalKline(params, signal) {
392
+ const spec = GLOBAL_SYMBOLS[String(params.symbol)];
393
+ const url = new URL('https://push2his.eastmoney.com/api/qt/stock/kline/get');
394
+ url.searchParams.set('secid', spec.secid);
395
+ url.searchParams.set('klt', String(GLOBAL_PERIODS[String(params.period)]));
396
+ url.searchParams.set('fqt', '1');
397
+ url.searchParams.set('beg', String(params.start_date).replaceAll('-', ''));
398
+ url.searchParams.set('end', String(params.end_date).replaceAll('-', ''));
399
+ url.searchParams.set('fields1', 'f1,f2,f3,f4,f5,f6');
400
+ url.searchParams.set('fields2', 'f51,f52,f53,f54,f55,f56,f57,f58');
401
+ const payload = await getJson(url.toString(), signal, 'global kline');
402
+ if (Number(payload.rc) !== 0 || !isRecord(payload.data) || !Array.isArray(payload.data.klines)) {
403
+ throw sourceError('Eastmoney global kline returned a non-list response', 'eastmoney_invalid_response');
404
+ }
405
+ if (!payload.data.klines.every((line) => typeof line === 'string')) {
406
+ throw sourceError('Eastmoney global kline contains a non-string row', 'eastmoney_invalid_response');
407
+ }
408
+ const preKPrice = numberOrNull(payload.data.preKPrice);
409
+ const name = textOrNull(payload.data.name) ?? spec.name;
410
+ let previousClose = preKPrice;
411
+ const rows = payload.data.klines.map((line) => {
412
+ const row = parseGlobalKlineRow(line, String(params.symbol), spec, name, previousClose);
413
+ previousClose = Number(row.close);
414
+ return row;
415
+ });
416
+ return { data: rows, schema: globalKlineRow };
417
+ }
418
+ function normalizeMarketMargin(params) {
419
+ assertKnown(params, ['start_date', 'end_date', 'market', 'page', 'size']);
420
+ const normalized = normalizeDateRange(params, ['start_date', 'end_date', 'market', 'page', 'size']);
421
+ const market = params.market === undefined ? 'all' : String(params.market).toLowerCase();
422
+ if (market !== 'all' && !(market in MARKET_MARGIN_FILTER))
423
+ throw new Error(`market must be one of all, ${Object.keys(MARKET_MARGIN_FILTER).join(', ')}`);
424
+ return { ...normalized, market };
425
+ }
426
+ function parseMarketMarginRow(raw) {
427
+ const tradeDate = dayValue(raw.DIM_DATE);
428
+ if (tradeDate === null)
429
+ throw sourceError('Eastmoney market margin row has invalid DIM_DATE', 'eastmoney_invalid_response');
430
+ const code = String(raw.SCDM ?? '');
431
+ const market = MARKET_MARGIN_CODE[code];
432
+ if (!market)
433
+ throw sourceError(`Eastmoney market margin row has unknown SCDM ${code || '(empty)'}`, 'eastmoney_invalid_response');
434
+ return {
435
+ trade_date: tradeDate,
436
+ trade_date_ms: dateMs(tradeDate),
437
+ market,
438
+ market_label: textOrNull(raw.XOB_MARKET_0001),
439
+ eastmoney_market_code: code,
440
+ margin_balance: numberOrNull(raw.RZYE),
441
+ short_balance: numberOrNull(raw.RQYE),
442
+ total_balance: numberOrNull(raw.RZRQYE),
443
+ margin_buy: numberOrNull(raw.RZMRE),
444
+ margin_repay: numberOrNull(raw.RZCHE),
445
+ margin_net_buy: numberOrNull(raw.RZJME),
446
+ short_balance_volume: numberOrNull(raw.RQYL),
447
+ short_sell_volume: numberOrNull(raw.RQMCL),
448
+ short_repay_volume: numberOrNull(raw.RQCHL),
449
+ short_net_buy_volume: numberOrNull(raw.RQJMG),
450
+ float_market_cap: numberOrNull(raw.LTSZ),
451
+ margin_balance_pct: numberOrNull(raw.RZYEZB),
452
+ source: 'eastmoney',
453
+ };
454
+ }
455
+ async function executeMarketMargin(params, signal) {
456
+ const marketFilter = params.market === 'all' ? '' : MARKET_MARGIN_FILTER[String(params.market)];
457
+ const url = new URL(DATACENTER_URL);
458
+ url.searchParams.set('reportName', 'RPTA_WEB_RZRQ_LSSH');
459
+ url.searchParams.set('columns', 'ALL');
460
+ url.searchParams.set('source', 'WEB');
461
+ url.searchParams.set('client', 'WEB');
462
+ url.searchParams.set('sortColumns', 'DIM_DATE');
463
+ url.searchParams.set('sortTypes', '-1');
464
+ url.searchParams.set('pageNumber', String(params.page));
465
+ url.searchParams.set('pageSize', String(params.size));
466
+ url.searchParams.set('filter', `(DIM_DATE>='${String(params.start_date)}')(DIM_DATE<='${String(params.end_date)}')${marketFilter}`);
467
+ const result = requireDatacenterResult(await getJson(url.toString(), signal, 'market margin'), 'market margin');
468
+ const parsed = requireRows(result, 'market margin');
469
+ return {
470
+ data: { item: parsed.rows.map(parseMarketMarginRow), pagination: pagination(Number(params.page), Number(params.size), parsed.pages, parsed.total) },
471
+ schema: datacenterOutput(marketMarginRow),
472
+ };
473
+ }
192
474
  function parseTopRow(raw) {
193
475
  // MARKET is free text and redundant when SECUCODE has a suffix; only require it for bare codes,
194
476
  // otherwise a whitelist rejects valid billboard pages. Keep the raw `market` field.
@@ -1071,7 +1353,8 @@ async function executeBondList(params, signal) {
1071
1353
  function createSource(options) {
1072
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 };
1073
1355
  const normalize = (params) => options.normalize(params);
1074
- return { schema, normalizeParams: normalize, validateOutput: (data) => isRecord(data) && Array.isArray(data.item) && isRecord(data.pagination), execute: async (request, signal) => options.execute(normalize(request.params), signal) };
1356
+ const validateOutput = options.validateOutput ?? ((data) => isRecord(data) && Array.isArray(data.item) && isRecord(data.pagination));
1357
+ return { schema, normalizeParams: normalize, validateOutput, execute: async (request, signal) => options.execute(normalize(request.params), signal) };
1075
1358
  }
1076
1359
  const dateRangeInput = {
1077
1360
  type: 'object', properties: { start_date: { type: 'string', description: '起始自然日 YYYY-MM-DD' }, end_date: { type: 'string', description: '截止自然日 YYYY-MM-DD' }, page: { type: 'integer', minimum: 1 }, size: { type: 'integer', minimum: 1, maximum: MAX_PAGE_SIZE } }, required: ['start_date', 'end_date'], additionalProperties: false,
@@ -1144,6 +1427,41 @@ const bondListInput = {
1144
1427
  required: ['start_date', 'end_date'],
1145
1428
  additionalProperties: false,
1146
1429
  };
1430
+ const globalQuoteInput = {
1431
+ type: 'object',
1432
+ properties: {
1433
+ symbols: {
1434
+ type: 'array', minItems: 1, maxItems: GLOBAL_SYMBOL_NAMES.length,
1435
+ items: { type: 'string', enum: GLOBAL_SYMBOL_NAMES },
1436
+ description: '稳定符号;未知符号在参数层拒绝。可用:SPX/NDX/DJIA/HSI/HSCEI/N225/SXXP/FCHI/FTSE/AS51/HSAHP/UDI/USDCNH/US10Y/US2Y/CL00Y/GC00Y/HG00Y',
1437
+ },
1438
+ },
1439
+ required: ['symbols'],
1440
+ additionalProperties: false,
1441
+ };
1442
+ const globalKlineInput = {
1443
+ type: 'object',
1444
+ properties: {
1445
+ symbol: { type: 'string', enum: GLOBAL_SYMBOL_NAMES, description: '稳定符号,与 eastmoney_global_quote 同一注册表' },
1446
+ period: { type: 'string', enum: Object.keys(GLOBAL_PERIODS), description: '默认 day;只支持日/周/月,没有分钟线' },
1447
+ start_date: { type: 'string', description: '起始自然日 YYYY-MM-DD' },
1448
+ end_date: { type: 'string', description: '截止自然日 YYYY-MM-DD' },
1449
+ },
1450
+ required: ['symbol', 'start_date', 'end_date'],
1451
+ additionalProperties: false,
1452
+ };
1453
+ const marketMarginInput = {
1454
+ type: 'object',
1455
+ properties: {
1456
+ start_date: { type: 'string', description: '起始自然日 YYYY-MM-DD' },
1457
+ end_date: { type: 'string', description: '截止自然日 YYYY-MM-DD' },
1458
+ market: { type: 'string', enum: ['all', 'sse', 'szse', 'bse'], description: '默认 all;sse 沪市 / szse 深市 / bse 北交所' },
1459
+ page: { type: 'integer', minimum: 1 },
1460
+ size: { type: 'integer', minimum: 1, maximum: MAX_PAGE_SIZE },
1461
+ },
1462
+ required: ['start_date', 'end_date'],
1463
+ additionalProperties: false,
1464
+ };
1147
1465
  export function createEastmoneySources() {
1148
1466
  return [
1149
1467
  createSource({ capability: 'eastmoney_top_buy_sell_market', name: 'get_eastmoney_top_buy_sell_market', summary: '东财全市场龙虎榜汇总', description: '按交易日区间分页获取东方财富龙虎榜上榜股票汇总。金额字段单位为元,CHANGE_RATE/TURNOVERRATE/DEAL_*_RATIO 为东财百分数原值;同一股票同日可能因多个上榜原因返回多行,不去重。上游 HTTP 200 但 success=false、code 非 0 或 result 缺失均视为失败,不转换为空数组。', inputSchema: dateRangeInput, outputSchema: datacenterOutput(topBuySellRow), paginated: true, rowShape: { rowKey: 'item' }, allowed: ['start_date', 'end_date', 'page', 'size'], normalize: (params) => normalizeDateRange(params, ['start_date', 'end_date', 'page', 'size']), execute: (params, signal) => executeBillboard(params, signal) }),
@@ -1201,5 +1519,32 @@ export function createEastmoneySources() {
1201
1519
  inputSchema: bondListInput, outputSchema: datacenterOutput(bondRow), paginated: true, rowShape: { rowKey: 'item' }, cacheMaxAgeMs: 3_600_000,
1202
1520
  allowed: ['start_date', 'end_date', 'bond_code', 'stock_code', 'page', 'size'], normalize: normalizeBondList, execute: executeBondList,
1203
1521
  }),
1522
+ createSource({
1523
+ capability: 'eastmoney_global_quote', cacheMaxAgeMs: 60_000, name: 'get_eastmoney_global_quote',
1524
+ summary: '东财全球指数/商品/汇率/美债快照',
1525
+ description: '批量获取全球指数、商品、汇率、美债收益率、美元指数与 AH 溢价的查询时点快照(东财 push2 ulist,零 key)。symbols 使用稳定符号,未知符号在参数层拒绝,不静默丢行;返回 price / change / open / high / low / prev_close / volume / amount / quote_time / quote_time_utc。⛔ 多数指数、汇率、利率的 amount 实测为 0,输出 null 而不是 0(HSI/HSCEI 例外,带港元成交额);volume 只在注册表声明可用的符号上给(股票指数为股数、商品为合约张数、汇率/利率为 null)。⛔ VIX / SOX / RUT / DAX / HSTECH / USDJPY 实测无数据,不在承诺范围;免费公开源不承诺实时,is_delayed 留 null。f124=0 时 quote_time 为 null;部分符号未回时逐行 available=false + reason=symbol_not_returned。',
1526
+ inputSchema: globalQuoteInput,
1527
+ outputSchema: { type: 'array', items: globalQuoteRow },
1528
+ paginated: false, rowShape: { rootArray: true },
1529
+ allowed: ['symbols'], normalize: normalizeGlobalSymbols, validateOutput: (data) => Array.isArray(data), execute: executeGlobalQuote,
1530
+ }),
1531
+ createSource({
1532
+ capability: 'eastmoney_global_kline', cacheMaxAgeMs: 60_000, name: 'get_eastmoney_global_kline',
1533
+ summary: '东财全球指数/商品/汇率/美债日周月 K 线',
1534
+ description: '按稳定符号与日期区间获取全球指数、商品、汇率、美债收益率与 AH 溢价的日/周/月 K 线(东财 push2his,零 key)。⛔ 上游第 8 列是振幅 amplitude_pct,不是涨跌幅;change_pct 由前收计算,首根用 preKPrice,preKPrice=0 时首根为 null。指数、汇率、利率的 amount 实测为 0,输出 null;HSI/HSCEI 的 amount 是港元成交额,其余 amount_unit=null。volume 只在注册表声明可用的符号上给。没有分钟线;HSTECH / DAX / VIX 等无数据,不在承诺范围。空区间返回 [],不是取数失败。',
1535
+ inputSchema: globalKlineInput,
1536
+ outputSchema: { type: 'array', items: globalKlineRow },
1537
+ paginated: false, rowShape: { rootArray: true },
1538
+ allowed: ['symbol', 'period', 'start_date', 'end_date'], normalize: normalizeGlobalKline, validateOutput: (data) => Array.isArray(data), execute: executeGlobalKline,
1539
+ }),
1540
+ createSource({
1541
+ capability: 'eastmoney_margin_total', name: 'get_eastmoney_margin_total',
1542
+ summary: '东财市场级两融合计(按交易所日频)',
1543
+ description: '按交易日区间与市场获取 A 股市场级两融汇总(RPTA_WEB_RZRQ_LSSH,实测 8,983 行、2010-03 起)。金额字段单位为元:margin_balance 融资余额、short_balance 融券余额、total_balance 两融合计、margin_buy 融资买入、margin_repay 融资偿还、margin_net_buy 融资净买入;融券量为股数,不能与金额相加。⛔ 深市/北交所披露 T+1:实测同一日期可能只有沪市有行,不能把不完整日期加总;按 market 取单市场或 all 原样返回,缺哪个市场由行本身表达。market 枚举 sse/szse/bse;market_label 是上游原文(融资融券_沪证 / 深证 / 京证)。',
1544
+ inputSchema: marketMarginInput,
1545
+ outputSchema: datacenterOutput(marketMarginRow),
1546
+ paginated: true, rowShape: { rowKey: 'item' },
1547
+ allowed: ['start_date', 'end_date', 'market', 'page', 'size'], normalize: normalizeMarketMargin, execute: executeMarketMargin,
1548
+ }),
1204
1549
  ];
1205
1550
  }