@v587d/capital-generation 2.29.0 → 2.30.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 +3 -3
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/collector-runtime.js +56 -1
- package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
- package/lib/data-collector/catalog-taxonomy.js +33 -0
- package/lib/data-collector/dataset-tools.js +4 -2
- package/lib/data-collector/describe.d.ts +2 -0
- package/lib/data-collector/describe.js +2 -0
- package/lib/data-collector/store.d.ts +11 -0
- package/lib/data-collector/store.js +80 -1
- package/lib/data-collector/tools.d.ts +1 -1
- package/lib/data-collector/tools.js +10 -9
- package/lib/python-runtime/errors.d.ts +1 -1
- package/lib/python-runtime/errors.js +2 -0
- package/lib/python-runtime/manager.d.ts +28 -1
- package/lib/python-runtime/manager.js +141 -5
- package/lib/python-runtime/probe.d.ts +24 -0
- package/lib/python-runtime/probe.js +66 -50
- package/lib/sources/csindex-http.d.ts +4 -0
- package/lib/sources/csindex-http.js +233 -0
- package/lib/sources/eastmoney-http.js +1504 -1
- package/lib/sources/fuyao-rest.js +168 -8
- package/lib/sources/official-http.d.ts +4 -0
- package/lib/sources/official-http.js +477 -0
- package/lib/sources/python-remote.d.ts +25 -0
- package/lib/sources/python-remote.js +461 -0
- package/lib/sources/sina-http.d.ts +2 -0
- package/lib/sources/sina-http.js +484 -0
- package/lib/sources/tencent-http.js +23 -8
- package/lib/sources/ths-http.d.ts +2 -0
- package/lib/sources/ths-http.js +517 -0
- package/lib/time/tools.js +19 -0
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/sources.d.ts +7 -0
- package/lib/web-retriever/sources.js +46 -21
- package/lib/web-retriever/throttle.d.ts +8 -0
- package/lib/web-retriever/throttle.js +13 -0
- package/lib/web-retriever/tools.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/preset/capital-generation/agent.patch.yml +7 -5
- package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
- package/python/scripts/baostock_stock_basic.py +129 -0
- package/python/scripts/baostock_valuation_history.py +141 -0
- package/python/scripts/pbc_social_financing.py +291 -0
- package/python/vendor/baostock/LICENSE +19 -0
- package/python/vendor/baostock/__init__.py +42 -0
- package/python/vendor/baostock/common/__init__.py +0 -0
- package/python/vendor/baostock/common/contants.py +189 -0
- package/python/vendor/baostock/common/context.py +4 -0
- package/python/vendor/baostock/corpreport/__init__.py +0 -0
- package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
- package/python/vendor/baostock/data/__init__.py +0 -0
- package/python/vendor/baostock/data/messageheader.py +17 -0
- package/python/vendor/baostock/data/msg.py +21 -0
- package/python/vendor/baostock/data/resultset.py +200 -0
- package/python/vendor/baostock/demo/__init__.py +0 -0
- package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
- package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
- package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
- package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
- package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
- package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
- package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
- package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
- package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
- package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
- package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
- package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
- package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
- package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
- package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
- package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
- package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
- package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
- package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
- package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
- package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
- package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
- package/python/vendor/baostock/evaluation/__init__.py +0 -0
- package/python/vendor/baostock/evaluation/season_index.py +758 -0
- package/python/vendor/baostock/login/__init__.py +0 -0
- package/python/vendor/baostock/login/loginout.py +230 -0
- package/python/vendor/baostock/macroscopic/__init__.py +0 -0
- package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
- package/python/vendor/baostock/metadata/__init__.py +0 -0
- package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
- package/python/vendor/baostock/security/__init__.py +0 -0
- package/python/vendor/baostock/security/history.py +265 -0
- package/python/vendor/baostock/security/sectorinfo.py +1024 -0
- package/python/vendor/baostock/util/__init__.py +0 -0
- package/python/vendor/baostock/util/socketutil.py +97 -0
- package/python/vendor/baostock/util/stringutil.py +83 -0
- package/python/vendor/et_xmlfile/LICENSE +23 -0
- package/python/vendor/et_xmlfile/LICENSE.python +298 -0
- package/python/vendor/et_xmlfile/__init__.py +8 -0
- package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
- package/python/vendor/et_xmlfile/xmlfile.py +158 -0
- package/python/vendor/openpyxl/LICENSE +23 -0
- package/python/vendor/openpyxl/__init__.py +19 -0
- package/python/vendor/openpyxl/_constants.py +13 -0
- package/python/vendor/openpyxl/cell/__init__.py +4 -0
- package/python/vendor/openpyxl/cell/_writer.py +136 -0
- package/python/vendor/openpyxl/cell/cell.py +332 -0
- package/python/vendor/openpyxl/cell/read_only.py +136 -0
- package/python/vendor/openpyxl/cell/rich_text.py +202 -0
- package/python/vendor/openpyxl/cell/text.py +184 -0
- package/python/vendor/openpyxl/chart/_3d.py +105 -0
- package/python/vendor/openpyxl/chart/__init__.py +19 -0
- package/python/vendor/openpyxl/chart/_chart.py +199 -0
- package/python/vendor/openpyxl/chart/area_chart.py +106 -0
- package/python/vendor/openpyxl/chart/axis.py +401 -0
- package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
- package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
- package/python/vendor/openpyxl/chart/chartspace.py +195 -0
- package/python/vendor/openpyxl/chart/data_source.py +246 -0
- package/python/vendor/openpyxl/chart/descriptors.py +43 -0
- package/python/vendor/openpyxl/chart/error_bar.py +62 -0
- package/python/vendor/openpyxl/chart/label.py +127 -0
- package/python/vendor/openpyxl/chart/layout.py +74 -0
- package/python/vendor/openpyxl/chart/legend.py +75 -0
- package/python/vendor/openpyxl/chart/line_chart.py +129 -0
- package/python/vendor/openpyxl/chart/marker.py +90 -0
- package/python/vendor/openpyxl/chart/picture.py +35 -0
- package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
- package/python/vendor/openpyxl/chart/pivot.py +65 -0
- package/python/vendor/openpyxl/chart/plotarea.py +162 -0
- package/python/vendor/openpyxl/chart/print_settings.py +57 -0
- package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
- package/python/vendor/openpyxl/chart/reader.py +32 -0
- package/python/vendor/openpyxl/chart/reference.py +124 -0
- package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
- package/python/vendor/openpyxl/chart/series.py +197 -0
- package/python/vendor/openpyxl/chart/series_factory.py +41 -0
- package/python/vendor/openpyxl/chart/shapes.py +89 -0
- package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
- package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
- package/python/vendor/openpyxl/chart/text.py +78 -0
- package/python/vendor/openpyxl/chart/title.py +76 -0
- package/python/vendor/openpyxl/chart/trendline.py +98 -0
- package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
- package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
- package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
- package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
- package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
- package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
- package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
- package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
- package/python/vendor/openpyxl/chartsheet/views.py +51 -0
- package/python/vendor/openpyxl/comments/__init__.py +4 -0
- package/python/vendor/openpyxl/comments/author.py +21 -0
- package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
- package/python/vendor/openpyxl/comments/comments.py +62 -0
- package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
- package/python/vendor/openpyxl/compat/__init__.py +54 -0
- package/python/vendor/openpyxl/compat/abc.py +8 -0
- package/python/vendor/openpyxl/compat/numbers.py +43 -0
- package/python/vendor/openpyxl/compat/product.py +17 -0
- package/python/vendor/openpyxl/compat/singleton.py +40 -0
- package/python/vendor/openpyxl/compat/strings.py +25 -0
- package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
- package/python/vendor/openpyxl/descriptors/base.py +272 -0
- package/python/vendor/openpyxl/descriptors/container.py +41 -0
- package/python/vendor/openpyxl/descriptors/excel.py +112 -0
- package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
- package/python/vendor/openpyxl/descriptors/nested.py +129 -0
- package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
- package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
- package/python/vendor/openpyxl/descriptors/slots.py +18 -0
- package/python/vendor/openpyxl/drawing/__init__.py +4 -0
- package/python/vendor/openpyxl/drawing/colors.py +435 -0
- package/python/vendor/openpyxl/drawing/connector.py +144 -0
- package/python/vendor/openpyxl/drawing/drawing.py +92 -0
- package/python/vendor/openpyxl/drawing/effect.py +407 -0
- package/python/vendor/openpyxl/drawing/fill.py +425 -0
- package/python/vendor/openpyxl/drawing/geometry.py +584 -0
- package/python/vendor/openpyxl/drawing/graphic.py +177 -0
- package/python/vendor/openpyxl/drawing/image.py +65 -0
- package/python/vendor/openpyxl/drawing/line.py +144 -0
- package/python/vendor/openpyxl/drawing/picture.py +144 -0
- package/python/vendor/openpyxl/drawing/properties.py +174 -0
- package/python/vendor/openpyxl/drawing/relation.py +17 -0
- package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
- package/python/vendor/openpyxl/drawing/text.py +717 -0
- package/python/vendor/openpyxl/drawing/xdr.py +33 -0
- package/python/vendor/openpyxl/formatting/__init__.py +3 -0
- package/python/vendor/openpyxl/formatting/formatting.py +114 -0
- package/python/vendor/openpyxl/formatting/rule.py +291 -0
- package/python/vendor/openpyxl/formula/__init__.py +3 -0
- package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
- package/python/vendor/openpyxl/formula/translate.py +166 -0
- package/python/vendor/openpyxl/packaging/__init__.py +3 -0
- package/python/vendor/openpyxl/packaging/core.py +115 -0
- package/python/vendor/openpyxl/packaging/custom.py +289 -0
- package/python/vendor/openpyxl/packaging/extended.py +137 -0
- package/python/vendor/openpyxl/packaging/interface.py +56 -0
- package/python/vendor/openpyxl/packaging/manifest.py +194 -0
- package/python/vendor/openpyxl/packaging/relationship.py +158 -0
- package/python/vendor/openpyxl/packaging/workbook.py +185 -0
- package/python/vendor/openpyxl/pivot/__init__.py +1 -0
- package/python/vendor/openpyxl/pivot/cache.py +965 -0
- package/python/vendor/openpyxl/pivot/fields.py +326 -0
- package/python/vendor/openpyxl/pivot/record.py +111 -0
- package/python/vendor/openpyxl/pivot/table.py +1261 -0
- package/python/vendor/openpyxl/reader/__init__.py +1 -0
- package/python/vendor/openpyxl/reader/drawings.py +71 -0
- package/python/vendor/openpyxl/reader/excel.py +349 -0
- package/python/vendor/openpyxl/reader/strings.py +44 -0
- package/python/vendor/openpyxl/reader/workbook.py +133 -0
- package/python/vendor/openpyxl/styles/__init__.py +11 -0
- package/python/vendor/openpyxl/styles/alignment.py +62 -0
- package/python/vendor/openpyxl/styles/borders.py +103 -0
- package/python/vendor/openpyxl/styles/builtins.py +1397 -0
- package/python/vendor/openpyxl/styles/cell_style.py +206 -0
- package/python/vendor/openpyxl/styles/colors.py +172 -0
- package/python/vendor/openpyxl/styles/differential.py +95 -0
- package/python/vendor/openpyxl/styles/fills.py +224 -0
- package/python/vendor/openpyxl/styles/fonts.py +113 -0
- package/python/vendor/openpyxl/styles/named_styles.py +282 -0
- package/python/vendor/openpyxl/styles/numbers.py +200 -0
- package/python/vendor/openpyxl/styles/protection.py +17 -0
- package/python/vendor/openpyxl/styles/proxy.py +62 -0
- package/python/vendor/openpyxl/styles/styleable.py +151 -0
- package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
- package/python/vendor/openpyxl/styles/table.py +94 -0
- package/python/vendor/openpyxl/utils/__init__.py +17 -0
- package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
- package/python/vendor/openpyxl/utils/cell.py +240 -0
- package/python/vendor/openpyxl/utils/dataframe.py +87 -0
- package/python/vendor/openpyxl/utils/datetime.py +140 -0
- package/python/vendor/openpyxl/utils/escape.py +43 -0
- package/python/vendor/openpyxl/utils/exceptions.py +34 -0
- package/python/vendor/openpyxl/utils/formulas.py +24 -0
- package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
- package/python/vendor/openpyxl/utils/inference.py +60 -0
- package/python/vendor/openpyxl/utils/protection.py +22 -0
- package/python/vendor/openpyxl/utils/units.py +108 -0
- package/python/vendor/openpyxl/workbook/__init__.py +4 -0
- package/python/vendor/openpyxl/workbook/_writer.py +197 -0
- package/python/vendor/openpyxl/workbook/child.py +166 -0
- package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
- package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
- package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
- package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
- package/python/vendor/openpyxl/workbook/function_group.py +36 -0
- package/python/vendor/openpyxl/workbook/properties.py +151 -0
- package/python/vendor/openpyxl/workbook/protection.py +163 -0
- package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
- package/python/vendor/openpyxl/workbook/views.py +155 -0
- package/python/vendor/openpyxl/workbook/web.py +98 -0
- package/python/vendor/openpyxl/workbook/workbook.py +438 -0
- package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
- package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
- package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
- package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
- package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
- package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
- package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
- package/python/vendor/openpyxl/worksheet/controls.py +107 -0
- package/python/vendor/openpyxl/worksheet/copier.py +70 -0
- package/python/vendor/openpyxl/worksheet/custom.py +35 -0
- package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
- package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
- package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
- package/python/vendor/openpyxl/worksheet/errors.py +93 -0
- package/python/vendor/openpyxl/worksheet/filters.py +486 -0
- package/python/vendor/openpyxl/worksheet/formula.py +51 -0
- package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
- package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
- package/python/vendor/openpyxl/worksheet/merge.py +141 -0
- package/python/vendor/openpyxl/worksheet/ole.py +133 -0
- package/python/vendor/openpyxl/worksheet/page.py +174 -0
- package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
- package/python/vendor/openpyxl/worksheet/picture.py +8 -0
- package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
- package/python/vendor/openpyxl/worksheet/properties.py +97 -0
- package/python/vendor/openpyxl/worksheet/protection.py +120 -0
- package/python/vendor/openpyxl/worksheet/related.py +17 -0
- package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
- package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
- package/python/vendor/openpyxl/worksheet/table.py +385 -0
- package/python/vendor/openpyxl/worksheet/views.py +155 -0
- package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
- package/python/vendor/openpyxl/writer/__init__.py +1 -0
- package/python/vendor/openpyxl/writer/excel.py +295 -0
- package/python/vendor/openpyxl/writer/theme.py +291 -0
- package/python/vendor/openpyxl/xml/__init__.py +42 -0
- package/python/vendor/openpyxl/xml/constants.py +129 -0
- package/python/vendor/openpyxl/xml/functions.py +87 -0
- package/watchlist/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildDataKey } from '../data-collector/hub.js';
|
|
2
2
|
import { getDataTimeContract } from '../time/tools.js';
|
|
3
|
-
import { sharedEastmoneyClient, EastmoneyTransportError } from '../net/eastmoney-client.js';
|
|
3
|
+
import { sharedEastmoneyClient, sharedEastmoneyThrottle, EastmoneyTransportError } from '../net/eastmoney-client.js';
|
|
4
4
|
import { normalizeEastmoneyAshareIdentity, normalizeEastmoneyBoardIdentity, normalizeEastmoneySecurityIdentity } from './security-identity.js';
|
|
5
5
|
const DATACENTER_URL = 'https://datacenter-web.eastmoney.com/api/data/v1/get';
|
|
6
6
|
const CLIST_URL = 'https://push2.eastmoney.com/api/qt/clist/get';
|
|
@@ -1462,6 +1462,656 @@ const marketMarginInput = {
|
|
|
1462
1462
|
required: ['start_date', 'end_date'],
|
|
1463
1463
|
additionalProperties: false,
|
|
1464
1464
|
};
|
|
1465
|
+
const PROFILING_URL = 'https://push2.eastmoney.com/api/qt/stock/get';
|
|
1466
|
+
/**
|
|
1467
|
+
* push2 secid market digit: SH is `1`, SZ and BJ share `0`. 5x ETFs/LOFs, 588x STAR ETFs and 900x
|
|
1468
|
+
* SH B-shares are SH — a `6`-prefix guess routes them to `0.` and upstream answers `data: null`.
|
|
1469
|
+
* 92x (BSE since 2024-10) must be tested before 9x. Never derive a market from one leading digit.
|
|
1470
|
+
*/
|
|
1471
|
+
function eastmoneySecidMarketId(digits) {
|
|
1472
|
+
if (/^92/u.test(digits))
|
|
1473
|
+
return '0';
|
|
1474
|
+
return /^[569]/u.test(digits) ? '1' : '0';
|
|
1475
|
+
}
|
|
1476
|
+
/** A-share market implied by the secid rule: SH when the market digit is 1, else BJ on 4x/8x/92x. */
|
|
1477
|
+
function eastmoneyAshareMarket(digits) {
|
|
1478
|
+
if (eastmoneySecidMarketId(digits) === '1')
|
|
1479
|
+
return 'SH';
|
|
1480
|
+
return /^(?:4|8|92)/u.test(digits) ? 'BJ' : 'SZ';
|
|
1481
|
+
}
|
|
1482
|
+
const TICKER_FORM = /^(?:(\d{6})(?:\.(SH|SZ|BJ))?|(SH|SZ|BJ)(\d{6}))$/u;
|
|
1483
|
+
/**
|
|
1484
|
+
* Canonical `600519.SH` for stock-keyed capabilities. A bare code reads as the A-share of that
|
|
1485
|
+
* number (`000001` = 平安银行, not 上证指数); an explicit market that disagrees with the A-share
|
|
1486
|
+
* prefix is rejected rather than rewritten, so `000001.SH` cannot silently become 平安银行 rows.
|
|
1487
|
+
*/
|
|
1488
|
+
function ashareThscode(value, name = 'ticker') {
|
|
1489
|
+
if (typeof value !== 'string')
|
|
1490
|
+
throw new Error(`${name} must be a string`);
|
|
1491
|
+
const match = TICKER_FORM.exec(value.trim().toUpperCase());
|
|
1492
|
+
if (!match)
|
|
1493
|
+
throw new Error(`${name} must be a six-digit A-share code, optionally with a market suffix (e.g. 600519 or 600519.SH)`);
|
|
1494
|
+
const digits = String(match[1] ?? match[4]);
|
|
1495
|
+
const derived = eastmoneyAshareMarket(digits);
|
|
1496
|
+
const declared = (match[2] ?? match[3]);
|
|
1497
|
+
if (declared !== undefined && declared !== derived) {
|
|
1498
|
+
throw new Error(`${name} market ${declared} conflicts with the A-share code prefix (resolved ${derived}); index/ETF-style codes are not accepted`);
|
|
1499
|
+
}
|
|
1500
|
+
return `${digits}.${derived}`;
|
|
1501
|
+
}
|
|
1502
|
+
/** Upstream `20010827`-style compact date; invalid or empty becomes null, never a 1970 timestamp. */
|
|
1503
|
+
function compactDay(value) {
|
|
1504
|
+
const text = String(value ?? '').trim();
|
|
1505
|
+
if (!/^\d{8}$/u.test(text))
|
|
1506
|
+
return null;
|
|
1507
|
+
const day = `${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}`;
|
|
1508
|
+
const parsed = new Date(`${day}T00:00:00Z`);
|
|
1509
|
+
return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0, 10) === day ? day : null;
|
|
1510
|
+
}
|
|
1511
|
+
const profileRow = {
|
|
1512
|
+
type: 'object',
|
|
1513
|
+
properties: {
|
|
1514
|
+
thscode: { type: 'string' }, ticker: { type: 'string' }, name: { type: 'string' },
|
|
1515
|
+
market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] }, eastmoney_secid: { type: 'string' },
|
|
1516
|
+
industry: nullableString,
|
|
1517
|
+
total_shares: nullableNumber, float_shares: nullableNumber,
|
|
1518
|
+
total_market_cap: nullableNumber, float_market_cap: nullableNumber,
|
|
1519
|
+
list_date: nullableString, list_date_ms: { oneOf: [{ type: 'integer' }, { type: 'null' }] },
|
|
1520
|
+
pe_dynamic: nullableNumber, pb: nullableNumber,
|
|
1521
|
+
},
|
|
1522
|
+
required: ['thscode', 'ticker', 'name', 'market', 'eastmoney_secid', 'industry', 'total_shares', 'float_shares', 'total_market_cap', 'float_market_cap', 'list_date', 'list_date_ms', 'pe_dynamic', 'pb'],
|
|
1523
|
+
additionalProperties: false,
|
|
1524
|
+
};
|
|
1525
|
+
const profileInput = {
|
|
1526
|
+
type: 'object',
|
|
1527
|
+
properties: {
|
|
1528
|
+
ticker: { type: 'string', description: '六位代码或带市场后缀(600519 / 600519.SH / sh600519);裸代码按 A 股个股解析(000001 = 平安银行,不是上证指数),指数/ETF 不接受' },
|
|
1529
|
+
},
|
|
1530
|
+
required: ['ticker'],
|
|
1531
|
+
additionalProperties: false,
|
|
1532
|
+
};
|
|
1533
|
+
function normalizeProfile(params) {
|
|
1534
|
+
assertKnown(params, ['ticker']);
|
|
1535
|
+
return { ticker: ashareThscode(params.ticker) };
|
|
1536
|
+
}
|
|
1537
|
+
function parseProfileRow(data, thscode) {
|
|
1538
|
+
const [digits, market] = thscode.split('.');
|
|
1539
|
+
if (String(data.f57 ?? '') !== digits || typeof data.f58 !== 'string' || data.f58.trim().length === 0) {
|
|
1540
|
+
throw sourceError(`Eastmoney profile response does not match ${thscode}`, 'eastmoney_invalid_response');
|
|
1541
|
+
}
|
|
1542
|
+
const totalShares = numberOrNull(data.f84);
|
|
1543
|
+
// Indexes/funds answer with a code and name but no share capital; reporting them as a "stock
|
|
1544
|
+
// profile" would hand back a row of nulls.
|
|
1545
|
+
if (totalShares === null || totalShares <= 0) {
|
|
1546
|
+
throw sourceError(`Eastmoney profile for ${thscode} has no share capital (indexes and funds are out of scope)`, 'eastmoney_invalid_ticker');
|
|
1547
|
+
}
|
|
1548
|
+
const listDate = compactDay(data.f189);
|
|
1549
|
+
return {
|
|
1550
|
+
thscode, ticker: digits, name: data.f58.trim(), market, eastmoney_secid: `${eastmoneySecidMarketId(digits)}.${digits}`,
|
|
1551
|
+
industry: textOrNull(data.f127),
|
|
1552
|
+
total_shares: totalShares,
|
|
1553
|
+
float_shares: numberOrNull(data.f85),
|
|
1554
|
+
total_market_cap: numberOrNull(data.f116),
|
|
1555
|
+
float_market_cap: numberOrNull(data.f117),
|
|
1556
|
+
list_date: listDate,
|
|
1557
|
+
list_date_ms: listDate === null ? null : dateMs(listDate),
|
|
1558
|
+
// f162 = 市盈率(动态) and f167 = 市净率: verified against datacenter PE_DYNAMIC 21.6075 and
|
|
1559
|
+
// price / BPS (1485.75 / 216.9496 = 6.848) for 600519 on 2026-11-20. f9/f23 are not returned here.
|
|
1560
|
+
pe_dynamic: numberOrNull(data.f162),
|
|
1561
|
+
pb: numberOrNull(data.f167),
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
async function executeProfile(params, signal) {
|
|
1565
|
+
const thscode = String(params.ticker);
|
|
1566
|
+
const digits = thscode.slice(0, 6);
|
|
1567
|
+
const url = new URL(PROFILING_URL);
|
|
1568
|
+
url.searchParams.set('fltt', '2');
|
|
1569
|
+
url.searchParams.set('invt', '2');
|
|
1570
|
+
url.searchParams.set('secid', `${eastmoneySecidMarketId(digits)}.${digits}`);
|
|
1571
|
+
url.searchParams.set('fields', 'f57,f58,f84,f85,f116,f117,f127,f162,f167,f189');
|
|
1572
|
+
const payload = await getJson(url.toString(), signal, `security profile ${thscode}`);
|
|
1573
|
+
if (Number(payload.rc) !== 0)
|
|
1574
|
+
throw sourceError(`Eastmoney profile failed for ${thscode}: rc ${String(payload.rc)}`, 'eastmoney_upstream_error');
|
|
1575
|
+
if (payload.data === null || payload.data === undefined) {
|
|
1576
|
+
throw sourceError(`Eastmoney profile returned no data for ${thscode} (unknown code or wrong secid market)`, 'eastmoney_invalid_ticker');
|
|
1577
|
+
}
|
|
1578
|
+
if (!isRecord(payload.data))
|
|
1579
|
+
throw sourceError('Eastmoney profile returned a non-object data', 'eastmoney_invalid_response');
|
|
1580
|
+
return { data: { item: [parseProfileRow(payload.data, thscode)], pagination: pagination(1, 1, 1, 1) }, schema: datacenterOutput(profileRow) };
|
|
1581
|
+
}
|
|
1582
|
+
const ST_MARKETS = ['sh', 'sz', 'bj'];
|
|
1583
|
+
/** Eastmoney risk-warning board: `m:1` SH, `m:0` SZ — the SZ arm also returns BSE codes (see execute). */
|
|
1584
|
+
const ST_RISK_BOARD_FS = { sh: 'm:1+f:4', sz: 'm:0+f:4' };
|
|
1585
|
+
/** BSE full A-share list; BSE ST names must be filtered by name, not by the risk-warning flag. */
|
|
1586
|
+
const ST_BSE_FS = 'm:0+t:81+s:2048';
|
|
1587
|
+
const ST_CLIST_FIELDS = 'f12,f13,f14,f2,f3,f4,f5,f6,f7,f8';
|
|
1588
|
+
const ST_PAGE_SIZE = 100;
|
|
1589
|
+
const ST_MAX_PAGES = 30;
|
|
1590
|
+
const stStockRow = {
|
|
1591
|
+
type: 'object',
|
|
1592
|
+
properties: {
|
|
1593
|
+
code: { type: 'string' }, name: { type: 'string' }, market: { type: 'string', enum: ['sh', 'sz', 'bj'] },
|
|
1594
|
+
share_type: { type: 'string', enum: ['a_share', 'b_share'] }, st_type: { type: 'string', enum: ['ST', '*ST'] },
|
|
1595
|
+
price: nullableNumber, change_pct: nullableNumber, change_amount: nullableNumber,
|
|
1596
|
+
volume: nullableNumber, amount: nullableNumber, amplitude_pct: nullableNumber, turnover_pct: nullableNumber,
|
|
1597
|
+
},
|
|
1598
|
+
required: ['code', 'name', 'market', 'share_type', 'st_type', 'price', 'change_pct', 'change_amount', 'volume', 'amount', 'amplitude_pct', 'turnover_pct'],
|
|
1599
|
+
additionalProperties: false,
|
|
1600
|
+
};
|
|
1601
|
+
const stStockListInput = {
|
|
1602
|
+
type: 'object',
|
|
1603
|
+
properties: {
|
|
1604
|
+
market: { type: 'string', enum: ['all', 'sh', 'sz', 'bj'], description: '默认 all;按市场分别取沪风险警示板 / 深风险警示板 / 北交所全表名称筛' },
|
|
1605
|
+
},
|
|
1606
|
+
required: [],
|
|
1607
|
+
additionalProperties: false,
|
|
1608
|
+
};
|
|
1609
|
+
const stStockListOutput = {
|
|
1610
|
+
type: 'object',
|
|
1611
|
+
properties: {
|
|
1612
|
+
item: { type: 'array', items: stStockRow },
|
|
1613
|
+
total: { type: 'integer' },
|
|
1614
|
+
markets: { type: 'array', items: { type: 'string', enum: [...ST_MARKETS] } },
|
|
1615
|
+
by_market: {
|
|
1616
|
+
type: 'object',
|
|
1617
|
+
properties: { sh: { type: 'integer' }, sz: { type: 'integer' }, bj: { type: 'integer' } },
|
|
1618
|
+
required: ['sh', 'sz', 'bj'], additionalProperties: false,
|
|
1619
|
+
},
|
|
1620
|
+
},
|
|
1621
|
+
required: ['item', 'total', 'markets', 'by_market'],
|
|
1622
|
+
additionalProperties: false,
|
|
1623
|
+
};
|
|
1624
|
+
function normalizeStStockList(params) {
|
|
1625
|
+
assertKnown(params, ['market']);
|
|
1626
|
+
const market = params.market === undefined ? 'all' : String(params.market).toLowerCase();
|
|
1627
|
+
if (market !== 'all' && !ST_MARKETS.includes(market))
|
|
1628
|
+
throw new Error(`market must be one of all, ${ST_MARKETS.join(', ')}`);
|
|
1629
|
+
return { market };
|
|
1630
|
+
}
|
|
1631
|
+
/** `f12`-only classification: BSE legacy 4x/8x and 920x, SH 5x/6x/9x, everything else SZ. */
|
|
1632
|
+
function stMarketOf(code) {
|
|
1633
|
+
if (/^(?:4|8|92)/u.test(code))
|
|
1634
|
+
return 'bj';
|
|
1635
|
+
if (/^[569]/u.test(code))
|
|
1636
|
+
return 'sh';
|
|
1637
|
+
return 'sz';
|
|
1638
|
+
}
|
|
1639
|
+
async function fetchCListAll(fs, signal, context) {
|
|
1640
|
+
const rows = [];
|
|
1641
|
+
let total = null;
|
|
1642
|
+
for (let page = 1; page <= ST_MAX_PAGES; page += 1) {
|
|
1643
|
+
const url = new URL(CLIST_URL);
|
|
1644
|
+
url.searchParams.set('pn', String(page));
|
|
1645
|
+
url.searchParams.set('pz', String(ST_PAGE_SIZE));
|
|
1646
|
+
url.searchParams.set('po', '1');
|
|
1647
|
+
url.searchParams.set('np', '1');
|
|
1648
|
+
url.searchParams.set('ut', EASTMONEY_UT);
|
|
1649
|
+
url.searchParams.set('fltt', '2');
|
|
1650
|
+
url.searchParams.set('invt', '2');
|
|
1651
|
+
url.searchParams.set('fid', 'f12');
|
|
1652
|
+
url.searchParams.set('fs', fs);
|
|
1653
|
+
url.searchParams.set('fields', ST_CLIST_FIELDS);
|
|
1654
|
+
const data = requireCList(await getJson(url.toString(), signal, context), context);
|
|
1655
|
+
if (!Array.isArray(data.diff) || typeof data.total !== 'number' || !data.diff.every(isRecord))
|
|
1656
|
+
throw sourceError(`Eastmoney ${context} result shape changed`, 'eastmoney_invalid_response');
|
|
1657
|
+
// A list that changes between pages would mix two snapshots; fail instead of returning a blend.
|
|
1658
|
+
if (total !== null && data.total !== total)
|
|
1659
|
+
throw sourceError(`Eastmoney ${context} total changed from ${total} to ${data.total} while paging; retry`, 'eastmoney_invalid_response');
|
|
1660
|
+
total = data.total;
|
|
1661
|
+
rows.push(...data.diff);
|
|
1662
|
+
if (rows.length >= total || data.diff.length === 0)
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
if (total === null)
|
|
1666
|
+
throw sourceError(`Eastmoney ${context} returned no total`, 'eastmoney_invalid_response');
|
|
1667
|
+
if (rows.length !== total)
|
|
1668
|
+
throw sourceError(`Eastmoney ${context} returned ${rows.length} of ${total} rows`, 'eastmoney_invalid_response');
|
|
1669
|
+
return rows;
|
|
1670
|
+
}
|
|
1671
|
+
function parseStStockRow(raw, market) {
|
|
1672
|
+
const code = String(raw.f12 ?? '');
|
|
1673
|
+
const name = String(raw.f14 ?? '').trim();
|
|
1674
|
+
if (!/^\d{6}$/u.test(code) || name.length === 0)
|
|
1675
|
+
throw sourceError('Eastmoney risk-warning row has an unusable code or name', 'eastmoney_invalid_response');
|
|
1676
|
+
// Every SH/SZ risk-warning row must carry the ST marker; a missing one means the flag changed.
|
|
1677
|
+
if (!/ST/iu.test(name))
|
|
1678
|
+
throw sourceError(`Eastmoney risk-warning row ${code} has no ST marker in its name (${name})`, 'eastmoney_invalid_response');
|
|
1679
|
+
return {
|
|
1680
|
+
code, name, market, share_type: /^(?:2|9)/u.test(code) ? 'b_share' : 'a_share',
|
|
1681
|
+
st_type: name.startsWith('*') ? '*ST' : 'ST',
|
|
1682
|
+
// Suspended/halted rows ship `-` in the quote columns; numberOrNull keeps them null, never 0.
|
|
1683
|
+
price: numberOrNull(raw.f2),
|
|
1684
|
+
change_pct: numberOrNull(raw.f3),
|
|
1685
|
+
change_amount: numberOrNull(raw.f4),
|
|
1686
|
+
volume: numberOrNull(raw.f5),
|
|
1687
|
+
amount: numberOrNull(raw.f6),
|
|
1688
|
+
amplitude_pct: numberOrNull(raw.f7),
|
|
1689
|
+
turnover_pct: numberOrNull(raw.f8),
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
async function executeStStockList(params, signal) {
|
|
1693
|
+
const requested = String(params.market);
|
|
1694
|
+
const markets = requested === 'all' ? [...ST_MARKETS] : [requested];
|
|
1695
|
+
const rows = [];
|
|
1696
|
+
for (const market of markets) {
|
|
1697
|
+
if (market === 'bj') {
|
|
1698
|
+
const list = await fetchCListAll(ST_BSE_FS, signal, 'BSE full list');
|
|
1699
|
+
// An empty BSE list would turn "no data" into "no ST on BSE"; the name filter needs the list.
|
|
1700
|
+
if (list.length === 0)
|
|
1701
|
+
throw sourceError('Eastmoney BSE full list is empty; refusing to report "no ST on BSE"', 'eastmoney_invalid_response');
|
|
1702
|
+
for (const raw of list)
|
|
1703
|
+
if (/ST/iu.test(String(raw.f14 ?? '')))
|
|
1704
|
+
rows.push(parseStStockRow(raw, 'bj'));
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
const board = await fetchCListAll(ST_RISK_BOARD_FS[market], signal, `${market === 'sh' ? 'SH' : 'SZ'} risk-warning board`);
|
|
1708
|
+
// Always non-empty in practice: an empty board is an upstream break, not "no ST stocks today".
|
|
1709
|
+
if (board.length === 0)
|
|
1710
|
+
throw sourceError(`Eastmoney ${market} risk-warning board returned no rows; refusing to call it an empty ST list`, 'eastmoney_invalid_response');
|
|
1711
|
+
for (const raw of board) {
|
|
1712
|
+
const code = String(raw.f12 ?? '');
|
|
1713
|
+
// Verified 2026-11-22: the m:0 board carries 189 BSE codes (186 legacy 430x/83x/87x that are no
|
|
1714
|
+
// longer in the BSE list). They belong to the BSE arm, which filters the current list by name.
|
|
1715
|
+
if (stMarketOf(code) === 'bj')
|
|
1716
|
+
continue;
|
|
1717
|
+
if (stMarketOf(code) !== market)
|
|
1718
|
+
throw sourceError(`Eastmoney ${market} risk-warning board returned ${code} as ${stMarketOf(code)}`, 'eastmoney_invalid_response');
|
|
1719
|
+
rows.push(parseStStockRow(raw, market));
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
const seen = new Set();
|
|
1723
|
+
for (const row of rows) {
|
|
1724
|
+
const code = String(row.code);
|
|
1725
|
+
if (seen.has(code))
|
|
1726
|
+
throw sourceError(`Eastmoney ST list contains duplicate code ${code}`, 'eastmoney_invalid_response');
|
|
1727
|
+
seen.add(code);
|
|
1728
|
+
}
|
|
1729
|
+
const order = { sh: 0, sz: 1, bj: 2 };
|
|
1730
|
+
rows.sort((left, right) => (order[String(left.market)] - order[String(right.market)]) || String(left.code).localeCompare(String(right.code)));
|
|
1731
|
+
const by_market = { sh: 0, sz: 0, bj: 0 };
|
|
1732
|
+
for (const row of rows)
|
|
1733
|
+
by_market[String(row.market)] += 1;
|
|
1734
|
+
return {
|
|
1735
|
+
data: { item: rows, total: rows.length, markets, by_market },
|
|
1736
|
+
schema: stStockListOutput,
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
const EVENT_DEFAULT_SIZE = 100;
|
|
1740
|
+
/** Optional ticker + optional closed date range + page/size: the shape shared by the event tables. */
|
|
1741
|
+
function eventInput(options) {
|
|
1742
|
+
return {
|
|
1743
|
+
type: 'object',
|
|
1744
|
+
properties: {
|
|
1745
|
+
ticker: { type: 'string', description: options.ticker },
|
|
1746
|
+
start_date: { type: 'string', description: options.startDate },
|
|
1747
|
+
end_date: { type: 'string', description: options.endDate },
|
|
1748
|
+
...(options.extra ?? {}),
|
|
1749
|
+
page: { type: 'integer', minimum: 1 },
|
|
1750
|
+
size: { type: 'integer', minimum: 1, maximum: MAX_PAGE_SIZE },
|
|
1751
|
+
},
|
|
1752
|
+
required: [],
|
|
1753
|
+
additionalProperties: false,
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
/** Values-only canonicalization: keys stay exactly those the model declared (§10.7) and a second
|
|
1757
|
+
* pass over the result is a no-op. Dates are optional but must come as a pair. */
|
|
1758
|
+
function normalizeEvent(params, extraKeys = []) {
|
|
1759
|
+
assertKnown(params, ['ticker', 'start_date', 'end_date', 'page', 'size', ...extraKeys]);
|
|
1760
|
+
const page = params.page === undefined ? 1 : integer(params.page, 'page', 1, Number.MAX_SAFE_INTEGER);
|
|
1761
|
+
const size = params.size === undefined ? EVENT_DEFAULT_SIZE : integer(params.size, 'size', 1, MAX_PAGE_SIZE);
|
|
1762
|
+
const normalized = { page, size };
|
|
1763
|
+
if (params.ticker !== undefined)
|
|
1764
|
+
normalized.ticker = ashareThscode(params.ticker);
|
|
1765
|
+
const start = params.start_date === undefined ? undefined : date(params.start_date, 'start_date');
|
|
1766
|
+
const end = params.end_date === undefined ? undefined : date(params.end_date, 'end_date');
|
|
1767
|
+
if ((start === undefined) !== (end === undefined))
|
|
1768
|
+
throw new Error('start_date and end_date must be given together');
|
|
1769
|
+
if (start !== undefined && end !== undefined) {
|
|
1770
|
+
if (start > end)
|
|
1771
|
+
throw new Error('start_date must not be later than end_date');
|
|
1772
|
+
normalized.start_date = start;
|
|
1773
|
+
normalized.end_date = end;
|
|
1774
|
+
}
|
|
1775
|
+
return normalized;
|
|
1776
|
+
}
|
|
1777
|
+
function eventFilter(parts) { return parts.join(''); }
|
|
1778
|
+
function eventTickerFilter(field, ticker) {
|
|
1779
|
+
return ticker === undefined ? [] : [`(${field}="${String(ticker).slice(0, 6)}")`];
|
|
1780
|
+
}
|
|
1781
|
+
function eventDateFilter(field, params) {
|
|
1782
|
+
return params.start_date === undefined ? [] : [`(${field}>='${String(params.start_date)}')(${field}<='${String(params.end_date)}')`];
|
|
1783
|
+
}
|
|
1784
|
+
async function fetchEventPage(spec, signal) {
|
|
1785
|
+
const url = new URL(DATACENTER_URL);
|
|
1786
|
+
url.searchParams.set('reportName', spec.reportName);
|
|
1787
|
+
url.searchParams.set('columns', 'ALL');
|
|
1788
|
+
url.searchParams.set('source', 'WEB');
|
|
1789
|
+
url.searchParams.set('client', 'WEB');
|
|
1790
|
+
url.searchParams.set('sortColumns', spec.sortColumns);
|
|
1791
|
+
url.searchParams.set('sortTypes', spec.sortTypes);
|
|
1792
|
+
url.searchParams.set('pageNumber', String(spec.page));
|
|
1793
|
+
url.searchParams.set('pageSize', String(spec.size));
|
|
1794
|
+
if (spec.filter.length > 0)
|
|
1795
|
+
url.searchParams.set('filter', spec.filter);
|
|
1796
|
+
const result = requireDatacenterResult(await getJson(url.toString(), signal, spec.context), spec.context);
|
|
1797
|
+
return requireRows(result, spec.context);
|
|
1798
|
+
}
|
|
1799
|
+
/** SECUCODE when the table carries it, else the 6-digit code column with the A-share digit rule. */
|
|
1800
|
+
function rowIdentity(raw, context, codeField) {
|
|
1801
|
+
if (typeof raw.SECUCODE === 'string' && raw.SECUCODE.includes('.'))
|
|
1802
|
+
return { ...normalizeEastmoneySecurityIdentity({ secucode: raw.SECUCODE }) };
|
|
1803
|
+
const code = String(raw[codeField] ?? '');
|
|
1804
|
+
if (!/^\d{6}$/u.test(code))
|
|
1805
|
+
throw sourceError(`Eastmoney ${context} row has no usable security code`, 'eastmoney_invalid_response');
|
|
1806
|
+
return { ...normalizeEastmoneyAshareIdentity(code) };
|
|
1807
|
+
}
|
|
1808
|
+
function eventRowSchema(properties) {
|
|
1809
|
+
return {
|
|
1810
|
+
type: 'object',
|
|
1811
|
+
properties: {
|
|
1812
|
+
thscode: { type: 'string' }, ticker: { type: 'string' }, eastmoney_code: { type: 'string' },
|
|
1813
|
+
eastmoney_market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] }, name: { type: 'string' },
|
|
1814
|
+
...properties,
|
|
1815
|
+
},
|
|
1816
|
+
required: ['thscode', 'ticker', 'eastmoney_code', 'eastmoney_market', 'name', ...Object.keys(properties)],
|
|
1817
|
+
additionalProperties: false,
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
const institutionResearchRow = eventRowSchema({
|
|
1821
|
+
notice_date: { type: 'string' }, notice_date_ms: { type: 'integer' },
|
|
1822
|
+
survey_start_date: nullableString, survey_end_date: nullableString,
|
|
1823
|
+
org_count: nullableNumber, survey_way: nullableString, reception_place: nullableString, receptionist: nullableString,
|
|
1824
|
+
});
|
|
1825
|
+
const institutionResearchInput = eventInput({
|
|
1826
|
+
ticker: '个股代码(600519 或 600519.SH);省略取全市场',
|
|
1827
|
+
startDate: '公告日区间起点 YYYY-MM-DD(NOTICE_DATE)',
|
|
1828
|
+
endDate: '公告日区间终点 YYYY-MM-DD(NOTICE_DATE)',
|
|
1829
|
+
});
|
|
1830
|
+
function normalizeInstitutionResearch(params) { return normalizeEvent(params); }
|
|
1831
|
+
function parseInstitutionResearchRow(raw) {
|
|
1832
|
+
const notice = dayValue(raw.NOTICE_DATE);
|
|
1833
|
+
if (notice === null)
|
|
1834
|
+
throw sourceError('Eastmoney institution survey row has invalid NOTICE_DATE', 'eastmoney_invalid_response');
|
|
1835
|
+
return {
|
|
1836
|
+
...rowIdentity(raw, 'institution survey', 'SECURITY_CODE'),
|
|
1837
|
+
name: String(raw.SECURITY_NAME_ABBR ?? ''),
|
|
1838
|
+
notice_date: notice,
|
|
1839
|
+
notice_date_ms: dateMs(notice),
|
|
1840
|
+
survey_start_date: dayValue(raw.RECEIVE_START_DATE),
|
|
1841
|
+
survey_end_date: dayValue(raw.RECEIVE_END_DATE),
|
|
1842
|
+
org_count: numberOrNull(raw.SUM),
|
|
1843
|
+
survey_way: textOrNull(raw.RECEIVE_WAY_EXPLAIN),
|
|
1844
|
+
reception_place: textOrNull(raw.RECEIVE_PLACE),
|
|
1845
|
+
receptionist: textOrNull(raw.RECEPTIONIST),
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
async function executeInstitutionResearch(params, signal) {
|
|
1849
|
+
// Aggregate rows only: NUMBERNEW="1" keeps one row per survey and SUM is the reported org count.
|
|
1850
|
+
const filter = eventFilter(['(IS_SOURCE="1")(NUMBERNEW="1")', ...eventTickerFilter('SECURITY_CODE', params.ticker), ...eventDateFilter('NOTICE_DATE', params)]);
|
|
1851
|
+
// Sort uniqueness (verified 2026-11-22): NOTICE_DATE 2026-11-01..2026-11-21 = 1728 rows over 4 pages
|
|
1852
|
+
// of 500 → 0 duplicate (NOTICE_DATE, SECURITY_CODE, RECEIVE_START_DATE) tuples, 0 duplicate rows.
|
|
1853
|
+
const parsed = await fetchEventPage({ reportName: 'RPT_ORG_SURVEYNEW', context: 'institution survey', filter, sortColumns: 'NOTICE_DATE,SECURITY_CODE,RECEIVE_START_DATE', sortTypes: '-1,1,-1', page: Number(params.page), size: Number(params.size) }, signal);
|
|
1854
|
+
return { data: { item: parsed.rows.map(parseInstitutionResearchRow), pagination: pagination(Number(params.page), Number(params.size), parsed.pages, parsed.total) }, schema: datacenterOutput(institutionResearchRow) };
|
|
1855
|
+
}
|
|
1856
|
+
const HOLDER_DIRECTION_CODE = { increase: '增持', decrease: '减持' };
|
|
1857
|
+
const HOLDER_DIRECTION_TEXT = { 增持: 'increase', 减持: 'decrease' };
|
|
1858
|
+
const holderChangeRow = eventRowSchema({
|
|
1859
|
+
notice_date: { type: 'string' }, notice_date_ms: { type: 'integer' },
|
|
1860
|
+
holder_name: { type: 'string' }, direction: { type: 'string', enum: ['increase', 'decrease'] },
|
|
1861
|
+
change_shares_10k: nullableNumber, change_pct_total: nullableNumber, change_pct_float: nullableNumber,
|
|
1862
|
+
after_hold_shares_10k: nullableNumber, after_pct_total: nullableNumber,
|
|
1863
|
+
after_float_hold_shares_10k: nullableNumber, after_pct_float: nullableNumber,
|
|
1864
|
+
avg_price: nullableNumber, channel: nullableString, start_date: nullableString, end_date: nullableString,
|
|
1865
|
+
});
|
|
1866
|
+
const holderChangeInput = eventInput({
|
|
1867
|
+
ticker: '个股代码(600519 或 600519.SH);省略取全市场',
|
|
1868
|
+
startDate: '公告日区间起点 YYYY-MM-DD(NOTICE_DATE)',
|
|
1869
|
+
endDate: '公告日区间终点 YYYY-MM-DD(NOTICE_DATE)',
|
|
1870
|
+
extra: { direction: { type: 'string', enum: ['increase', 'decrease'], description: '增持 increase / 减持 decrease;省略取两种' } },
|
|
1871
|
+
});
|
|
1872
|
+
function normalizeHolderChange(params) {
|
|
1873
|
+
const normalized = normalizeEvent(params, ['direction']);
|
|
1874
|
+
if (params.direction === undefined)
|
|
1875
|
+
return normalized;
|
|
1876
|
+
const direction = String(params.direction).toLowerCase();
|
|
1877
|
+
if (!(direction in HOLDER_DIRECTION_CODE))
|
|
1878
|
+
throw new Error('direction must be one of increase, decrease');
|
|
1879
|
+
return { ...normalized, direction };
|
|
1880
|
+
}
|
|
1881
|
+
function parseHolderChangeRow(raw) {
|
|
1882
|
+
const notice = dayValue(raw.NOTICE_DATE);
|
|
1883
|
+
if (notice === null)
|
|
1884
|
+
throw sourceError('Eastmoney holder change row has invalid NOTICE_DATE', 'eastmoney_invalid_response');
|
|
1885
|
+
const direction = HOLDER_DIRECTION_TEXT[String(raw.DIRECTION ?? '')];
|
|
1886
|
+
if (direction === undefined)
|
|
1887
|
+
throw sourceError(`Eastmoney holder change row has unknown DIRECTION ${String(raw.DIRECTION ?? '(empty)')}`, 'eastmoney_invalid_response');
|
|
1888
|
+
const changeShares = numberOrNull(raw.CHANGE_NUM_SYMBOL);
|
|
1889
|
+
// Upstream ships a signed share count plus a separate direction; a mismatch would silently flip
|
|
1890
|
+
// 增持 into 减持 for consumers reading only the number.
|
|
1891
|
+
if (changeShares !== null && changeShares !== 0 && (changeShares < 0) !== (direction === 'decrease')) {
|
|
1892
|
+
throw sourceError('Eastmoney holder change row flips the signed share count against DIRECTION', 'eastmoney_invalid_response');
|
|
1893
|
+
}
|
|
1894
|
+
return {
|
|
1895
|
+
...rowIdentity(raw, 'holder change', 'SECURITY_CODE'),
|
|
1896
|
+
name: String(raw.SECURITY_NAME_ABBR ?? ''),
|
|
1897
|
+
notice_date: notice,
|
|
1898
|
+
notice_date_ms: dateMs(notice),
|
|
1899
|
+
holder_name: String(raw.HOLDER_NAME ?? ''),
|
|
1900
|
+
direction,
|
|
1901
|
+
change_shares_10k: changeShares,
|
|
1902
|
+
// ⛔ AFTER_CHANGE_RATE is the move's share of total shares, not the post-move holding ratio:
|
|
1903
|
+
// 000915 moved 213.04万股 → 0.909 here while HOLD_RATIO (holding after) is 24.17.
|
|
1904
|
+
change_pct_total: numberOrNull(raw.AFTER_CHANGE_RATE),
|
|
1905
|
+
change_pct_float: numberOrNull(raw.CHANGE_FREE_RATIO),
|
|
1906
|
+
after_hold_shares_10k: numberOrNull(raw.AFTER_HOLDER_NUM),
|
|
1907
|
+
after_pct_total: numberOrNull(raw.HOLD_RATIO),
|
|
1908
|
+
after_float_hold_shares_10k: numberOrNull(raw.FREE_SHARES),
|
|
1909
|
+
after_pct_float: numberOrNull(raw.FREE_SHARES_RATIO),
|
|
1910
|
+
avg_price: numberOrNull(raw.TRADE_AVERAGE_PRICE),
|
|
1911
|
+
channel: textOrNull(raw.MARKET),
|
|
1912
|
+
start_date: dayValue(raw.START_DATE),
|
|
1913
|
+
end_date: dayValue(raw.END_DATE),
|
|
1914
|
+
};
|
|
1915
|
+
}
|
|
1916
|
+
async function executeHolderChange(params, signal) {
|
|
1917
|
+
const directionFilter = params.direction === undefined ? [] : [`(DIRECTION="${HOLDER_DIRECTION_CODE[String(params.direction)]}")`];
|
|
1918
|
+
const filter = eventFilter([...directionFilter, ...eventTickerFilter('SECURITY_CODE', params.ticker), ...eventDateFilter('NOTICE_DATE', params)]);
|
|
1919
|
+
// Sort uniqueness (verified 2026-11-22): NOTICE_DATE 2026-06-01..2026-11-21 = 2969 rows over 6 pages
|
|
1920
|
+
// of 500 → 0 duplicate identity tuples and 0 duplicate rows.
|
|
1921
|
+
const parsed = await fetchEventPage({ reportName: 'RPT_SHARE_HOLDER_INCREASE', context: 'holder change', filter, sortColumns: 'NOTICE_DATE,SECURITY_CODE,HOLDER_NAME,START_DATE,END_DATE', sortTypes: '-1,1,1,1,1', page: Number(params.page), size: Number(params.size) }, signal);
|
|
1922
|
+
return { data: { item: parsed.rows.map(parseHolderChangeRow), pagination: pagination(Number(params.page), Number(params.size), parsed.pages, parsed.total) }, schema: datacenterOutput(holderChangeRow) };
|
|
1923
|
+
}
|
|
1924
|
+
/** 001–006 have names; 007/008 appear in the table (63 + 1 of 5846 rows on 2026-11-22) but upstream
|
|
1925
|
+
* never names them, so `progress` stays null and `progress_code` keeps the raw code. */
|
|
1926
|
+
const BUYBACK_PROGRESS = { '001': '董事会预案', '002': '股东大会通过', '003': '股东大会否决', '004': '实施中', '005': '停止实施', '006': '完成实施' };
|
|
1927
|
+
const BUYBACK_PROGRESS_CODE = Object.fromEntries(Object.entries(BUYBACK_PROGRESS).map(([code, label]) => [label, code]));
|
|
1928
|
+
const BUYBACK_PROGRESS_NAMES = Object.keys(BUYBACK_PROGRESS_CODE);
|
|
1929
|
+
const buybackRow = eventRowSchema({
|
|
1930
|
+
progress: { oneOf: [{ type: 'string', enum: BUYBACK_PROGRESS_NAMES }, { type: 'null' }] },
|
|
1931
|
+
progress_code: { type: 'string' },
|
|
1932
|
+
update_date: { type: 'string' }, update_date_ms: { type: 'integer' },
|
|
1933
|
+
plan_notice_date: nullableString, latest_notice_date: nullableString, finish_date: nullableString,
|
|
1934
|
+
plan_start_date: nullableString, plan_end_date: nullableString,
|
|
1935
|
+
price_cap: nullableNumber,
|
|
1936
|
+
plan_shares_lower: nullableNumber, plan_shares_upper: nullableNumber,
|
|
1937
|
+
plan_amount_lower: nullableNumber, plan_amount_upper: nullableNumber,
|
|
1938
|
+
plan_pct_total_lower: nullableNumber, plan_pct_total_upper: nullableNumber,
|
|
1939
|
+
done_shares: nullableNumber, done_amount: nullableNumber,
|
|
1940
|
+
done_price_low: nullableNumber, done_price_high: nullableNumber,
|
|
1941
|
+
objective: nullableString,
|
|
1942
|
+
});
|
|
1943
|
+
const buybackInput = eventInput({
|
|
1944
|
+
ticker: '个股代码(000333 或 000333.SZ);省略取全市场',
|
|
1945
|
+
startDate: '数据更新日区间起点 YYYY-MM-DD(UPD,不是方案公告日)',
|
|
1946
|
+
endDate: '数据更新日区间终点 YYYY-MM-DD(UPD)',
|
|
1947
|
+
extra: { progress: { type: 'string', enum: BUYBACK_PROGRESS_NAMES, description: '方案进度;省略取全部(含上游未命名的 007/008 码)' } },
|
|
1948
|
+
});
|
|
1949
|
+
function normalizeBuyback(params) {
|
|
1950
|
+
const normalized = normalizeEvent(params, ['progress']);
|
|
1951
|
+
if (params.progress === undefined)
|
|
1952
|
+
return normalized;
|
|
1953
|
+
const progress = String(params.progress);
|
|
1954
|
+
if (!(progress in BUYBACK_PROGRESS_CODE))
|
|
1955
|
+
throw new Error(`progress must be one of ${BUYBACK_PROGRESS_NAMES.join(', ')}`);
|
|
1956
|
+
return { ...normalized, progress };
|
|
1957
|
+
}
|
|
1958
|
+
function parseBuybackRow(raw) {
|
|
1959
|
+
const updateDate = dayValue(raw.UPD);
|
|
1960
|
+
if (updateDate === null)
|
|
1961
|
+
throw sourceError('Eastmoney buyback row has invalid UPD', 'eastmoney_invalid_response');
|
|
1962
|
+
const code = String(raw.REPURPROGRESS ?? '');
|
|
1963
|
+
return {
|
|
1964
|
+
...rowIdentity(raw, 'buyback', 'DIM_SCODE'),
|
|
1965
|
+
name: String(raw.SECURITYSHORTNAME ?? ''),
|
|
1966
|
+
progress: BUYBACK_PROGRESS[code] ?? null,
|
|
1967
|
+
progress_code: code,
|
|
1968
|
+
update_date: updateDate,
|
|
1969
|
+
update_date_ms: dateMs(updateDate),
|
|
1970
|
+
plan_notice_date: dayValue(raw.UPDATEDATE),
|
|
1971
|
+
latest_notice_date: dayValue(raw.NOTICEDATE),
|
|
1972
|
+
finish_date: dayValue(raw.FINISHDATE),
|
|
1973
|
+
plan_start_date: dayValue(raw.REPURSTARTDATE),
|
|
1974
|
+
plan_end_date: dayValue(raw.REPURENDDATE),
|
|
1975
|
+
price_cap: numberOrNull(raw.REPURPRICECAP),
|
|
1976
|
+
plan_shares_lower: numberOrNull(raw.REPURNUMLOWER),
|
|
1977
|
+
plan_shares_upper: numberOrNull(raw.REPURNUMCAP),
|
|
1978
|
+
plan_amount_lower: numberOrNull(raw.REPURAMOUNTLOWER),
|
|
1979
|
+
plan_amount_upper: numberOrNull(raw.REPURAMOUNTLIMIT),
|
|
1980
|
+
plan_pct_total_lower: numberOrNull(raw.ZSZXX),
|
|
1981
|
+
plan_pct_total_upper: numberOrNull(raw.ZSZSX),
|
|
1982
|
+
done_shares: numberOrNull(raw.REPURNUM),
|
|
1983
|
+
done_amount: numberOrNull(raw.REPURAMOUNT),
|
|
1984
|
+
done_price_low: numberOrNull(raw.REPURPRICELOWER1),
|
|
1985
|
+
done_price_high: numberOrNull(raw.REPURPRICECAP1),
|
|
1986
|
+
objective: textOrNull(raw.REPUROBJECTIVE),
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
async function executeBuyback(params, signal) {
|
|
1990
|
+
const progressFilter = params.progress === undefined ? [] : [`(REPURPROGRESS="${BUYBACK_PROGRESS_CODE[String(params.progress)]}")`];
|
|
1991
|
+
const filter = eventFilter([...progressFilter, ...eventTickerFilter('DIM_SCODE', params.ticker), ...eventDateFilter('UPD', params)]);
|
|
1992
|
+
// Sort uniqueness (verified 2026-11-22): all 5846 rows over 12 pages of 500 → 0 duplicate
|
|
1993
|
+
// (DIM_SCODE, REPURCODE) plans and 0 duplicate rows. One row per plan, current state only.
|
|
1994
|
+
const parsed = await fetchEventPage({ reportName: 'RPTA_WEB_GETHGLIST_NEW', context: 'buyback', filter, sortColumns: 'UPD,DIM_SCODE,REPURCODE', sortTypes: '-1,1,1', page: Number(params.page), size: Number(params.size) }, signal);
|
|
1995
|
+
return { data: { item: parsed.rows.map(parseBuybackRow), pagination: pagination(Number(params.page), Number(params.size), parsed.pages, parsed.total) }, schema: datacenterOutput(buybackRow) };
|
|
1996
|
+
}
|
|
1997
|
+
const pledgeRow = eventRowSchema({
|
|
1998
|
+
stats_date: { type: 'string' }, stats_date_ms: { type: 'integer' },
|
|
1999
|
+
industry: nullableString,
|
|
2000
|
+
pledge_ratio_pct: nullableNumber, pledged_shares_10k: nullableNumber, pledged_market_cap_10k: nullableNumber,
|
|
2001
|
+
pledge_deal_num: nullableNumber, unrestricted_pledged_10k: nullableNumber, restricted_pledged_10k: nullableNumber,
|
|
2002
|
+
});
|
|
2003
|
+
const pledgeInput = eventInput({
|
|
2004
|
+
ticker: '沪深个股代码(600519 或 600519.SH);北交所不接受(中国结算统计只覆盖沪深)',
|
|
2005
|
+
startDate: '统计日区间起点 YYYY-MM-DD(TRADE_DATE;中国结算按周发布,通常周五)',
|
|
2006
|
+
endDate: '统计日区间终点 YYYY-MM-DD(TRADE_DATE)',
|
|
2007
|
+
});
|
|
2008
|
+
function normalizePledge(params) {
|
|
2009
|
+
const normalized = normalizeEvent(params);
|
|
2010
|
+
const ticker = normalized.ticker;
|
|
2011
|
+
if (typeof ticker === 'string' && ticker.endsWith('.BJ')) {
|
|
2012
|
+
throw new Error(`${ticker} 是北交所证券;中国结算股权质押统计只覆盖沪深(实测 2026-11-20 全市场 2265 行无北交所),本能力不返回北交所数据`);
|
|
2013
|
+
}
|
|
2014
|
+
return normalized;
|
|
2015
|
+
}
|
|
2016
|
+
function parsePledgeRow(raw) {
|
|
2017
|
+
const statsDate = dayValue(raw.TRADE_DATE);
|
|
2018
|
+
if (statsDate === null)
|
|
2019
|
+
throw sourceError('Eastmoney pledge row has invalid TRADE_DATE', 'eastmoney_invalid_response');
|
|
2020
|
+
const total = numberOrNull(raw.REPURCHASE_BALANCE);
|
|
2021
|
+
const unrestricted = numberOrNull(raw.REPURCHASE_UNLIMITED_BALANCE);
|
|
2022
|
+
const restricted = numberOrNull(raw.REPURCHASE_LIMITED_BALANCE);
|
|
2023
|
+
// Verified invariant over all 2265 rows of 2026-11-20: 无限售 + 限售 = 合计 (万股).
|
|
2024
|
+
if (total !== null && unrestricted !== null && restricted !== null && Math.abs(unrestricted + restricted - total) > Math.max(1, total * 0.001)) {
|
|
2025
|
+
throw sourceError(`Eastmoney pledge row ${String(raw.SECURITY_CODE ?? '')} has unrestricted + restricted != total`, 'eastmoney_invalid_response');
|
|
2026
|
+
}
|
|
2027
|
+
return {
|
|
2028
|
+
...rowIdentity(raw, 'pledge', 'SECURITY_CODE'),
|
|
2029
|
+
name: String(raw.SECURITY_NAME_ABBR ?? ''),
|
|
2030
|
+
stats_date: statsDate,
|
|
2031
|
+
stats_date_ms: dateMs(statsDate),
|
|
2032
|
+
industry: textOrNull(raw.INDUSTRY),
|
|
2033
|
+
pledge_ratio_pct: numberOrNull(raw.PLEDGE_RATIO),
|
|
2034
|
+
pledged_shares_10k: total,
|
|
2035
|
+
pledged_market_cap_10k: numberOrNull(raw.PLEDGE_MARKET_CAP),
|
|
2036
|
+
pledge_deal_num: numberOrNull(raw.PLEDGE_DEAL_NUM),
|
|
2037
|
+
unrestricted_pledged_10k: unrestricted,
|
|
2038
|
+
restricted_pledged_10k: restricted,
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
async function executePledge(params, signal) {
|
|
2042
|
+
const common = { reportName: 'RPT_CSDC_LIST', context: 'pledge', sortColumns: 'TRADE_DATE,PLEDGE_RATIO,SECURITY_CODE', sortTypes: '-1,-1,1' };
|
|
2043
|
+
let filter;
|
|
2044
|
+
if (params.ticker !== undefined || params.start_date !== undefined) {
|
|
2045
|
+
filter = eventFilter([...eventTickerFilter('SECURITY_CODE', params.ticker), ...eventDateFilter('TRADE_DATE', params)]);
|
|
2046
|
+
}
|
|
2047
|
+
else {
|
|
2048
|
+
// No filters means "latest statistics week", matching the upstream convenience behaviour: one
|
|
2049
|
+
// extra 1-row request resolves the date so later pages cannot spill into earlier weeks.
|
|
2050
|
+
const latest = await fetchEventPage({ ...common, filter: '', page: 1, size: 1 }, signal);
|
|
2051
|
+
const statsDate = latest.rows.length === 0 ? null : dayValue(latest.rows[0].TRADE_DATE);
|
|
2052
|
+
if (statsDate === null)
|
|
2053
|
+
throw sourceError('Eastmoney pledge table has no statistics date', 'eastmoney_invalid_response');
|
|
2054
|
+
filter = `(TRADE_DATE='${statsDate}')`;
|
|
2055
|
+
}
|
|
2056
|
+
// Sort uniqueness (verified 2026-11-22): 2026-11-20 = 2265 rows over 5 pages of 500 → 0 duplicate
|
|
2057
|
+
// (TRADE_DATE, SECURITY_CODE); ratio alone is NOT unique (upstream saw a dup + a missing row).
|
|
2058
|
+
const parsed = await fetchEventPage({ ...common, filter, page: Number(params.page), size: Number(params.size) }, signal);
|
|
2059
|
+
return { data: { item: parsed.rows.map(parsePledgeRow), pagination: pagination(Number(params.page), Number(params.size), parsed.pages, parsed.total) }, schema: datacenterOutput(pledgeRow) };
|
|
2060
|
+
}
|
|
2061
|
+
const newStockRow = eventRowSchema({
|
|
2062
|
+
apply_code: nullableString, exchange: nullableString, board: nullableString,
|
|
2063
|
+
apply_date: { type: 'string' }, apply_date_ms: { type: 'integer' },
|
|
2064
|
+
ballot_date: nullableString, pay_date: nullableString, listing_date: nullableString,
|
|
2065
|
+
issue_price: nullableNumber, issue_pe: nullableNumber, industry_pe: nullableNumber,
|
|
2066
|
+
issue_shares_10k: nullableNumber, online_shares: nullableNumber, apply_upper_shares: nullableNumber,
|
|
2067
|
+
top_apply_mktcap_10k: nullableNumber, win_rate_pct: nullableNumber,
|
|
2068
|
+
first_close_price: nullableNumber, first_close_change_pct: nullableNumber,
|
|
2069
|
+
});
|
|
2070
|
+
const newStockInput = eventInput({
|
|
2071
|
+
ticker: '新股代码(920067 或 920067.BJ);省略取全市场',
|
|
2072
|
+
startDate: '申购日区间起点 YYYY-MM-DD(APPLY_DATE)',
|
|
2073
|
+
endDate: '申购日区间终点 YYYY-MM-DD(APPLY_DATE)',
|
|
2074
|
+
});
|
|
2075
|
+
function normalizeNewStock(params) { return normalizeEvent(params); }
|
|
2076
|
+
function parseNewStockRow(raw) {
|
|
2077
|
+
const applyDate = dayValue(raw.APPLY_DATE);
|
|
2078
|
+
if (applyDate === null)
|
|
2079
|
+
throw sourceError('Eastmoney new stock row has invalid APPLY_DATE', 'eastmoney_invalid_response');
|
|
2080
|
+
const issuePrice = numberOrNull(raw.ISSUE_PRICE);
|
|
2081
|
+
return {
|
|
2082
|
+
...rowIdentity(raw, 'new stock', 'SECURITY_CODE'),
|
|
2083
|
+
name: String(raw.SECURITY_NAME ?? ''),
|
|
2084
|
+
apply_code: textOrNull(raw.APPLY_CODE),
|
|
2085
|
+
exchange: textOrNull(raw.TRADE_MARKET),
|
|
2086
|
+
// MARKET names the board precisely (上交所科创板 / 深交所创业板); BSE rows leave MARKET null and
|
|
2087
|
+
// only carry MARKET_TYPE_NEW = 北交所, so the fallback is the only way to keep board non-null.
|
|
2088
|
+
board: textOrNull(raw.MARKET) ?? textOrNull(raw.MARKET_TYPE_NEW),
|
|
2089
|
+
apply_date: applyDate,
|
|
2090
|
+
apply_date_ms: dateMs(applyDate),
|
|
2091
|
+
ballot_date: dayValue(raw.BALLOT_NUM_DATE),
|
|
2092
|
+
pay_date: dayValue(raw.BALLOT_PAY_DATE),
|
|
2093
|
+
listing_date: dayValue(raw.LISTING_DATE),
|
|
2094
|
+
// Null before pricing. Upstream also parks 0 in adjacent price placeholders, so 0 is reported as
|
|
2095
|
+
// null (not priced yet) rather than a real zero-yuan offer; all 2 such rows on 2026-11-22 are null.
|
|
2096
|
+
issue_price: issuePrice === null || issuePrice <= 0 ? null : issuePrice,
|
|
2097
|
+
issue_pe: numberOrNull(raw.AFTER_ISSUE_PE),
|
|
2098
|
+
industry_pe: numberOrNull(raw.INDUSTRY_PE),
|
|
2099
|
+
issue_shares_10k: numberOrNull(raw.ISSUE_NUM),
|
|
2100
|
+
online_shares: numberOrNull(raw.ONLINE_ISSUE_NUM),
|
|
2101
|
+
apply_upper_shares: numberOrNull(raw.ONLINE_APPLY_UPPER),
|
|
2102
|
+
top_apply_mktcap_10k: numberOrNull(raw.TOP_APPLY_MARKETCAP),
|
|
2103
|
+
win_rate_pct: numberOrNull(raw.ONLINE_ISSUE_LWR),
|
|
2104
|
+
first_close_price: numberOrNull(raw.CLOSE_PRICE),
|
|
2105
|
+
first_close_change_pct: numberOrNull(raw.LD_CLOSE_CHANGE),
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
async function executeNewStock(params, signal) {
|
|
2109
|
+
const filter = eventFilter([...eventTickerFilter('SECURITY_CODE', params.ticker), ...eventDateFilter('APPLY_DATE', params)]);
|
|
2110
|
+
// Sort uniqueness (verified 2026-11-22): all 5642 rows over 12 pages of 500 → 0 duplicate
|
|
2111
|
+
// SECURITY_CODE and 0 duplicate rows; includes upcoming subscriptions (LISTING_DATE null).
|
|
2112
|
+
const parsed = await fetchEventPage({ reportName: 'RPTA_APP_IPOAPPLY', context: 'new stock calendar', filter, sortColumns: 'APPLY_DATE,SECURITY_CODE', sortTypes: '-1,-1', page: Number(params.page), size: Number(params.size) }, signal);
|
|
2113
|
+
return { data: { item: parsed.rows.map(parseNewStockRow), pagination: pagination(Number(params.page), Number(params.size), parsed.pages, parsed.total) }, schema: datacenterOutput(newStockRow) };
|
|
2114
|
+
}
|
|
1465
2115
|
export function createEastmoneySources() {
|
|
1466
2116
|
return [
|
|
1467
2117
|
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) }),
|
|
@@ -1546,5 +2196,858 @@ export function createEastmoneySources() {
|
|
|
1546
2196
|
paginated: true, rowShape: { rowKey: 'item' },
|
|
1547
2197
|
allowed: ['start_date', 'end_date', 'market', 'page', 'size'], normalize: normalizeMarketMargin, execute: executeMarketMargin,
|
|
1548
2198
|
}),
|
|
2199
|
+
createSource({
|
|
2200
|
+
capability: 'eastmoney_security_profile', cacheMaxAgeMs: 60_000, name: 'get_eastmoney_security_profile',
|
|
2201
|
+
summary: '东财个股基本面:行业/股本/市值/上市日/PE/PB',
|
|
2202
|
+
description: '获取单只 A 股的东财 push2 基本面快照(stock/get,按 secid 直连)。字段口径已实测核对(2026-11-22,600519):industry 是东财 f127 行业板块名(实测「白酒Ⅱ」),total_shares/float_shares 为 f84/f85(股,与 datacenter TOTAL_SHARE 1,250,081,601 精确一致),total_market_cap/float_market_cap 为 f116/f117(元,实测等于价×股本 1,857,308,738,685.75),list_date 为 f189(上游 YYYYMMDD「20010827」,转 YYYY-MM-DD 并给 list_date_ms),pe_dynamic 为 f162 动态市盈率(实测 21.61,与 datacenter PE_DYNAMIC 21.60752555 对上),pb 为 f167 市净率(实测 6.85,价格/BPS = 1485.75/216.9496 = 6.848 对上)。市值随价格变动,是查询时点快照,不是历史序列。⛔ 与同花顺口径的 index_membership_by_stock **不是一回事**:这里 industry 只给东财一级/二级板块名一个字符串(如「白酒Ⅱ」),既没有板块代码也不给多板块归属,不能当申万行业或同花顺行业用,两者不可对比、不可拼接。⛔ secid 市场号由 helper 规则决定(沪=1,深/北同为 0;5x ETF、588x 科创 ETF、900x 沪 B 都算沪市,92x 北交所必须先于 9x 判断),不许按首位数字猜:裸 6 位代码按 A 股个股解析(000001 = 平安银行,不是上证指数),显式市场与代码前缀冲突(如 000001.SH 上证指数)直接拒绝。指数/基金不在范围:上游对这类 secid 不给股本,本能力报 eastmoney_invalid_ticker,不回一行 null 冒充。PE/PB 是东财原值:亏损股动态 PE 可为负值,停牌或异常时上游用「-」占位,本能力输出 null(null 不等于 0 倍)。',
|
|
2203
|
+
inputSchema: profileInput, outputSchema: datacenterOutput(profileRow), paginated: false, rowShape: { rowKey: 'item' },
|
|
2204
|
+
allowed: ['ticker'], normalize: normalizeProfile, execute: executeProfile,
|
|
2205
|
+
validateOutput: (data) => isRecord(data) && Array.isArray(data.item) && data.item.length === 1 && isRecord(data.pagination),
|
|
2206
|
+
}),
|
|
2207
|
+
createSource({
|
|
2208
|
+
capability: 'eastmoney_st_stock_list', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_st_stock_list',
|
|
2209
|
+
summary: '沪深京 ST/*ST 当日名单(风险警示快照)',
|
|
2210
|
+
description: '获取沪深京当日 ST / *ST 名单快照(东财 push2 clist,实测 2026-11-22:沪风险警示板 81 行、深风险警示板 304 行、北交所全表 366 行)。⛔ 北交所口径实测与上游 SKILL 文档不一致,按实测写清:`m:0+f:4` 并不是「只有深市」——实测返回 304 行,其中 189 行是北交所代码(430/830/831/…/873 老号段加 920 新号段),但这 189 行里 186 只在北交所当前 A 股全表(m:0+t:81+s:2048,实测 366 行)里没有对应的 ST 名称行,属老号段僵尸数据;当前北交所真正的 ST 只有 3 只(920575 *ST康乐、920090 *ST同辉、920023 *ST田野),它们既出现在风险警示板里也在北交所全表里。所以本能力按市场分别取:sh 用 m:1+f:4;sz 用 m:0+f:4 并剔除北交所代码;bj 用 m:0+t:81+s:2048 全表按名称含 ST 筛——⛔ 不能直接吃风险警示板,否则会把 186 只僵尸老号段当成北交所 ST 列出来。行按 sh→sz→bj、代码升序,code 唯一(重复即报 upstream 结构变化)。share_type 区分 a_share / b_share(沪 900xxx、深 200xxx 是 B 股;实测沪市 1 只 ST中路B、深市 2 只 ST晨鸣B / *ST皇庭B),⛔ B 股价格与成交额币种不同(沪 B 美元、深 B 港元),不能与 A 股人民币金额相加。单位:price 元(B 股为各自币种)、change_pct %、change_amount 元、volume 手、amount 元、amplitude_pct / turnover_pct %,均为东财原值;停牌行上游给「-」,这里输出 null 而不是 0。⛔ 只有当日快照、没有历史:要回测用的历史 ST 状态请换来源,本能力不提供按日回溯。翻页途中上游 total 变化会直接报错(避免把两份名单拼在一起);任一风险警示板返回 0 行按上游异常报错,不会被说成「今天没有 ST」。total / by_market 是本次行数与各市场计数,markets 是实际覆盖的市场集合。',
|
|
2211
|
+
inputSchema: stStockListInput, outputSchema: stStockListOutput, paginated: false, rowShape: { rowKey: 'item' },
|
|
2212
|
+
allowed: ['market'], normalize: normalizeStStockList, execute: executeStStockList,
|
|
2213
|
+
validateOutput: (data) => isRecord(data) && Array.isArray(data.item) && typeof data.total === 'number' && Array.isArray(data.markets) && isRecord(data.by_market),
|
|
2214
|
+
}),
|
|
2215
|
+
createSource({
|
|
2216
|
+
capability: 'eastmoney_institution_research', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_institution_research',
|
|
2217
|
+
summary: '东财机构调研事件(按公告日,一次调研一行)',
|
|
2218
|
+
description: '按公告日区间 / 个股分页获取东方财富机构调研事件(RPT_ORG_SURVEYNEW,取 IS_SOURCE="1" 且 NUMBERNEW="1" 的汇总行:一次调研一行)。实测 2026-11-22:NOTICE_DATE 2026-10-01..2026-11-21 共 2,941 条,688062 共 12 次调研。时间轴有两个:notice_date 是公告日(NOTICE_DATE,start_date/end_date 过滤的就是它,给 notice_date_ms 毫秒轴);survey_start_date / survey_end_date 是实际接待日(RECEIVE_START_DATE / RECEIVE_END_DATE),通常早于公告日几天。org_count 是上游汇总的参与机构家数(SUM,单位家)——⛔ 实测与逐机构明细行数并不总相等(002053: 1 vs 2、600098: 68 vs 69),它是公司披露口径的家数,不要反推成机构明细条数、也不是去重后的机构个数。survey_way 是调研方式原文(如「特定对象调研,路演活动」)、reception_place 接待地点、receptionist 接待人,均为上游原文不改写。⛔ 本能力只做汇总口径,不提供逐机构明细:上游同一张表可以关掉 NUMBERNEW 换成一行一机构,但那样行语义会变,不做进同一个能力。排序键 NOTICE_DATE 降序 + SECURITY_CODE 升序 + RECEIVE_START_DATE 降序,已实测唯一(1728 行 / 4 页无重复、无漏行)。空结果=区间内没有调研记录(上游 9201,返回空 item + 全零分页),不是取数失败,不要重试。',
|
|
2219
|
+
inputSchema: institutionResearchInput, outputSchema: datacenterOutput(institutionResearchRow), paginated: true, rowShape: { rowKey: 'item' },
|
|
2220
|
+
allowed: ['ticker', 'start_date', 'end_date', 'page', 'size'], normalize: normalizeInstitutionResearch, execute: executeInstitutionResearch,
|
|
2221
|
+
}),
|
|
2222
|
+
createSource({
|
|
2223
|
+
capability: 'eastmoney_holder_change', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_holder_change',
|
|
2224
|
+
summary: '东财重要股东增减持事件(按公告日)',
|
|
2225
|
+
description: '按公告日区间 / 个股 / 方向分页获取东方财富重要股东增减持事件(RPT_SHARE_HOLDER_INCREASE)。实测 2026-11-22:NOTICE_DATE 2026-06-01..2026-11-21 共 2,969 条;方向分布(2026-09-01 起 1,248 行)增持 371 / 减持 877,且带符号变动股数的符号与 DIRECTION 100% 一致(代码里对该一致性有断言)。时间轴:notice_date 是公告日(NOTICE_DATE,start_date/end_date 过滤口径,给 notice_date_ms)、start_date / end_date 是变动期间起止。⛔ 字段名陷阱:上游 AFTER_CHANGE_RATE 实测是「本次变动占总股本的比例(%)」,**不是**变动后持股比例——000915 增持 213.04 万股对应 0.909(变动/总股本),变动后持股占比是 HOLD_RATIO = 24.17;本能力把它输出为 change_pct_total 并在描述里钉死,别把它当持股比例用。change_pct_float(CHANGE_FREE_RATIO)是本次变动占流通股比例(%)。after_hold_shares_10k / after_float_hold_shares_10k 是变动后持股数(万股),after_pct_total / after_pct_float 是变动后占公司总股本 / 流通股比例(%)——实测 000915 变动后 5,664.1741 万股 × 24.17% 与总股本自洽。股数单位统一万股,change_shares_10k 带符号(减持为负)。avg_price 是公告披露的成交均价(元/股),实测 1,248 行有 809 行为 null——很多公告不披露,null 不是 0。channel 是变动方式原文(如「二级市场」「大宗交易」「协议转让」)。⛔ 上游 CHANGE_RATE(实测样本 -4.3769)、CLOSE_PRICE 等列口径未核验(疑似公告日行情涨跌幅),不收录,也不要用本能力推断「公告后股价反应」。direction 参数与输出都用 ASCII increase / decrease(上游原文是「增持」「减持」)。排序键 NOTICE_DATE 降序 + SECURITY_CODE 升序 + HOLDER_NAME + START_DATE + END_DATE 升序,已实测唯一(2,969 行 / 6 页无重复、无漏行)。空结果=区间内没有增减持公告,不是失败。',
|
|
2226
|
+
inputSchema: holderChangeInput, outputSchema: datacenterOutput(holderChangeRow), paginated: true, rowShape: { rowKey: 'item' },
|
|
2227
|
+
allowed: ['ticker', 'start_date', 'end_date', 'direction', 'page', 'size'], normalize: normalizeHolderChange, execute: executeHolderChange,
|
|
2228
|
+
}),
|
|
2229
|
+
createSource({
|
|
2230
|
+
capability: 'eastmoney_buyback', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_buyback',
|
|
2231
|
+
summary: '东财回购方案与实施进度(方案一行)',
|
|
2232
|
+
description: '按数据更新日区间 / 个股 / 进度分页获取东方财富回购方案(RPTA_WEB_GETHGLIST_NEW,一个方案一行、只给当前状态,没有历史轨迹)。实测 2026-11-22:全表 5,846 行 / 1,949 页;进度码分布 001 董事会预案 115、002 股东大会通过 15、003 股东大会否决 8、004 实施中 445、005 停止实施 125、006 完成实施 5,074、007 63、008 1。⛔ 上游 007/008 两个进度码连东财页面都不给名字,本能力 progress=null、progress_code 保留原码,不猜语义。⛔ 时间轴是三个不同字段,别混:参数 start_date/end_date 过滤的是 UPD(数据更新日,也是排序键,输出 update_date / update_date_ms);plan_notice_date 来自上游 UPDATEDATE(方案相关公告日,实测 001 预案行等于更新日、004 行早于最新进展公告)、latest_notice_date 来自 NOTICEDATE(最新一次进展公告日,001/007 行为 null)、finish_date 来自 FINISHDATE(完成日)。量纲(实测 600519 精确对上):股数为股、金额为元——plan_shares_lower/upper(REPURNUMLOWER/REPURNUMCAP,804,864 / 1,609,727 股)、plan_amount_lower/upper(15 亿 / 30 亿元)、done_shares/done_amount(已回购 2,188,614 股 / 2,999,933,749.57 元)、price_cap 回购价格上限(元)、done_price_low/high 已回购价格区间(元)。plan_pct_total_lower/upper 是占总股本%的下限/上限(实测 804,864/1,250,081,601 = 0.0644 与 ZSZXX 0.06427 对上),实测 635/5,846 行这两列为 null(老方案上游不填)。done_* 在未开始实施的方案上为 null(实测 280 行两者皆空),null 不等于 0。progress 参数用 6 个中文名(对应 001–006),无法用 007/008 过滤,但省略 progress 时会返回它们。objective 是上游原文(如「用于依法注销减少注册资本」),不改写。排序键 UPD 降序 + DIM_SCODE 升序 + REPURCODE 升序,已实测唯一(5,846 行 / 12 页无重复方案、无重复行)。空结果=区间内没有回购记录,不是失败。',
|
|
2233
|
+
inputSchema: buybackInput, outputSchema: datacenterOutput(buybackRow), paginated: true, rowShape: { rowKey: 'item' },
|
|
2234
|
+
allowed: ['ticker', 'start_date', 'end_date', 'progress', 'page', 'size'], normalize: normalizeBuyback, execute: executeBuyback,
|
|
2235
|
+
}),
|
|
2236
|
+
createSource({
|
|
2237
|
+
capability: 'eastmoney_pledge', cacheMaxAgeMs: 3_600_000, name: 'get_eastmoney_pledge',
|
|
2238
|
+
summary: '东财股权质押周度统计(仅沪深)',
|
|
2239
|
+
description: '获取东方财富股权质押周度统计(RPT_CSDC_LIST,原始来源中国结算,实测 2026-11-22 全表 1,655,524 行、最新统计日 2026-11-20(周五)2,265 只沪深股票)。⛔ **只覆盖沪深、没有北交所**:实测最新统计日 2,265 行里没有任何 4x/8x/92x 北交所代码,用 920982 查上游直接 9201 空结果;所以本能力对北交所 ticker 在参数层直接拒绝,不返回空表冒充「没有质押」(空表说明不了没有质押,只说明本表不覆盖)。不传 ticker 也不传日期时=最近一个统计日全市场:内部先查一次最新 TRADE_DATE 再按当天过滤,避免翻页滑到上一周。时间轴 stats_date 是统计日(TRADE_DATE,按周发布、通常周五;给 stats_date_ms),不是公告日。量纲(实测 301015 精确对上):pledged_shares_10k 是质押股数(万股,REPURCHASE_BALANCE,18,522.06 万股 ÷ 总股本 = pledge_ratio_pct 35.24% 自洽)、pledged_market_cap_10k 是质押市值(万元,411,374.9526 万元 ≈ 41.1 亿元)、pledge_ratio_pct 质押股数占总股本%。unrestricted_pledged_10k / restricted_pledged_10k 是无限售 / 有限售质押股数(万股),实测 2,265 行全部满足「无限售 + 限售 = 合计」,代码里有该断言,不成立即报上游结构变化。pledge_deal_num 是上游 PLEDGE_DEAL_NUM(笔数口径未独立核验,只做同列相对比较)。industry 是东财行业名原文,空则 null。排序键 TRADE_DATE 降序 + PLEDGE_RATIO 降序 + SECURITY_CODE 升序,已实测唯一(2,265 行 / 5 页无重复、无漏行)——⛔ 只按 PLEDGE_RATIO 排序不唯一,上游曾因此翻页重复 1 行、漏 1 行。空结果=区间里没有统计日(按周发布、通常周五),不是失败。',
|
|
2240
|
+
inputSchema: pledgeInput, outputSchema: datacenterOutput(pledgeRow), paginated: true, rowShape: { rowKey: 'item' },
|
|
2241
|
+
allowed: ['ticker', 'start_date', 'end_date', 'page', 'size'], normalize: normalizePledge, execute: executePledge,
|
|
2242
|
+
}),
|
|
2243
|
+
createSource({
|
|
2244
|
+
capability: 'eastmoney_new_stock', cacheMaxAgeMs: 3_600_000, name: 'get_eastmoney_new_stock',
|
|
2245
|
+
summary: '东财新股申购与发行日历(含未申购排期)',
|
|
2246
|
+
description: '按申购日区间 / 个股分页获取东方财富新股申购与发行日历(RPTA_APP_IPOAPPLY,含尚未申购的排期与已上市新股)。实测 2026-11-22:全表 5,642 行、2026 年 139 只、覆盖三个交易所(上交所 / 深交所 / 北交所)。时间轴:apply_date 是申购日(APPLY_DATE,start_date/end_date 过滤口径,给 apply_date_ms)、ballot_date 是摇号中签日(BALLOT_NUM_DATE)、pay_date 是缴款日(BALLOT_PAY_DATE)、listing_date 是上市日(未上市为 null)。exchange 是 TRADE_MARKET 原文(上海证券交易所 / 深圳证券交易所 / 北京证券交易所),board 取 MARKET(如「上交所科创板」「深交所创业板」)——北交所行 MARKET 为 null、只有 MARKET_TYPE_NEW=北交所,故 board 先取 MARKET 再退回 MARKET_TYPE_NEW,否则北交所行会丢板块。量纲(实测对得上):issue_price 元/股、issue_shares_10k 发行股数(万股,ISSUE_NUM;301661 1375 万股与网上 2,887,500 + 网下 6,737,500 股、战略配售合计自洽)、online_shares 网上发行股数(股)、apply_upper_shares 网上申购上限(股)、win_rate_pct 网上中签率%、issue_pe 发行后市盈率、industry_pe 行业市盈率、first_close_price / first_close_change_pct 上市首日收盘价(元)与首日涨跌幅(%)——实测 5,637 行里 5,629 行满足 close = price×(1+chg/100),8 行例外是 B 股 / 异常历史行,故两列原值给出、不做二次换算。⛔ ISSUE_PRICE 在定价前是 null(实测全表仅 2 行,均为未上市新股),上游在相邻价格列用 0 占位,本能力把 0 也当 null(未定价),不要把 null 读成 0 元发行。⛔ TOP_APPLY_MARKETCAP 单位虽是万元但口径跨市场不同:沪深是「顶格申购需配市值」(实测 688845 9000 股 → 9 万元、301661 2500 股 → 2.5 万元),北交所是「顶格申购需缴款金额」(实测 920067 708,300 股 × 23.52 元 = 1665.92 万元精确成立),禁止跨市场比较。win_rate_pct 实测全表 559 行为 null(未定价或未公布中签率),null 不是 0。排序键 APPLY_DATE 降序 + SECURITY_CODE 降序,已实测唯一(5,642 行 / 12 页无重复代码、无重复行)。空结果=区间内没有新股,不是失败。',
|
|
2247
|
+
inputSchema: newStockInput, outputSchema: datacenterOutput(newStockRow), paginated: true, rowShape: { rowKey: 'item' },
|
|
2248
|
+
allowed: ['ticker', 'start_date', 'end_date', 'page', 'size'], normalize: normalizeNewStock, execute: executeNewStock,
|
|
2249
|
+
}),
|
|
2250
|
+
...createEastmoneyLimitPoolSources(),
|
|
2251
|
+
];
|
|
2252
|
+
}
|
|
2253
|
+
/**
|
|
2254
|
+
* push2ex limit pools, dycalchis price anomalies, emappdata stock hot concepts. All three hosts sit
|
|
2255
|
+
* outside the push2 egress path; every call still goes through the shared eastmoney client or the
|
|
2256
|
+
* process-wide throttle (no private fetch/limiter).
|
|
2257
|
+
*/
|
|
2258
|
+
const PUSH2EX_BASE_URL = 'https://push2ex.eastmoney.com';
|
|
2259
|
+
const PUSH2EX_UT = '7eea3edcaed734bea9cbfc24409ed989';
|
|
2260
|
+
const PUSH2EX_REFERER = 'https://quote.eastmoney.com/';
|
|
2261
|
+
/** Upstream caps pagesize at 10k; a pool must be taken in one page because page boundaries are not stable. */
|
|
2262
|
+
const PUSH2EX_PAGE_SIZE = 10_000;
|
|
2263
|
+
const ANOMALY_BASE_URL = 'https://dycalchis.eastmoney.com/price-anomaly';
|
|
2264
|
+
/** Six fixed H5 params: without `team=h5` (and the rest) upstream answers {"result":1001,"msg":"unknow team"}. */
|
|
2265
|
+
const ANOMALY_H5_PARAMS = { team: 'h5', product: 'EastMoney', client: 'WAP', version: '9001', name: 'WAP', user: '123' };
|
|
2266
|
+
const ANOMALY_LIST_DEFAULT_SIZE = 200;
|
|
2267
|
+
const ANOMALY_COUNT_DEFAULT_SIZE = 50;
|
|
2268
|
+
/** Count-endpoint sorting is applied locally: upstream ignores sortKey/sortDir (5 combinations, identical order). */
|
|
2269
|
+
const ANOMALY_SORT_FIELDS = { times: 'anomaly_times', deviation_pct: 'deviation_pct', change_pct: 'change_pct', price: 'price', window_days: 'window_days' };
|
|
2270
|
+
/** 12 rule names taken from the upstream frontend map; unknown codes stay null (no invented text). */
|
|
2271
|
+
const ANOMALY_RULES = {
|
|
2272
|
+
1: '主板连续10个交易日内4次出现同向异常波动',
|
|
2273
|
+
2: '创业板连续10个交易日内3次出现同向异常波动',
|
|
2274
|
+
3: '科创板连续10个交易日内3次出现同向异常波动',
|
|
2275
|
+
4: '连续十个交易日内日收盘价涨跌幅偏离值累计达到+100%',
|
|
2276
|
+
5: '连续十个交易日内日收盘价涨跌幅偏离值累计达到-50%',
|
|
2277
|
+
6: '连续三十个交易日内日收盘价涨跌幅偏离值累计达到+200%',
|
|
2278
|
+
7: '连续三十个交易日内日收盘价涨跌幅偏离值累计达到-70%',
|
|
2279
|
+
8: '北交所连续10个交易日内3次出现同向异常波动',
|
|
2280
|
+
40: '连续十个交易日内日收盘价涨跌幅偏离值累计达到+150%',
|
|
2281
|
+
50: '连续十个交易日内日收盘价涨跌幅偏离值累计达到-60%',
|
|
2282
|
+
60: '连续三十个交易日内日收盘价涨跌幅偏离值累计达到+300%',
|
|
2283
|
+
70: '连续三十个交易日内日收盘价涨跌幅偏离值累计达到-75%',
|
|
2284
|
+
};
|
|
2285
|
+
const HOT_CONCEPT_URL = 'https://emappdata.eastmoney.com/stockrank/getHotStockRankList';
|
|
2286
|
+
const HOT_CONCEPT_BODY = { appId: 'appId01', globalId: '786e4c21-70dc-435a-93bb-38' };
|
|
2287
|
+
/** Beijing calendar day. push2ex silently clamps any date later than the latest trading day onto that day. */
|
|
2288
|
+
function beijingToday() {
|
|
2289
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', {
|
|
2290
|
+
timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit',
|
|
2291
|
+
}).formatToParts(new Date()).map((part) => [part.type, part.value]));
|
|
2292
|
+
return `${parts.year}-${parts.month}-${parts.day}`;
|
|
2293
|
+
}
|
|
2294
|
+
/** `getJson` has no header slot; push2ex wants Referer, so this entry reuses the shared client and mirrors its classification. */
|
|
2295
|
+
async function getJsonWithHeaders(url, signal, context, headers) {
|
|
2296
|
+
let payload;
|
|
2297
|
+
try {
|
|
2298
|
+
payload = await sharedEastmoneyClient().fetchJson(url, { signal, headers });
|
|
2299
|
+
}
|
|
2300
|
+
catch (error) {
|
|
2301
|
+
if (error instanceof Error && error.name === 'AbortError')
|
|
2302
|
+
throw error;
|
|
2303
|
+
const status = error instanceof EastmoneyTransportError ? error.status : undefined;
|
|
2304
|
+
throw sourceError(status === undefined
|
|
2305
|
+
? `Eastmoney request failed for ${context}: ${error instanceof Error ? error.message : String(error)}`
|
|
2306
|
+
: `Eastmoney HTTP ${status} for ${context}`, status === 429 ? 'eastmoney_rate_limit' : 'eastmoney_http_error');
|
|
2307
|
+
}
|
|
2308
|
+
if (!isRecord(payload))
|
|
2309
|
+
throw sourceError(`Eastmoney ${context} returned a non-object response`, 'eastmoney_invalid_response');
|
|
2310
|
+
return payload;
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* emappdata only speaks POST with a JSON body and the shared client has no body slot, so this entry
|
|
2314
|
+
* uses the same process-wide throttle and repeats that client's abort/status/JSON classification.
|
|
2315
|
+
*/
|
|
2316
|
+
async function postJsonWithThrottle(url, body, signal, context) {
|
|
2317
|
+
let payload;
|
|
2318
|
+
try {
|
|
2319
|
+
payload = await sharedEastmoneyThrottle()(async () => {
|
|
2320
|
+
if (signal.aborted) {
|
|
2321
|
+
const error = new Error('eastmoney request aborted');
|
|
2322
|
+
error.name = 'AbortError';
|
|
2323
|
+
throw error;
|
|
2324
|
+
}
|
|
2325
|
+
const response = await globalThis.fetch(url, {
|
|
2326
|
+
method: 'POST',
|
|
2327
|
+
headers: { 'user-agent': 'Mozilla/5.0', 'content-type': 'application/json' },
|
|
2328
|
+
body: JSON.stringify(body),
|
|
2329
|
+
signal,
|
|
2330
|
+
});
|
|
2331
|
+
if (response.status >= 400) {
|
|
2332
|
+
const error = new Error(`eastmoney returned HTTP ${response.status}`);
|
|
2333
|
+
error.status = response.status;
|
|
2334
|
+
throw error;
|
|
2335
|
+
}
|
|
2336
|
+
return await response.json();
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
catch (error) {
|
|
2340
|
+
if (error instanceof Error && error.name === 'AbortError')
|
|
2341
|
+
throw error;
|
|
2342
|
+
const status = error?.status;
|
|
2343
|
+
const statusCode = typeof status === 'number' ? status : undefined;
|
|
2344
|
+
throw sourceError(statusCode === undefined
|
|
2345
|
+
? `Eastmoney request failed for ${context}: ${error instanceof Error ? error.message : String(error)}`
|
|
2346
|
+
: `Eastmoney HTTP ${statusCode} for ${context}`, statusCode === 429 ? 'eastmoney_rate_limit' : 'eastmoney_http_error');
|
|
2347
|
+
}
|
|
2348
|
+
if (!isRecord(payload))
|
|
2349
|
+
throw sourceError(`Eastmoney ${context} returned a non-object response`, 'eastmoney_invalid_response');
|
|
2350
|
+
return payload;
|
|
2351
|
+
}
|
|
2352
|
+
/** Row array of plain objects; a non-array or a non-object row is an upstream shape change. */
|
|
2353
|
+
function poolRowArray(value, context) {
|
|
2354
|
+
if (!Array.isArray(value))
|
|
2355
|
+
throw sourceError(`Eastmoney ${context} is missing its row array`, 'eastmoney_invalid_response');
|
|
2356
|
+
const rows = [];
|
|
2357
|
+
for (const row of value) {
|
|
2358
|
+
if (!isRecord(row))
|
|
2359
|
+
throw sourceError(`Eastmoney ${context} contains a non-object row`, 'eastmoney_invalid_response');
|
|
2360
|
+
rows.push(row);
|
|
2361
|
+
}
|
|
2362
|
+
return rows;
|
|
2363
|
+
}
|
|
2364
|
+
function poolNumber(value, field, context) {
|
|
2365
|
+
if (value === undefined || value === null || value === '')
|
|
2366
|
+
return null;
|
|
2367
|
+
const parsed = numberOrNull(value);
|
|
2368
|
+
if (parsed === null)
|
|
2369
|
+
throw sourceError(`Eastmoney ${context} row has an unreadable ${field}=${String(value)}`, 'eastmoney_invalid_response');
|
|
2370
|
+
return parsed;
|
|
2371
|
+
}
|
|
2372
|
+
function poolInteger(value, field, context) {
|
|
2373
|
+
const parsed = poolNumber(value, field, context);
|
|
2374
|
+
if (parsed !== null && !Number.isSafeInteger(parsed))
|
|
2375
|
+
throw sourceError(`Eastmoney ${context} row has a non-integer ${field}=${String(value)}`, 'eastmoney_invalid_response');
|
|
2376
|
+
return parsed;
|
|
2377
|
+
}
|
|
2378
|
+
/** Upstream pool prices are thousandths of a yuan (27710 = 27.71). A non-integer here means a unit change. */
|
|
2379
|
+
function poolPrice(value, field, context) {
|
|
2380
|
+
const parsed = poolNumber(value, field, context);
|
|
2381
|
+
if (parsed === null)
|
|
2382
|
+
return null;
|
|
2383
|
+
if (!Number.isSafeInteger(parsed))
|
|
2384
|
+
throw sourceError(`Eastmoney ${context} row has a non-integer ${field}=${String(value)}; pool prices are x1000`, 'eastmoney_invalid_response');
|
|
2385
|
+
return parsed / 1000;
|
|
2386
|
+
}
|
|
2387
|
+
/** Seal times are HHMMSS integers (92501 = 09:25:01), not Unix seconds: the two must never be mixed. */
|
|
2388
|
+
function poolSealTime(value, field, context) {
|
|
2389
|
+
const parsed = poolInteger(value, field, context);
|
|
2390
|
+
if (parsed === null)
|
|
2391
|
+
return null;
|
|
2392
|
+
if (parsed < 0 || parsed > 235959)
|
|
2393
|
+
throw sourceError(`Eastmoney ${context} row has an out-of-range ${field}=${String(value)} (expected HHMMSS)`, 'eastmoney_invalid_response');
|
|
2394
|
+
const text = String(parsed).padStart(6, '0');
|
|
2395
|
+
const hour = Number(text.slice(0, 2));
|
|
2396
|
+
const minute = Number(text.slice(2, 4));
|
|
2397
|
+
const second = Number(text.slice(4, 6));
|
|
2398
|
+
if (hour > 23 || minute > 59 || second > 59)
|
|
2399
|
+
throw sourceError(`Eastmoney ${context} row has an invalid clock time ${field}=${String(value)}`, 'eastmoney_invalid_response');
|
|
2400
|
+
return `${text.slice(0, 2)}:${text.slice(2, 4)}:${text.slice(4, 6)}`;
|
|
2401
|
+
}
|
|
2402
|
+
/** zttj = { days, ct }: upstream frontend renders ct/days (n/m = n limit-ups in m days) -> "N天M板". */
|
|
2403
|
+
function poolZtStat(value, context) {
|
|
2404
|
+
if (value === undefined || value === null)
|
|
2405
|
+
return { days: null, boards: null, text: null };
|
|
2406
|
+
if (!isRecord(value))
|
|
2407
|
+
throw sourceError(`Eastmoney ${context} row has a malformed zttj`, 'eastmoney_invalid_response');
|
|
2408
|
+
const days = poolInteger(value.days, 'zttj.days', context);
|
|
2409
|
+
const boards = poolInteger(value.ct, 'zttj.ct', context);
|
|
2410
|
+
if (days === null || boards === null)
|
|
2411
|
+
throw sourceError(`Eastmoney ${context} row has an incomplete zttj`, 'eastmoney_invalid_response');
|
|
2412
|
+
return { days, boards, text: `${days}天${boards}板` };
|
|
2413
|
+
}
|
|
2414
|
+
/** m is 1 for SH and 0 for both SZ and BSE, so the market is derived from the code range with the shared helper. */
|
|
2415
|
+
function poolBaseRow(raw, context, seen) {
|
|
2416
|
+
const code = String(raw.c ?? '');
|
|
2417
|
+
if (!/^\d{6}$/u.test(code))
|
|
2418
|
+
throw sourceError(`Eastmoney ${context} row has an unusable code ${code || '(empty)'}`, 'eastmoney_invalid_response');
|
|
2419
|
+
const identity = normalizeEastmoneyAshareIdentity(code);
|
|
2420
|
+
const marketCode = poolInteger(raw.m, 'm', context);
|
|
2421
|
+
const expectedMarketCode = identity.eastmoney_market === 'SH' ? 1 : 0;
|
|
2422
|
+
if (marketCode !== expectedMarketCode) {
|
|
2423
|
+
throw sourceError(`Eastmoney ${context} row ${code} carries market code ${String(raw.m)} but its code range is ${identity.eastmoney_market}`, 'eastmoney_invalid_response');
|
|
2424
|
+
}
|
|
2425
|
+
if (seen.has(code))
|
|
2426
|
+
throw sourceError(`Eastmoney ${context} contains duplicate code ${code}; a pool is one row per stock`, 'eastmoney_invalid_response');
|
|
2427
|
+
seen.add(code);
|
|
2428
|
+
const name = textOrNull(raw.n);
|
|
2429
|
+
if (name === null || name.trim().length === 0)
|
|
2430
|
+
throw sourceError(`Eastmoney ${context} row ${code} has no name`, 'eastmoney_invalid_response');
|
|
2431
|
+
return { thscode: identity.thscode, code, name, market: identity.eastmoney_market };
|
|
2432
|
+
}
|
|
2433
|
+
function parseLimitUpRow(raw, context, seen) {
|
|
2434
|
+
const base = poolBaseRow(raw, context, seen);
|
|
2435
|
+
const stat = poolZtStat(raw.zttj, context);
|
|
2436
|
+
return {
|
|
2437
|
+
...base,
|
|
2438
|
+
price: poolPrice(raw.p, 'p', context),
|
|
2439
|
+
change_pct: poolNumber(raw.zdp, 'zdp', context),
|
|
2440
|
+
amount: poolNumber(raw.amount, 'amount', context),
|
|
2441
|
+
float_market_cap: poolNumber(raw.ltsz, 'ltsz', context),
|
|
2442
|
+
total_market_cap: poolNumber(raw.tshare, 'tshare', context),
|
|
2443
|
+
turnover_rate_pct: poolNumber(raw.hs, 'hs', context),
|
|
2444
|
+
limit_days: poolInteger(raw.lbc, 'lbc', context),
|
|
2445
|
+
first_seal: poolSealTime(raw.fbt, 'fbt', context),
|
|
2446
|
+
last_seal: poolSealTime(raw.lbt, 'lbt', context),
|
|
2447
|
+
seal_fund: poolNumber(raw.fund, 'fund', context),
|
|
2448
|
+
break_times: poolInteger(raw.zbc, 'zbc', context),
|
|
2449
|
+
industry: textOrNull(raw.hybk),
|
|
2450
|
+
zt_stat: stat.text,
|
|
2451
|
+
zt_stat_days: stat.days,
|
|
2452
|
+
zt_stat_boards: stat.boards,
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
function parseLimitBreakRow(raw, context, seen) {
|
|
2456
|
+
const base = poolBaseRow(raw, context, seen);
|
|
2457
|
+
const stat = poolZtStat(raw.zttj, context);
|
|
2458
|
+
return {
|
|
2459
|
+
...base,
|
|
2460
|
+
price: poolPrice(raw.p, 'p', context),
|
|
2461
|
+
limit_price: poolPrice(raw.ztp, 'ztp', context),
|
|
2462
|
+
change_pct: poolNumber(raw.zdp, 'zdp', context),
|
|
2463
|
+
amount: poolNumber(raw.amount, 'amount', context),
|
|
2464
|
+
float_market_cap: poolNumber(raw.ltsz, 'ltsz', context),
|
|
2465
|
+
total_market_cap: poolNumber(raw.tshare, 'tshare', context),
|
|
2466
|
+
turnover_rate_pct: poolNumber(raw.hs, 'hs', context),
|
|
2467
|
+
first_seal: poolSealTime(raw.fbt, 'fbt', context),
|
|
2468
|
+
break_times: poolInteger(raw.zbc, 'zbc', context),
|
|
2469
|
+
amplitude_pct: poolNumber(raw.zf, 'zf', context),
|
|
2470
|
+
speed_pct: poolNumber(raw.zs, 'zs', context),
|
|
2471
|
+
industry: textOrNull(raw.hybk),
|
|
2472
|
+
zt_stat: stat.text,
|
|
2473
|
+
zt_stat_days: stat.days,
|
|
2474
|
+
zt_stat_boards: stat.boards,
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2477
|
+
function parseLimitDownRow(raw, context, seen) {
|
|
2478
|
+
const base = poolBaseRow(raw, context, seen);
|
|
2479
|
+
return {
|
|
2480
|
+
...base,
|
|
2481
|
+
price: poolPrice(raw.p, 'p', context),
|
|
2482
|
+
change_pct: poolNumber(raw.zdp, 'zdp', context),
|
|
2483
|
+
amount: poolNumber(raw.amount, 'amount', context),
|
|
2484
|
+
float_market_cap: poolNumber(raw.ltsz, 'ltsz', context),
|
|
2485
|
+
total_market_cap: poolNumber(raw.tshare, 'tshare', context),
|
|
2486
|
+
pe: poolNumber(raw.pe, 'pe', context),
|
|
2487
|
+
turnover_rate_pct: poolNumber(raw.hs, 'hs', context),
|
|
2488
|
+
seal_fund: poolNumber(raw.fund, 'fund', context),
|
|
2489
|
+
last_seal: poolSealTime(raw.lbt, 'lbt', context),
|
|
2490
|
+
board_amount: poolNumber(raw.fba, 'fba', context),
|
|
2491
|
+
limit_down_days: poolInteger(raw.days, 'days', context),
|
|
2492
|
+
open_times: poolInteger(raw.oc, 'oc', context),
|
|
2493
|
+
industry: textOrNull(raw.hybk),
|
|
2494
|
+
};
|
|
2495
|
+
}
|
|
2496
|
+
/** Yesterday pool: `yfbt`/`ylbc` are yesterday-scoped columns; never feed them through the limit-up parser. */
|
|
2497
|
+
function parseYesterdayLimitUpRow(raw, context, seen) {
|
|
2498
|
+
const base = poolBaseRow(raw, context, seen);
|
|
2499
|
+
const stat = poolZtStat(raw.zttj, context);
|
|
2500
|
+
return {
|
|
2501
|
+
...base,
|
|
2502
|
+
price: poolPrice(raw.p, 'p', context),
|
|
2503
|
+
limit_price: poolPrice(raw.ztp, 'ztp', context),
|
|
2504
|
+
change_pct: poolNumber(raw.zdp, 'zdp', context),
|
|
2505
|
+
amount: poolNumber(raw.amount, 'amount', context),
|
|
2506
|
+
float_market_cap: poolNumber(raw.ltsz, 'ltsz', context),
|
|
2507
|
+
total_market_cap: poolNumber(raw.tshare, 'tshare', context),
|
|
2508
|
+
turnover_rate_pct: poolNumber(raw.hs, 'hs', context),
|
|
2509
|
+
amplitude_pct: poolNumber(raw.zf, 'zf', context),
|
|
2510
|
+
speed_pct: poolNumber(raw.zs, 'zs', context),
|
|
2511
|
+
yesterday_first_seal: poolSealTime(raw.yfbt, 'yfbt', context),
|
|
2512
|
+
yesterday_limit_days: poolInteger(raw.ylbc, 'ylbc', context),
|
|
2513
|
+
industry: textOrNull(raw.hybk),
|
|
2514
|
+
zt_stat: stat.text,
|
|
2515
|
+
zt_stat_days: stat.days,
|
|
2516
|
+
zt_stat_boards: stat.boards,
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
const limitPoolEnvelope = (row) => ({
|
|
2520
|
+
type: 'object',
|
|
2521
|
+
properties: {
|
|
2522
|
+
item: { type: 'array', items: row },
|
|
2523
|
+
trade_date: { type: 'string' },
|
|
2524
|
+
server_latest_trade_date: nullableString,
|
|
2525
|
+
requested_date_clamped: { type: 'boolean' },
|
|
2526
|
+
available: { type: 'boolean' },
|
|
2527
|
+
row_count: { type: 'integer' },
|
|
2528
|
+
upstream_total: { type: 'integer' },
|
|
2529
|
+
note: nullableString,
|
|
2530
|
+
},
|
|
2531
|
+
required: ['item', 'trade_date', 'server_latest_trade_date', 'requested_date_clamped', 'available', 'row_count', 'upstream_total', 'note'],
|
|
2532
|
+
additionalProperties: false,
|
|
2533
|
+
});
|
|
2534
|
+
async function executeLimitPool(spec, params, signal) {
|
|
2535
|
+
const tradeDate = String(params.trade_date);
|
|
2536
|
+
const url = new URL(`${PUSH2EX_BASE_URL}/${spec.endpoint}`);
|
|
2537
|
+
url.searchParams.set('ut', PUSH2EX_UT);
|
|
2538
|
+
url.searchParams.set('dpt', 'wz.ztzt');
|
|
2539
|
+
url.searchParams.set('Pageindex', '0');
|
|
2540
|
+
url.searchParams.set('pagesize', String(PUSH2EX_PAGE_SIZE));
|
|
2541
|
+
url.searchParams.set('sort', spec.sort);
|
|
2542
|
+
url.searchParams.set('date', tradeDate.replaceAll('-', ''));
|
|
2543
|
+
const payload = await getJsonWithHeaders(url.toString(), signal, spec.context, { referer: PUSH2EX_REFERER });
|
|
2544
|
+
if (Number(payload.rc) !== 0) {
|
|
2545
|
+
throw sourceError(`Eastmoney ${spec.context} rejected trade_date ${tradeDate}: rc=${String(payload.rc)}; upstream needs date=YYYYMMDD and answers rc=102/null when it is missing or unreadable`, 'eastmoney_upstream_error');
|
|
2546
|
+
}
|
|
2547
|
+
if (!isRecord(payload.data))
|
|
2548
|
+
throw sourceError(`Eastmoney ${spec.context} returned rc=0 without a data object`, 'eastmoney_invalid_response');
|
|
2549
|
+
const data = payload.data;
|
|
2550
|
+
const total = poolInteger(data.tc, 'tc', spec.context);
|
|
2551
|
+
if (total === null)
|
|
2552
|
+
throw sourceError(`Eastmoney ${spec.context} returned no total (tc)`, 'eastmoney_invalid_response');
|
|
2553
|
+
const rawRows = poolRowArray(data.pool, spec.context);
|
|
2554
|
+
if (rawRows.length !== total) {
|
|
2555
|
+
throw sourceError(`Eastmoney ${spec.context} returned ${rawRows.length} of ${total} rows at pagesize=${PUSH2EX_PAGE_SIZE}; a partial pool is not served`, 'eastmoney_invalid_response');
|
|
2556
|
+
}
|
|
2557
|
+
const latest = compactDay(data.qdate);
|
|
2558
|
+
if (latest === null)
|
|
2559
|
+
throw sourceError(`Eastmoney ${spec.context} returned an unusable qdate ${String(data.qdate ?? '(missing)')}`, 'eastmoney_invalid_response');
|
|
2560
|
+
const clamped = tradeDate > latest;
|
|
2561
|
+
const seen = new Set();
|
|
2562
|
+
const item = rawRows.map((raw) => spec.parse(raw, spec.context, seen));
|
|
2563
|
+
const available = item.length > 0;
|
|
2564
|
+
const note = available
|
|
2565
|
+
? (clamped ? `请求日 ${tradeDate} 晚于上游最近交易日 ${latest}:上游把日期夹到 ${latest},本批行属于 ${latest},不是请求日。` : null)
|
|
2566
|
+
: (clamped
|
|
2567
|
+
? `请求日 ${tradeDate} 晚于上游最近交易日 ${latest}:上游夹到 ${latest},而该日池为空(tc=0)。`
|
|
2568
|
+
: `上游在 ${tradeDate} 返回 tc=0 的空池(非交易日,或早于上游约 15 个交易日的保留窗口;服务器最近交易日 ${latest})。空池不是取数失败。`);
|
|
2569
|
+
return {
|
|
2570
|
+
data: { item, trade_date: tradeDate, server_latest_trade_date: latest, requested_date_clamped: clamped, available, row_count: item.length, upstream_total: total, note },
|
|
2571
|
+
schema: limitPoolEnvelope(spec.row),
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
function normalizeLimitPool(params) {
|
|
2575
|
+
assertKnown(params, ['trade_date']);
|
|
2576
|
+
const trade_date = date(params.trade_date, 'trade_date');
|
|
2577
|
+
if (trade_date > beijingToday()) {
|
|
2578
|
+
throw new Error(`trade_date ${trade_date} is in the future (Beijing today is ${beijingToday()}); upstream would silently serve the latest trading day, so it is rejected here`);
|
|
2579
|
+
}
|
|
2580
|
+
return { trade_date };
|
|
2581
|
+
}
|
|
2582
|
+
const limitPoolInput = {
|
|
2583
|
+
type: 'object',
|
|
2584
|
+
properties: {
|
|
2585
|
+
trade_date: { type: 'string', description: '交易日 YYYY-MM-DD(北京时间)。必填:上游省略 date 直接 rc=102/data=null,没有「最新」默认;今天或更早都接受,未来日期在参数层拒绝' },
|
|
2586
|
+
},
|
|
2587
|
+
required: ['trade_date'],
|
|
2588
|
+
additionalProperties: false,
|
|
2589
|
+
};
|
|
2590
|
+
const limitUpRow = {
|
|
2591
|
+
type: 'object',
|
|
2592
|
+
properties: {
|
|
2593
|
+
thscode: { type: 'string' }, code: { type: 'string' }, name: { type: 'string' }, market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] },
|
|
2594
|
+
price: nullableNumber, change_pct: nullableNumber, amount: nullableNumber,
|
|
2595
|
+
float_market_cap: nullableNumber, total_market_cap: nullableNumber, turnover_rate_pct: nullableNumber,
|
|
2596
|
+
limit_days: nullableNumber, first_seal: nullableString, last_seal: nullableString,
|
|
2597
|
+
seal_fund: nullableNumber, break_times: nullableNumber, industry: nullableString,
|
|
2598
|
+
zt_stat: nullableString, zt_stat_days: nullableNumber, zt_stat_boards: nullableNumber,
|
|
2599
|
+
},
|
|
2600
|
+
required: ['thscode', 'code', 'name', 'market', 'price', 'change_pct', 'amount', 'float_market_cap', 'total_market_cap', 'turnover_rate_pct', 'limit_days', 'first_seal', 'last_seal', 'seal_fund', 'break_times', 'industry', 'zt_stat', 'zt_stat_days', 'zt_stat_boards'],
|
|
2601
|
+
additionalProperties: false,
|
|
2602
|
+
};
|
|
2603
|
+
const limitBreakRow = {
|
|
2604
|
+
type: 'object',
|
|
2605
|
+
properties: {
|
|
2606
|
+
thscode: { type: 'string' }, code: { type: 'string' }, name: { type: 'string' }, market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] },
|
|
2607
|
+
price: nullableNumber, limit_price: nullableNumber, change_pct: nullableNumber, amount: nullableNumber,
|
|
2608
|
+
float_market_cap: nullableNumber, total_market_cap: nullableNumber, turnover_rate_pct: nullableNumber,
|
|
2609
|
+
first_seal: nullableString, break_times: nullableNumber, amplitude_pct: nullableNumber, speed_pct: nullableNumber,
|
|
2610
|
+
industry: nullableString, zt_stat: nullableString, zt_stat_days: nullableNumber, zt_stat_boards: nullableNumber,
|
|
2611
|
+
},
|
|
2612
|
+
required: ['thscode', 'code', 'name', 'market', 'price', 'limit_price', 'change_pct', 'amount', 'float_market_cap', 'total_market_cap', 'turnover_rate_pct', 'first_seal', 'break_times', 'amplitude_pct', 'speed_pct', 'industry', 'zt_stat', 'zt_stat_days', 'zt_stat_boards'],
|
|
2613
|
+
additionalProperties: false,
|
|
2614
|
+
};
|
|
2615
|
+
const limitDownRow = {
|
|
2616
|
+
type: 'object',
|
|
2617
|
+
properties: {
|
|
2618
|
+
thscode: { type: 'string' }, code: { type: 'string' }, name: { type: 'string' }, market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] },
|
|
2619
|
+
price: nullableNumber, change_pct: nullableNumber, amount: nullableNumber,
|
|
2620
|
+
float_market_cap: nullableNumber, total_market_cap: nullableNumber, pe: nullableNumber, turnover_rate_pct: nullableNumber,
|
|
2621
|
+
seal_fund: nullableNumber, last_seal: nullableString, board_amount: nullableNumber,
|
|
2622
|
+
limit_down_days: nullableNumber, open_times: nullableNumber, industry: nullableString,
|
|
2623
|
+
},
|
|
2624
|
+
required: ['thscode', 'code', 'name', 'market', 'price', 'change_pct', 'amount', 'float_market_cap', 'total_market_cap', 'pe', 'turnover_rate_pct', 'seal_fund', 'last_seal', 'board_amount', 'limit_down_days', 'open_times', 'industry'],
|
|
2625
|
+
additionalProperties: false,
|
|
2626
|
+
};
|
|
2627
|
+
const yesterdayLimitUpRow = {
|
|
2628
|
+
type: 'object',
|
|
2629
|
+
properties: {
|
|
2630
|
+
thscode: { type: 'string' }, code: { type: 'string' }, name: { type: 'string' }, market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] },
|
|
2631
|
+
price: nullableNumber, limit_price: nullableNumber, change_pct: nullableNumber, amount: nullableNumber,
|
|
2632
|
+
float_market_cap: nullableNumber, total_market_cap: nullableNumber, turnover_rate_pct: nullableNumber,
|
|
2633
|
+
amplitude_pct: nullableNumber, speed_pct: nullableNumber,
|
|
2634
|
+
yesterday_first_seal: nullableString, yesterday_limit_days: nullableNumber, industry: nullableString,
|
|
2635
|
+
zt_stat: nullableString, zt_stat_days: nullableNumber, zt_stat_boards: nullableNumber,
|
|
2636
|
+
},
|
|
2637
|
+
required: ['thscode', 'code', 'name', 'market', 'price', 'limit_price', 'change_pct', 'amount', 'float_market_cap', 'total_market_cap', 'turnover_rate_pct', 'amplitude_pct', 'speed_pct', 'yesterday_first_seal', 'yesterday_limit_days', 'industry', 'zt_stat', 'zt_stat_days', 'zt_stat_boards'],
|
|
2638
|
+
additionalProperties: false,
|
|
2639
|
+
};
|
|
2640
|
+
const LIMIT_UP_POOL_SPEC = { context: 'limit-up pool', endpoint: 'getTopicZTPool', sort: 'fbt:asc', row: limitUpRow, parse: parseLimitUpRow };
|
|
2641
|
+
const LIMIT_BREAK_POOL_SPEC = { context: 'limit-break pool', endpoint: 'getTopicZBPool', sort: 'fbt:asc', row: limitBreakRow, parse: parseLimitBreakRow };
|
|
2642
|
+
const LIMIT_DOWN_POOL_SPEC = { context: 'limit-down pool', endpoint: 'getTopicDTPool', sort: 'fund:asc', row: limitDownRow, parse: parseLimitDownRow };
|
|
2643
|
+
const YESTERDAY_LIMIT_UP_POOL_SPEC = { context: 'yesterday limit-up pool', endpoint: 'getYesterdayZTPool', sort: 'zs:desc', row: yesterdayLimitUpRow, parse: parseYesterdayLimitUpRow };
|
|
2644
|
+
/** Market code only documents upstream column m; the market itself comes from the code range (m=0 is SZ and BJ). */
|
|
2645
|
+
function anomalyIdentity(raw, context) {
|
|
2646
|
+
const code = String(raw.c ?? '');
|
|
2647
|
+
if (!/^\d{6}$/u.test(code))
|
|
2648
|
+
throw sourceError(`Eastmoney ${context} row has an unusable code ${code || '(empty)'}`, 'eastmoney_invalid_response');
|
|
2649
|
+
const identity = normalizeEastmoneyAshareIdentity(code);
|
|
2650
|
+
const marketCode = poolInteger(raw.m, 'm', context);
|
|
2651
|
+
const expectedMarketCode = identity.eastmoney_market === 'SH' ? 1 : 0;
|
|
2652
|
+
if (marketCode !== null && marketCode !== expectedMarketCode) {
|
|
2653
|
+
throw sourceError(`Eastmoney ${context} row ${code} carries m=${marketCode} but its code range is ${identity.eastmoney_market} (m=0 covers SZ and BJ)`, 'eastmoney_invalid_response');
|
|
2654
|
+
}
|
|
2655
|
+
return { thscode: identity.thscode, code, market: identity.eastmoney_market, eastmoney_market_code: marketCode };
|
|
2656
|
+
}
|
|
2657
|
+
function anomalyName(raw, context, code) {
|
|
2658
|
+
const name = textOrNull(raw.n);
|
|
2659
|
+
if (name === null || name.trim().length === 0)
|
|
2660
|
+
throw sourceError(`Eastmoney ${context} row ${code} has no name`, 'eastmoney_invalid_response');
|
|
2661
|
+
return name;
|
|
2662
|
+
}
|
|
2663
|
+
function parseAnomalyListRow(raw, context) {
|
|
2664
|
+
const identity = anomalyIdentity(raw, context);
|
|
2665
|
+
const board = poolInteger(raw.s, 's', context);
|
|
2666
|
+
const rule = poolInteger(raw.e, 'e', context);
|
|
2667
|
+
// Frontend map: s==6 takes the stricter e*10 tier (4->40 .. 7->70); no s=6 sample observed yet.
|
|
2668
|
+
const ruleCode = rule === null ? null : (board === 6 && rule >= 4 && rule <= 7 ? rule * 10 : rule);
|
|
2669
|
+
const status = poolInteger(raw.o, 'o', context);
|
|
2670
|
+
return {
|
|
2671
|
+
...identity,
|
|
2672
|
+
name: anomalyName(raw, context, String(identity.code)),
|
|
2673
|
+
board_code: board,
|
|
2674
|
+
rule_code: ruleCode,
|
|
2675
|
+
rule: ruleCode === null ? null : (ANOMALY_RULES[ruleCode] ?? null),
|
|
2676
|
+
change_pct: poolNumber(raw.a, 'a', context),
|
|
2677
|
+
change_target_pct: poolNumber(raw.t, 't', context),
|
|
2678
|
+
deviation_pct: poolNumber(raw.x, 'x', context),
|
|
2679
|
+
window_days: poolInteger(raw.d, 'd', context),
|
|
2680
|
+
// o=2 is the upstream IS_HAPPEN "not today" value; anything else counts as today (frontend mapping).
|
|
2681
|
+
is_today: status === null ? null : status !== 2,
|
|
2682
|
+
status_code: status,
|
|
2683
|
+
};
|
|
2684
|
+
}
|
|
2685
|
+
function parseAnomalyCountRow(raw, context) {
|
|
2686
|
+
const identity = anomalyIdentity(raw, context);
|
|
2687
|
+
// Count `t` is an integer anomaly count; list `t` is a float target change. Never share this parser.
|
|
2688
|
+
const times = poolInteger(raw.t, 't', context);
|
|
2689
|
+
return {
|
|
2690
|
+
...identity,
|
|
2691
|
+
name: anomalyName(raw, context, String(identity.code)),
|
|
2692
|
+
board_code: poolInteger(raw.s, 's', context),
|
|
2693
|
+
price: poolNumber(raw.p, 'p', context),
|
|
2694
|
+
change_pct: poolNumber(raw.a, 'a', context),
|
|
2695
|
+
anomaly_times: times,
|
|
2696
|
+
deviation_pct: poolNumber(raw.x, 'x', context),
|
|
2697
|
+
window_days: poolInteger(raw.d, 'd', context),
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2700
|
+
const anomalyListRow = {
|
|
2701
|
+
type: 'object',
|
|
2702
|
+
properties: {
|
|
2703
|
+
thscode: { type: 'string' }, code: { type: 'string' }, name: { type: 'string' }, market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] },
|
|
2704
|
+
eastmoney_market_code: nullableNumber, board_code: nullableNumber, rule_code: nullableNumber, rule: nullableString,
|
|
2705
|
+
change_pct: nullableNumber, change_target_pct: nullableNumber, deviation_pct: nullableNumber, window_days: nullableNumber,
|
|
2706
|
+
is_today: { oneOf: [{ type: 'boolean' }, { type: 'null' }] }, status_code: nullableNumber,
|
|
2707
|
+
},
|
|
2708
|
+
required: ['thscode', 'code', 'name', 'market', 'eastmoney_market_code', 'board_code', 'rule_code', 'rule', 'change_pct', 'change_target_pct', 'deviation_pct', 'window_days', 'is_today', 'status_code'],
|
|
2709
|
+
additionalProperties: false,
|
|
2710
|
+
};
|
|
2711
|
+
const anomalyCountRow = {
|
|
2712
|
+
type: 'object',
|
|
2713
|
+
properties: {
|
|
2714
|
+
thscode: { type: 'string' }, code: { type: 'string' }, name: { type: 'string' }, market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] },
|
|
2715
|
+
eastmoney_market_code: nullableNumber, board_code: nullableNumber,
|
|
2716
|
+
price: nullableNumber, change_pct: nullableNumber, anomaly_times: nullableNumber,
|
|
2717
|
+
deviation_pct: nullableNumber, window_days: nullableNumber,
|
|
2718
|
+
},
|
|
2719
|
+
required: ['thscode', 'code', 'name', 'market', 'eastmoney_market_code', 'board_code', 'price', 'change_pct', 'anomaly_times', 'deviation_pct', 'window_days'],
|
|
2720
|
+
additionalProperties: false,
|
|
2721
|
+
};
|
|
2722
|
+
const anomalyEnvelope = (row) => ({
|
|
2723
|
+
type: 'object',
|
|
2724
|
+
properties: {
|
|
2725
|
+
item: { type: 'array', items: row },
|
|
2726
|
+
data_date: { type: 'string' },
|
|
2727
|
+
requested_date: nullableString,
|
|
2728
|
+
requested_date_clamped: { type: 'boolean' },
|
|
2729
|
+
available: { type: 'boolean' },
|
|
2730
|
+
row_count: { type: 'integer' },
|
|
2731
|
+
pagination: {
|
|
2732
|
+
type: 'object',
|
|
2733
|
+
properties: { page: { type: 'integer' }, size: { type: 'integer' }, pages: { type: 'integer' } },
|
|
2734
|
+
required: ['page', 'size', 'pages'],
|
|
2735
|
+
additionalProperties: false,
|
|
2736
|
+
},
|
|
2737
|
+
note: nullableString,
|
|
2738
|
+
},
|
|
2739
|
+
required: ['item', 'data_date', 'requested_date', 'requested_date_clamped', 'available', 'row_count', 'pagination', 'note'],
|
|
2740
|
+
additionalProperties: false,
|
|
2741
|
+
});
|
|
2742
|
+
function anomalySortLetter(sortKey) {
|
|
2743
|
+
const letters = { times: 't', deviation_pct: 'x', change_pct: 'a', price: 'p', window_days: 'd' };
|
|
2744
|
+
return letters[sortKey] ?? sortKey;
|
|
2745
|
+
}
|
|
2746
|
+
async function executeAnomaly(kind, params, signal) {
|
|
2747
|
+
const context = kind === 'list' ? 'price anomaly list' : 'price anomaly count';
|
|
2748
|
+
const url = new URL(`${ANOMALY_BASE_URL}/${kind}`);
|
|
2749
|
+
for (const [key, value] of Object.entries(ANOMALY_H5_PARAMS))
|
|
2750
|
+
url.searchParams.set(key, value);
|
|
2751
|
+
url.searchParams.set('pageSize', String(params.page_size));
|
|
2752
|
+
url.searchParams.set('pageNo', String(params.page_no));
|
|
2753
|
+
if (params.date !== undefined)
|
|
2754
|
+
url.searchParams.set('date', String(params.date).replaceAll('-', ''));
|
|
2755
|
+
if (kind === 'count' && params.sort_key !== undefined) {
|
|
2756
|
+
url.searchParams.set('sortKey', anomalySortLetter(String(params.sort_key)));
|
|
2757
|
+
url.searchParams.set('sortDir', params.sort_dir === undefined ? 'desc' : String(params.sort_dir));
|
|
2758
|
+
}
|
|
2759
|
+
const payload = await getJson(url.toString(), signal, context);
|
|
2760
|
+
if (Number(payload.result) !== 0) {
|
|
2761
|
+
throw sourceError(`Eastmoney ${context} rejected the request: result=${String(payload.result)} msg=${JSON.stringify(payload.msg ?? '')}; result!=0 is an upstream rejection (1001=unknow team), never "no anomalies"`, 'eastmoney_upstream_error');
|
|
2762
|
+
}
|
|
2763
|
+
const dataDate = compactDay(payload.date);
|
|
2764
|
+
if (dataDate === null)
|
|
2765
|
+
throw sourceError(`Eastmoney ${context} returned no business date (date=${String(payload.date ?? '(missing)')})`, 'eastmoney_invalid_response');
|
|
2766
|
+
const rawRows = poolRowArray(payload.data, context);
|
|
2767
|
+
const pageCount = poolInteger(payload.count, 'count', context);
|
|
2768
|
+
if (pageCount !== null && pageCount !== rawRows.length) {
|
|
2769
|
+
throw sourceError(`Eastmoney ${context} reports count=${pageCount} but returned ${rawRows.length} rows (count is this page's row count)`, 'eastmoney_invalid_response');
|
|
2770
|
+
}
|
|
2771
|
+
const pages = poolInteger(payload.pages, 'pages', context);
|
|
2772
|
+
if (pages === null)
|
|
2773
|
+
throw sourceError(`Eastmoney ${context} returned no pages value`, 'eastmoney_invalid_response');
|
|
2774
|
+
const requestedDate = params.date === undefined ? null : String(params.date);
|
|
2775
|
+
let clamped = false;
|
|
2776
|
+
if (requestedDate !== null && requestedDate !== dataDate) {
|
|
2777
|
+
if (requestedDate > dataDate)
|
|
2778
|
+
clamped = true;
|
|
2779
|
+
else {
|
|
2780
|
+
throw sourceError(`Eastmoney ${context} only serves the latest business day (${dataDate}); requested ${requestedDate} is not available (upstream ignores the date parameter)`, 'eastmoney_no_anomaly_data');
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
const item = rawRows.map((raw) => (kind === 'list' ? parseAnomalyListRow(raw, context) : parseAnomalyCountRow(raw, context)));
|
|
2784
|
+
const sortKey = params.sort_key === undefined ? undefined : String(params.sort_key);
|
|
2785
|
+
if (kind === 'count' && sortKey !== undefined) {
|
|
2786
|
+
const field = ANOMALY_SORT_FIELDS[sortKey];
|
|
2787
|
+
const direction = params.sort_dir === 'asc' ? 1 : -1;
|
|
2788
|
+
item.sort((left, right) => {
|
|
2789
|
+
const leftValue = typeof left[field] === 'number' ? left[field] : null;
|
|
2790
|
+
const rightValue = typeof right[field] === 'number' ? right[field] : null;
|
|
2791
|
+
if (leftValue === null && rightValue === null)
|
|
2792
|
+
return 0;
|
|
2793
|
+
if (leftValue === null)
|
|
2794
|
+
return 1;
|
|
2795
|
+
if (rightValue === null)
|
|
2796
|
+
return -1;
|
|
2797
|
+
return (leftValue - rightValue) * direction;
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
const available = item.length > 0;
|
|
2801
|
+
const notes = [];
|
|
2802
|
+
if (clamped)
|
|
2803
|
+
notes.push(`请求日 ${requestedDate} 晚于上游业务日 ${dataDate}:上游忽略 date 并返回最近业务日(实测 2026-11-22 传 20261001/abc/0/20270105 全部返回 20261120 同一批数据),本批行属于 ${dataDate}。`);
|
|
2804
|
+
if (!available)
|
|
2805
|
+
notes.push(`上游 data=[](业务日 ${dataDate} 没有${kind === 'list' ? '严重异常波动明细' : '异动聚合记录'};合法空,不是取数失败)。`);
|
|
2806
|
+
if (kind === 'count' && sortKey !== undefined)
|
|
2807
|
+
notes.push('排序在本地对本页执行:上游忽略 sortKey/sortDir(实测 5 种组合返回完全相同的顺序),跨页顺序不受控。');
|
|
2808
|
+
return {
|
|
2809
|
+
data: {
|
|
2810
|
+
item,
|
|
2811
|
+
data_date: dataDate,
|
|
2812
|
+
requested_date: requestedDate,
|
|
2813
|
+
requested_date_clamped: clamped,
|
|
2814
|
+
available,
|
|
2815
|
+
row_count: item.length,
|
|
2816
|
+
pagination: { page: Number(params.page_no), size: Number(params.page_size), pages },
|
|
2817
|
+
note: notes.length === 0 ? null : notes.join(' '),
|
|
2818
|
+
},
|
|
2819
|
+
schema: anomalyEnvelope(kind === 'list' ? anomalyListRow : anomalyCountRow),
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
function normalizeAnomalyDatePrefix(params) {
|
|
2823
|
+
const page_size = params.page_size === undefined
|
|
2824
|
+
? undefined
|
|
2825
|
+
: integer(params.page_size, 'page_size', 1, MAX_PAGE_SIZE);
|
|
2826
|
+
const page_no = params.page_no === undefined ? 1 : integer(params.page_no, 'page_no', 1, Number.MAX_SAFE_INTEGER);
|
|
2827
|
+
if (params.date !== undefined) {
|
|
2828
|
+
const day = date(params.date, 'date');
|
|
2829
|
+
if (day > beijingToday())
|
|
2830
|
+
throw new Error(`date ${day} is in the future (Beijing today is ${beijingToday()}); this endpoint only serves the latest business day`);
|
|
2831
|
+
}
|
|
2832
|
+
return { page_size, page_no, ...(params.date === undefined ? {} : { date: String(params.date) }) };
|
|
2833
|
+
}
|
|
2834
|
+
function normalizeAnomalyList(params) {
|
|
2835
|
+
assertKnown(params, ['page_size', 'page_no', 'date']);
|
|
2836
|
+
const normalized = normalizeAnomalyDatePrefix(params);
|
|
2837
|
+
if (normalized.page_size === undefined)
|
|
2838
|
+
normalized.page_size = ANOMALY_LIST_DEFAULT_SIZE;
|
|
2839
|
+
return normalized;
|
|
2840
|
+
}
|
|
2841
|
+
function normalizeAnomalyCount(params) {
|
|
2842
|
+
assertKnown(params, ['page_size', 'page_no', 'date', 'sort_key', 'sort_dir']);
|
|
2843
|
+
const normalized = normalizeAnomalyDatePrefix(params);
|
|
2844
|
+
if (normalized.page_size === undefined)
|
|
2845
|
+
normalized.page_size = ANOMALY_COUNT_DEFAULT_SIZE;
|
|
2846
|
+
if (params.sort_key !== undefined) {
|
|
2847
|
+
const sort_key = String(params.sort_key);
|
|
2848
|
+
if (!(sort_key in ANOMALY_SORT_FIELDS))
|
|
2849
|
+
throw new Error(`sort_key must be one of ${Object.keys(ANOMALY_SORT_FIELDS).join(', ')}`);
|
|
2850
|
+
normalized.sort_key = sort_key;
|
|
2851
|
+
}
|
|
2852
|
+
if (params.sort_dir !== undefined) {
|
|
2853
|
+
const sort_dir = String(params.sort_dir);
|
|
2854
|
+
if (sort_dir !== 'desc' && sort_dir !== 'asc')
|
|
2855
|
+
throw new Error('sort_dir must be desc or asc');
|
|
2856
|
+
normalized.sort_dir = sort_dir;
|
|
2857
|
+
}
|
|
2858
|
+
return normalized;
|
|
2859
|
+
}
|
|
2860
|
+
const anomalyListInput = {
|
|
2861
|
+
type: 'object',
|
|
2862
|
+
properties: {
|
|
2863
|
+
page_size: { type: 'integer', minimum: 1, maximum: MAX_PAGE_SIZE, description: '每页行数,默认 200;上游实测接受 10000,本层封顶 500(单日通常 < 50 行)' },
|
|
2864
|
+
page_no: { type: 'integer', minimum: 1, description: '页码,默认 1' },
|
|
2865
|
+
date: { type: 'string', description: '期望业务日 YYYY-MM-DD(可选)。上游忽略该参数、只返回最近业务日;早于返回业务日会被响亮拒绝,晚于则用 requested_date_clamped 标出' },
|
|
2866
|
+
},
|
|
2867
|
+
required: [],
|
|
2868
|
+
additionalProperties: false,
|
|
2869
|
+
};
|
|
2870
|
+
const anomalyCountInput = {
|
|
2871
|
+
type: 'object',
|
|
2872
|
+
properties: {
|
|
2873
|
+
...anomalyListInput.properties,
|
|
2874
|
+
page_size: { type: 'integer', minimum: 1, maximum: MAX_PAGE_SIZE, description: '每页行数,默认 50;上游实测接受 10000,本层封顶 500' },
|
|
2875
|
+
sort_key: { type: 'string', enum: Object.keys(ANOMALY_SORT_FIELDS), description: '本地排序键,默认不排序(保持上游顺序);上游忽略该参数' },
|
|
2876
|
+
sort_dir: { type: 'string', enum: ['desc', 'asc'], description: '本地排序方向,默认 desc' },
|
|
2877
|
+
},
|
|
2878
|
+
required: [],
|
|
2879
|
+
additionalProperties: false,
|
|
2880
|
+
};
|
|
2881
|
+
const hotConceptRow = {
|
|
2882
|
+
type: 'object',
|
|
2883
|
+
properties: { concept_name: { type: 'string' }, concept_code: { type: 'string' }, hit_count: { type: 'integer' } },
|
|
2884
|
+
required: ['concept_name', 'concept_code', 'hit_count'],
|
|
2885
|
+
additionalProperties: false,
|
|
2886
|
+
};
|
|
2887
|
+
const hotConceptOutput = {
|
|
2888
|
+
type: 'object',
|
|
2889
|
+
properties: {
|
|
2890
|
+
item: { type: 'array', items: hotConceptRow },
|
|
2891
|
+
thscode: { type: 'string' }, ticker: { type: 'string' }, market: { type: 'string', enum: ['SH', 'SZ', 'BJ'] },
|
|
2892
|
+
src_security_code: { type: 'string' },
|
|
2893
|
+
calculated_at: nullableString,
|
|
2894
|
+
calculated_at_ms: { oneOf: [{ type: 'integer' }, { type: 'null' }] },
|
|
2895
|
+
available: { type: 'boolean' },
|
|
2896
|
+
note: nullableString,
|
|
2897
|
+
},
|
|
2898
|
+
required: ['item', 'thscode', 'ticker', 'market', 'src_security_code', 'calculated_at', 'calculated_at_ms', 'available', 'note'],
|
|
2899
|
+
additionalProperties: false,
|
|
2900
|
+
};
|
|
2901
|
+
function normalizeHotConcepts(params) {
|
|
2902
|
+
assertKnown(params, ['ticker']);
|
|
2903
|
+
return { ticker: ashareThscode(params.ticker) };
|
|
2904
|
+
}
|
|
2905
|
+
async function executeHotConcepts(params, signal) {
|
|
2906
|
+
const thscode = String(params.ticker);
|
|
2907
|
+
const [ticker, market] = thscode.split('.');
|
|
2908
|
+
const srcSecurityCode = `${market}${ticker}`;
|
|
2909
|
+
const payload = await postJsonWithThrottle(HOT_CONCEPT_URL, { ...HOT_CONCEPT_BODY, srcSecurityCode }, signal, 'stock hot concepts');
|
|
2910
|
+
if (Number(payload.code) !== 0 || Number(payload.status) !== 0) {
|
|
2911
|
+
throw sourceError(`Eastmoney stock hot concepts failed for ${srcSecurityCode}: ${String(payload.message ?? 'unknown upstream error')} (code ${String(payload.code ?? 'unknown')})`, 'eastmoney_upstream_error');
|
|
2912
|
+
}
|
|
2913
|
+
if (!Array.isArray(payload.data))
|
|
2914
|
+
throw sourceError('Eastmoney stock hot concepts returned no data array', 'eastmoney_invalid_response');
|
|
2915
|
+
const context = 'stock hot concepts';
|
|
2916
|
+
const rawRows = poolRowArray(payload.data, context);
|
|
2917
|
+
const rows = rawRows.map((raw) => {
|
|
2918
|
+
if (String(raw.srcSecurityCode ?? '') !== srcSecurityCode) {
|
|
2919
|
+
throw sourceError(`Eastmoney ${context} returned ${String(raw.srcSecurityCode ?? '(missing)')} for requested ${srcSecurityCode}`, 'eastmoney_invalid_response');
|
|
2920
|
+
}
|
|
2921
|
+
const conceptName = textOrNull(raw.conceptName);
|
|
2922
|
+
if (conceptName === null || conceptName.trim().length === 0)
|
|
2923
|
+
throw sourceError(`Eastmoney ${context} row has no conceptName`, 'eastmoney_invalid_response');
|
|
2924
|
+
const conceptCode = String(raw.conceptId ?? '');
|
|
2925
|
+
if (!/^BK\d{4}$/u.test(conceptCode))
|
|
2926
|
+
throw sourceError(`Eastmoney ${context} row has an unusable conceptId ${conceptCode || '(empty)'}`, 'eastmoney_invalid_response');
|
|
2927
|
+
const hitCount = poolInteger(raw.hitCount, 'hitCount', context);
|
|
2928
|
+
if (hitCount === null)
|
|
2929
|
+
throw sourceError(`Eastmoney ${context} row has no hitCount`, 'eastmoney_invalid_response');
|
|
2930
|
+
return { concept_name: conceptName, concept_code: conceptCode, hit_count: hitCount };
|
|
2931
|
+
});
|
|
2932
|
+
// Upstream is already ordered by heat; sort locally so the promise "heat desc" does not depend on it.
|
|
2933
|
+
rows.sort((left, right) => right.hit_count - left.hit_count);
|
|
2934
|
+
const calculatedAt = rows.length === 0 ? null : textOrNull(rawRows[0].calcTime);
|
|
2935
|
+
let calculatedAtMs = null;
|
|
2936
|
+
if (calculatedAt !== null) {
|
|
2937
|
+
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/u.test(calculatedAt))
|
|
2938
|
+
throw sourceError(`Eastmoney ${context} returned an unparseable calcTime ${calculatedAt}`, 'eastmoney_invalid_response');
|
|
2939
|
+
calculatedAtMs = Date.parse(`${calculatedAt.replace(' ', 'T')}+08:00`);
|
|
2940
|
+
if (Number.isNaN(calculatedAtMs))
|
|
2941
|
+
throw sourceError(`Eastmoney ${context} returned an unparseable calcTime ${calculatedAt}`, 'eastmoney_invalid_response');
|
|
2942
|
+
}
|
|
2943
|
+
const available = rows.length > 0;
|
|
2944
|
+
return {
|
|
2945
|
+
data: {
|
|
2946
|
+
item: rows,
|
|
2947
|
+
thscode,
|
|
2948
|
+
ticker,
|
|
2949
|
+
market,
|
|
2950
|
+
src_security_code: srcSecurityCode,
|
|
2951
|
+
calculated_at: calculatedAt,
|
|
2952
|
+
calculated_at_ms: calculatedAtMs,
|
|
2953
|
+
available,
|
|
2954
|
+
note: available ? null : `东财 App 动态热度口径下 ${srcSecurityCode} 当前没有概念命中(上游 data=[],合法空,不是取数失败;也不代表该股不属于任何板块)。`,
|
|
2955
|
+
},
|
|
2956
|
+
schema: hotConceptOutput,
|
|
2957
|
+
};
|
|
2958
|
+
}
|
|
2959
|
+
function validateLimitPoolOutput(data) {
|
|
2960
|
+
return isRecord(data)
|
|
2961
|
+
&& Array.isArray(data.item)
|
|
2962
|
+
&& data.item.every(isRecord)
|
|
2963
|
+
&& data.item.length === data.row_count
|
|
2964
|
+
&& typeof data.trade_date === 'string'
|
|
2965
|
+
&& (data.server_latest_trade_date === null || typeof data.server_latest_trade_date === 'string')
|
|
2966
|
+
&& typeof data.requested_date_clamped === 'boolean'
|
|
2967
|
+
&& typeof data.available === 'boolean'
|
|
2968
|
+
&& typeof data.upstream_total === 'number';
|
|
2969
|
+
}
|
|
2970
|
+
function validateAnomalyOutput(data) {
|
|
2971
|
+
return isRecord(data)
|
|
2972
|
+
&& Array.isArray(data.item)
|
|
2973
|
+
&& data.item.every(isRecord)
|
|
2974
|
+
&& data.item.length === data.row_count
|
|
2975
|
+
&& typeof data.data_date === 'string'
|
|
2976
|
+
&& typeof data.available === 'boolean'
|
|
2977
|
+
&& isRecord(data.pagination);
|
|
2978
|
+
}
|
|
2979
|
+
function validateHotConceptOutput(data) {
|
|
2980
|
+
return isRecord(data)
|
|
2981
|
+
&& Array.isArray(data.item)
|
|
2982
|
+
&& data.item.every(isRecord)
|
|
2983
|
+
&& typeof data.thscode === 'string'
|
|
2984
|
+
&& typeof data.available === 'boolean';
|
|
2985
|
+
}
|
|
2986
|
+
function createEastmoneyLimitPoolSources() {
|
|
2987
|
+
return [
|
|
2988
|
+
createSource({
|
|
2989
|
+
capability: 'eastmoney_limit_up_pool', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_limit_up_pool',
|
|
2990
|
+
summary: '东财涨停池(push2ex 口径,含首末封与封板资金)',
|
|
2991
|
+
description: '获取东方财富涨停板行情中心的涨停池(push2ex getTopicZTPool,零 key,与 push2 不同主机;实测 2026-11-22 17:2x 北京时间可直连、HTTP 200)。⛔ 与本地 Fuyao/同花顺口径的 `limit_up_pool` 是**两家口径**:家数、连板数、封板时间、封板资金都不可比、不可拼接、不可混算。参数 trade_date(YYYY-MM-DD,北京时间交易日)**必填**:上游省略 date 直接返回 rc=102 + data=null(实测),没有「最新」默认,本层不做日期猜测。实测 2026-11-20(周五)涨停 28 只、2026-11-19 为 23 只;上游只保留**最近约 15 个交易日**(实测 2026-11-02 有数据 tc=125、2026-10-30 起 tc=0),更早日期与非交易日返回 rc=0 + tc=0 + pool=[](**不是 data=null,也不是取数失败**:输出 available=false + note);请求日**晚于最近交易日**(含周末、节假日、未来日)会被上游静默夹到最近交易日,本层在参数层拒绝未来日期,今天及更晚的请求用 requested_date_clamped + server_latest_trade_date(上游 qdate)标出真实归属日。一次 pagesize=10000 取满、不翻页;行数必须等于 data.tc,不等即响亮失败;同一代码出现两次、或 m 市场码与代码号段矛盾同样响亮失败(实测 2026-11-19 曾收到过一次混入其他交易日行的缓存脏响应,靠这两条拦住)。字段映射(均字节级实测):c→code(6 位)、n→name、m 只用于校验(1=沪,0=深市与北交所同码),不输出;市场一律按代码号段用 helper 推导,禁止按 m 猜、p→price(**上游 ×1000 整数,÷1000 得元**,如 27710→27.71)、zdp→change_pct(百分数原值,10.0039701461792 即 +10.00397%)、amount→amount(成交额,元)、ltsz→float_market_cap(流通市值,元)、tshare→total_market_cap(总市值,元;实测 603324 为 4,183,747,797.2)、hs→turnover_rate_pct(百分数原值)、lbc→limit_days(连板数)、fbt→first_seal、lbt→last_seal(**上游是 HHMMSS 整数**,92501→"09:25:01";与同花顺的 Unix 秒不是一套)、fund→seal_fund(封板资金,元;实测与腾讯买一量×100×涨停价 28/28 一致)、zbc→break_times(炸板次数)、hybk→industry(东财行业名原文,实测存在被截断的短名如「汽车零部」)、zttj{days,ct}→zt_stat(「N天M板」,东财前端 n/m 口径:days=窗口天数、ct=涨停次数;与连板数 limit_days 不等价,实测 002548 lbc=1 而 zttj={6,3}),同时保留 zt_stat_days/zt_stat_boards 原值。不含炸板/跌停/昨日涨停池字段,不要跨池拼行。',
|
|
2992
|
+
inputSchema: limitPoolInput, outputSchema: limitPoolEnvelope(limitUpRow), paginated: false, rowShape: { rowKey: 'item' },
|
|
2993
|
+
allowed: ['trade_date'], normalize: normalizeLimitPool, execute: (params, signal) => executeLimitPool(LIMIT_UP_POOL_SPEC, params, signal),
|
|
2994
|
+
validateOutput: validateLimitPoolOutput,
|
|
2995
|
+
}),
|
|
2996
|
+
createSource({
|
|
2997
|
+
capability: 'eastmoney_limit_break_pool', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_limit_break_pool',
|
|
2998
|
+
summary: '东财炸板池(push2ex 口径,含涨停价与振幅)',
|
|
2999
|
+
description: '获取东方财富涨停板行情中心的炸板池(push2ex getTopicZBPool,与涨停池同族、只有 endpoint 与 sort 不同,零 key)。⛔ 与本地 Fuyao/同花顺口径的 `limit_break_pool` 是**两家口径**,家数与字段不可混、不可拼接。参数 trade_date 必填(YYYY-MM-DD);上游省略 date 返回 rc=102/data=null(实测),非交易日与超出约 15 个交易日保留窗口的日期返回 rc=0 + tc=0 + pool=[](合法空,输出 available=false + note),请求日晚于最近交易日会被静默夹到最近交易日(用 requested_date_clamped + server_latest_trade_date 标出;未来日期在参数层拒绝)。一次 pagesize=10000 取满不翻页,行数必须等于 data.tc,重复代码或 m 与代码号段矛盾即响亮失败。字段(2026-11-20 实测 7 只):c/n→code/name、m 只用于校验(市场按代码号段),不输出、p→price(×1000 整数÷1000,元)、ztp→limit_price(**涨停价**,同样 ÷1000;实测直真科技 p=32.26/ztp=35.86、涨跌幅 -1.04%,35.86 恰为昨收 32.60×1.1)、zdp→change_pct(百分数原值)、amount→amount(成交额,元)、ltsz→float_market_cap(元)、tshare→total_market_cap(元)、hs→turnover_rate_pct(百分数原值)、fbt→first_seal(HHMMSS 整数,93454→"09:34:54")、zbc→break_times(炸板次数)、zf→amplitude_pct(振幅百分数原值)、zs→speed_pct(涨速百分数原值;**实测收盘后全为 0**,盘中才有值)、hybk→industry(东财行业名原文)、zttj{days,ct}→zt_stat/zt_stat_days/zt_stat_boards(「N天M板」,炸板池常见 {0,0} → 「0天0板」,表示窗口内没有计入的连续板数,不是缺数)。本池没有 lbt(末封时间)与封板资金,需要请用 `eastmoney_limit_up_pool`。',
|
|
3000
|
+
inputSchema: limitPoolInput, outputSchema: limitPoolEnvelope(limitBreakRow), paginated: false, rowShape: { rowKey: 'item' },
|
|
3001
|
+
allowed: ['trade_date'], normalize: normalizeLimitPool, execute: (params, signal) => executeLimitPool(LIMIT_BREAK_POOL_SPEC, params, signal),
|
|
3002
|
+
validateOutput: validateLimitPoolOutput,
|
|
3003
|
+
}),
|
|
3004
|
+
createSource({
|
|
3005
|
+
capability: 'eastmoney_limit_down_pool', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_limit_down_pool',
|
|
3006
|
+
summary: '东财跌停池(push2ex 口径,含封单资金与连续跌停)',
|
|
3007
|
+
description: '获取东方财富涨停板行情中心的跌停池(push2ex getTopicDTPool,零 key;与涨停/炸板同族,sort=fund:asc)。⛔ 与本地 Fuyao/同花顺口径的 `limit_down_pool` 是**两家口径**,家数与字段不可混、不可拼接。参数 trade_date 必填(YYYY-MM-DD);上游省略 date 返回 rc=102/data=null(实测),非交易日与超出约 15 个交易日保留窗口的日期返回 rc=0 + tc=0 + pool=[](合法空,available=false + note),请求日晚于最近交易日会被静默夹到最近交易日(requested_date_clamped + server_latest_trade_date 标出;未来日期参数层拒绝)。一次 pagesize=10000 取满不翻页,行数必须等于 data.tc,重复代码或 m 与代码号段矛盾即响亮失败。字段(2026-11-20 实测 58 只,逐列在真报文上核对):c/n→code/name、m 只用于校验(1=沪、0=深市与北交所同码),不输出;市场按代码号段、p→price(×1000 整数÷1000,元)、zdp→change_pct(百分数原值)、amount→amount(成交额,元;实测与换手率×流通市值一致)、ltsz→float_market_cap(流通市值,元)、tshare→total_market_cap(总市值,元)、pe→pe(东财动态市盈率原值,亏损股为负)、hs→turnover_rate_pct(百分数原值)、fund→seal_fund(**封单资金,元**,上游前端 title「当前以跌停价挂的卖单的资金总量」;实测与腾讯卖一量×100×股价 57/58 一致,如 605255 为 15067 手×100×59.80=90,100,660)、lbt→last_seal(末次触及跌停时间,HHMMSS 整数→HH:MM:SS,实测 135838→"13:58:38")、days→limit_down_days(**连续跌停天数**,实测 603037 于 11-19 为 1、11-20 为 2 连续递增)、oc→open_times(**打开跌停板次数**)、hybk→industry(东财行业名原文)。⛔ fba→board_amount 收录但**口径不可靠**:上游前端 title 写「成交价格为该股票跌停价的所有成交额的总和」,实测 58 行中 12 行大于当日成交额(002535:157,452,224 vs 23,102,652),3 只全天一字跌停(最高=最低)的票也不等于成交额,说明它并非已成交额子集;原值输出、只允许同列相对比较,禁止当成交额用、禁止与 amount 相减。',
|
|
3008
|
+
inputSchema: limitPoolInput, outputSchema: limitPoolEnvelope(limitDownRow), paginated: false, rowShape: { rowKey: 'item' },
|
|
3009
|
+
allowed: ['trade_date'], normalize: normalizeLimitPool, execute: (params, signal) => executeLimitPool(LIMIT_DOWN_POOL_SPEC, params, signal),
|
|
3010
|
+
validateOutput: validateLimitPoolOutput,
|
|
3011
|
+
}),
|
|
3012
|
+
createSource({
|
|
3013
|
+
capability: 'eastmoney_yesterday_limit_up_pool', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_yesterday_limit_up_pool',
|
|
3014
|
+
summary: '东财昨日涨停池(昨涨停今表现,含晋级率原料)',
|
|
3015
|
+
description: '获取东方财富涨停板行情中心的**昨日涨停池**(push2ex getYesterdayZTPool,sort=zs:desc,零 key):昨日涨停个股在今日的表现,用于算晋级率/赚钱效应。⛔ 本地此前没有这一池;与 Fuyao `limit_break_pool`/`limit_up_pool` 是两家口径,不可混算。⛔ **上游字段名带 y_ 前缀(yfbt/ylbc),不能与涨停池复用解析**:本能力用独立 parser 与独立行 schema,`yesterday_first_seal`/`yesterday_limit_days` 只来自 yfbt/ylbc,绝不读 fbt/lbt/lbc。参数 trade_date 必填(YYYY-MM-DD);上游省略 date 返回 rc=102/data=null(实测),非交易日与超出约 15 个交易日保留窗口的日期返回 rc=0 + tc=0 + pool=[](合法空),请求日晚于最近交易日会被静默夹到最近交易日(requested_date_clamped + server_latest_trade_date 标出;未来日期参数层拒绝)。一次 pagesize=10000 取满不翻页,行数必须等于 data.tc,重复代码或 m 与代码号段矛盾即响亮失败。字段(2026-11-20 实测 23 只):c/n→code/name、m 只用于校验(市场按代码号段),不输出、p→price(×1000÷1000,今日最新价,元)、ztp→limit_price(**今日涨停价**,÷1000;已涨停者 ztp==p,实测 002579/002771 相等)、zdp→change_pct(**今日涨跌幅**百分数原值,实测 002420 为 -9.81 即今天砸到接近跌停)、amount→amount(元)、ltsz→float_market_cap(元)、tshare→total_market_cap(元)、hs→turnover_rate_pct(百分数原值)、zf→amplitude_pct(振幅百分数原值)、zs→speed_pct(涨速百分数原值,实测收盘后全 0)、yfbt→yesterday_first_seal(**昨日**最后触及涨停时间,HHMMSS 整数→HH:MM:SS,如 131351→"13:13:51")、ylbc→yesterday_limit_days(**昨日**连板数;实测 000656 的 1119 涨停池 lbc=1 与本池 ylbc=1 对齐)、hybk→industry、zttj→zt_stat(「N天M板」,按截至今日的口径:今日仍涨停者会更新成今日档,如 002771 昨 3 板、今日仍涨停则本池给 4天4板)。本池没有今日首末封时间与封板资金;要今日封板质量请用 `eastmoney_limit_up_pool`。',
|
|
3016
|
+
inputSchema: limitPoolInput, outputSchema: limitPoolEnvelope(yesterdayLimitUpRow), paginated: false, rowShape: { rowKey: 'item' },
|
|
3017
|
+
allowed: ['trade_date'], normalize: normalizeLimitPool, execute: (params, signal) => executeLimitPool(YESTERDAY_LIMIT_UP_POOL_SPEC, params, signal),
|
|
3018
|
+
validateOutput: validateLimitPoolOutput,
|
|
3019
|
+
}),
|
|
3020
|
+
createSource({
|
|
3021
|
+
capability: 'eastmoney_price_anomaly_list', cacheMaxAgeMs: 900_000, name: 'get_eastmoney_price_anomaly_list',
|
|
3022
|
+
summary: '东财严重异常波动明细(规则码/累计偏离/统计窗口)',
|
|
3023
|
+
description: '获取东方财富「严重异常波动」口径的异动明细(dycalchis price-anomaly/list,交易所监管口径,零 key)。⛔ 必须带固定 H5 参数 team=h5&product=EastMoney&client=WAP&version=9001&name=WAP&user=123——缺 team 时上游回 {"result":1001,"msg":"unknow team"}(实测);`result != 0` 一律**正向抛错**(eastmoney_upstream_error),绝不当成「今天没异动」静默吞掉。⛔ **date 参数实测被上游完全忽略**:传 2026-11-20、2026-10-01、abc、0、2027-01-05 全部返回同一批 date=20261120 的数据(2026-11-22 北京时间实测)。因此本能力的 date 只是**断言**:等于返回业务日则通过;早于返回业务日 **响亮失败(eastmoney_no_anomaly_data)**,因为上游拿不到历史;晚于返回业务日(今天/周末/节假日)用 requested_date_clamped 标出,未来日期在参数层拒绝。响应 date 是**业务所属日**(YYYYMMDD→YYYY-MM-DD,非交易时段返回上一交易日属正常)。分页:page_size 默认 200、本层上限 500(上游实测接受 10000);上游 pages 的口径是 floor(total/page_size)+1(实测 list 4 行、size=2 时 pages=3 且第 3 页为空),count=**本页行数**(不是总数),代码按 count==行数 校验。字段映射(2026-11-20 实测 4 行):c/n→code/name;m→eastmoney_market_code 仅原值(**m=0 同时代表深市与北交所**,市场只能按代码号段 4/8/92→BJ 判,helper 复用);s→board_code(板块码,实测 1=主板、4=创业板、5=科创板,窗口内无 6/8 样本);e→rule_code(规则码;⛔ 上游前端映射:s==6 且 e∈{4,5,6,7} 时按 e*10 取更严阈值那档 4→40/5→50/6→60/7→70,本层按该规则换算,但**实测全窗口只有 s∈{4,5}、没有 s=6 样本,该分支未经真报文验证**);rule→上游 12 条规则中文名(对不上/未知码给 null,不编造;文字亦未逐条真报文核对);x→deviation_pct(累计偏离值 %,与 count 端点同名列同一口径:603324 4 连板时 x=48.29/d=4);d→window_days(统计窗口天数);a→change_pct(当日涨跌幅 %,实测 600530=-10、603324=+10、002148=8.17 与炸板池 zdp 8.172 一致);t→change_target_pct(⛔ **list 的 t 是浮点「涨跌幅目标值」**,与 count 的整数 t=异动次数**不是一回事**,本层分开解析、测试钉住;其精确口径未独立核验,只做同列比较);o→status_code + is_today(上游 IS_HAPPEN:=2 记 false、其余 true,按前端映射,未逐值核验)。空 data 是合法空(available=false + note)。本能力与本地 `anomaly_list`/`abnormal_monitor_list` 的「异动原因/监控区间」口径不同,不可拼接。',
|
|
3024
|
+
inputSchema: anomalyListInput, outputSchema: anomalyEnvelope(anomalyListRow), paginated: true, rowShape: { rowKey: 'item' },
|
|
3025
|
+
allowed: ['page_size', 'page_no', 'date'], normalize: normalizeAnomalyList, execute: (params, signal) => executeAnomaly('list', params, signal),
|
|
3026
|
+
validateOutput: validateAnomalyOutput,
|
|
3027
|
+
}),
|
|
3028
|
+
createSource({
|
|
3029
|
+
capability: 'eastmoney_price_anomaly_count', cacheMaxAgeMs: 900_000, name: 'get_eastmoney_price_anomaly_count',
|
|
3030
|
+
summary: '东财异动按标的聚合(窗口内异动次数/累计偏离)',
|
|
3031
|
+
description: '获取东方财富「严重异常波动」口径的**按标的聚合统计**(dycalchis price-anomaly/count,零 key)。⛔ 必须带固定 H5 参数 team=h5&product=EastMoney&client=WAP&version=9001&name=WAP&user=123(缺 team 回 result=1001 unknow team);`result != 0` 一律**正向抛错**,不许当「没有异动」。⛔ date 实测被上游忽略(2026-11-22 传 2026-10-01/abc/0/2027-01-05 全部返回 date=20261120 同一批数据);本能力 date 只是断言:等于返回业务日通过、早于返回业务日响亮失败(历史拿不到)、晚于用 requested_date_clamped 标出,未来日期参数层拒绝。响应 date 是业务所属日,非交易时段返回上一交易日属正常。分页:page_size 默认 50、本层上限 500;上游 pages=floor(total/page_size)+1(实测 11 行、size=2 时 pages=6),count=本页行数(按 count==行数校验)。⛔ **两函数同名字母含义不同**:本端点(count)的 `t` 是**窗口内异动次数(整数)**,list 端点的 `t` 是浮点「涨跌幅目标值」——本能力用独立 parser,t 非整数即响亮失败,绝不跨端点复用解析(测试钉住)。字段映射(2026-11-20 实测 11 行):c/n→code/name;m→eastmoney_market_code 仅原值(m=0 同时代表深市与北交所,市场按代码号段判);s→board_code(实测 1=主板,样本无 4/5/6/8);p→price(最新价,元;实测 603324=27.71、002771=15.82、002148=10.06 与涨停/炸板池价格逐条一致);a→change_pct(当日涨跌幅 % 原值);t→anomaly_times(窗口内异动次数,整数);x→deviation_pct(累计偏离值 %);d→window_days(统计窗口天数)。sort_key/sort_dir:⛔ 上游**忽略** sortKey/sortDir(实测 sortKey=t/x/a、asc/desc 共 5 种组合返回完全相同的顺序与数据),本层在**本地对本页**排序(sort_key ∈ times/deviation_pct/change_pct/price/window_days,默认不排序、保持上游顺序),跨页顺序不受控,note 会写明。空 data 是合法空(available=false + note)。本能力与本地 `anomaly_list`/`abnormal_monitor_list` 的「异动原因/监控区间」口径不同,不可拼接。',
|
|
3032
|
+
inputSchema: anomalyCountInput, outputSchema: anomalyEnvelope(anomalyCountRow), paginated: true, rowShape: { rowKey: 'item' },
|
|
3033
|
+
allowed: ['page_size', 'page_no', 'date', 'sort_key', 'sort_dir'], normalize: normalizeAnomalyCount, execute: (params, signal) => executeAnomaly('count', params, signal),
|
|
3034
|
+
validateOutput: validateAnomalyOutput,
|
|
3035
|
+
}),
|
|
3036
|
+
createSource({
|
|
3037
|
+
capability: 'eastmoney_stock_hot_concepts', cacheMaxAgeMs: 300_000, name: 'get_eastmoney_stock_hot_concepts',
|
|
3038
|
+
summary: '东财个股动态概念命中热度(App 热度口径)',
|
|
3039
|
+
description: '获取东方财富 App「个股热门概念命中」:这只票当下被市场归到哪些概念在炒(emappdata getHotStockRankList,POST {"appId":"appId01","globalId":"786e4c21-70dc-435a-93bb-38","srcSecurityCode":"SH600519"},零 key)。srcSecurityCode 必须是**大写 SH/SZ/BJ 前缀 + 6 位代码**:市场号段复用本文件既有 helper(4/8/92→BJ,6/9→SH,其余→SZ),**不许按首位猜沪深**,北交所 920x 必须走 BJ。返回 conceptName→concept_name、conceptId→concept_code(BK 码,校验 BK+4 位)、hitCount→hit_count(整数),按 hit_count 降序(上游实测即降序,本层再稳定降序)并给 calculated_at/calculated_at_ms(上游 calcTime,实测「2026-11-22 17:00:00」,北京时间口径的 App 热度计算时间)。⛔ **空 data 是合法空**(该票当前没有概念命中),输出 available=false + note,不是取数失败;实测 600519 有 7 条(白酒 BK0896 命中 6176)、000001 有 8 条、688981 有 6 条,而北交所 920575/920924/430047、错误前缀(SZ600519)、未知代码、裸 6 位代码都返回 code=0 的 data=[]——空只说明动态热度口径无命中,**不代表不属于任何概念**。返回行带 srcSecurityCode,必须与请求票一致,不一致即响亮失败;上游 code/status 非 0 抛错(实测空 body 回 code=-1「srcSecurityCode 股票代码不能为空」)。⛔ 这是**东财 App 动态热度口径**,与 `index_membership_by_stock`(同花顺静态板块归属)**不是一回事:不可对比、不可拼接**;hit_count 是热度命中计数,不是涨幅、资金流或板块成员数。',
|
|
3040
|
+
inputSchema: {
|
|
3041
|
+
type: 'object',
|
|
3042
|
+
properties: {
|
|
3043
|
+
ticker: { type: 'string', description: 'A 股代码(600519 或 600519.SH;北交所 920xxx 也可);内部转成大写 SH/SZ/BJ 前缀的 srcSecurityCode' },
|
|
3044
|
+
},
|
|
3045
|
+
required: ['ticker'],
|
|
3046
|
+
additionalProperties: false,
|
|
3047
|
+
},
|
|
3048
|
+
outputSchema: hotConceptOutput, paginated: false, rowShape: { rowKey: 'item' },
|
|
3049
|
+
allowed: ['ticker'], normalize: normalizeHotConcepts, execute: executeHotConcepts,
|
|
3050
|
+
validateOutput: validateHotConceptOutput,
|
|
3051
|
+
}),
|
|
1549
3052
|
];
|
|
1550
3053
|
}
|