ultrastiching-sdk 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. ultrastiching_sdk-0.1.3/.gitignore +17 -0
  2. ultrastiching_sdk-0.1.3/LICENSE +186 -0
  3. ultrastiching_sdk-0.1.3/PKG-INFO +264 -0
  4. ultrastiching_sdk-0.1.3/README.md +238 -0
  5. ultrastiching_sdk-0.1.3/demo.py +40 -0
  6. ultrastiching_sdk-0.1.3/pyproject.toml +42 -0
  7. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/__init__.py +24 -0
  8. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/_version.py +3 -0
  9. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/client.py +388 -0
  10. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/credentials.py +124 -0
  11. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/data/endpoints.json +1 -0
  12. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/data/marketdb-datasets.json +124 -0
  13. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/discovery.py +70 -0
  14. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/exceptions.py +110 -0
  15. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/generated/__init__.py +5 -0
  16. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/generated/api.py +28404 -0
  17. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/marketdb.py +544 -0
  18. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/py.typed +1 -0
  19. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/results.py +44 -0
  20. ultrastiching_sdk-0.1.3/src/meridian_kit_sdk/signing.py +71 -0
  21. ultrastiching_sdk-0.1.3/tests/test_build_python_release.py +37 -0
  22. ultrastiching_sdk-0.1.3/tests/test_client.py +285 -0
  23. ultrastiching_sdk-0.1.3/tests/test_convenience.py +252 -0
  24. ultrastiching_sdk-0.1.3/tests/test_discovery.py +70 -0
  25. ultrastiching_sdk-0.1.3/tests/test_generated_api.py +98 -0
  26. ultrastiching_sdk-0.1.3/tests/test_import_api_catalog.py +203 -0
  27. ultrastiching_sdk-0.1.3/tests/test_marketdb.py +276 -0
  28. ultrastiching_sdk-0.1.3/tests/test_python39_compatibility.py +26 -0
  29. ultrastiching_sdk-0.1.3/tests/test_signing.py +35 -0
@@ -0,0 +1,17 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ .coverage
8
+ htmlcov/
9
+ build/
10
+ dist/
11
+ *.egg-info/
12
+ .env
13
+ .env.*
14
+ !.env.example
15
+ .DS_Store
16
+ mcp-setup/skills/
17
+ mcp-setup/.skill-package-*/
@@ -0,0 +1,186 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source,
28
+ and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled
32
+ object code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work (an example is provided in the Appendix
37
+ below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as a
42
+ whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the
52
+ purposes of this definition, "submitted" means any form of electronic,
53
+ verbal, or written communication sent to the Licensor or its representatives,
54
+ including but not limited to communication on electronic mailing lists, source
55
+ code control systems, and issue tracking systems that are managed by, or on
56
+ behalf of, the Licensor for the purpose of discussing and improving the Work,
57
+ but excluding communication that is conspicuously marked or otherwise
58
+ designated in writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
61
+ behalf of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
65
+ License, each Contributor hereby grants to You a perpetual, worldwide,
66
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
67
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
68
+ sublicense, and distribute the Work and such Derivative Works in Source or
69
+ Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of this
72
+ License, each Contributor hereby grants to You a perpetual, worldwide,
73
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
74
+ section) patent license to make, have made, use, offer to sell, sell, import,
75
+ and otherwise transfer the Work, where such license applies only to those
76
+ patent claims licensable by such Contributor that are necessarily infringed
77
+ by their Contribution(s) alone or by combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You institute
79
+ patent litigation against any entity (including a cross-claim or counterclaim
80
+ in a lawsuit) alleging that the Work or a Contribution incorporated within
81
+ the Work constitutes direct or contributory patent infringement, then any
82
+ patent licenses granted to You under this License for that Work shall
83
+ terminate as of the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
86
+ Derivative Works thereof in any medium, with or without modifications, and in
87
+ Source or Object form, provided that You meet the following conditions:
88
+
89
+ (a) You must give any other recipients of the Work or Derivative Works a copy
90
+ of this License; and
91
+
92
+ (b) You must cause any modified files to carry prominent notices stating that
93
+ You changed the files; and
94
+
95
+ (c) You must retain, in the Source form of any Derivative Works that You
96
+ distribute, all copyright, patent, trademark, and attribution notices from the
97
+ Source form of the Work, excluding those notices that do not pertain to any
98
+ part of the Derivative Works; and
99
+
100
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
101
+ then any Derivative Works that You distribute must include a readable copy of
102
+ the attribution notices contained within such NOTICE file, excluding those
103
+ notices that do not pertain to any part of the Derivative Works, in at least
104
+ one of the following places: within a NOTICE text file distributed as part of
105
+ the Derivative Works; within the Source form or documentation, if provided
106
+ along with the Derivative Works; or, within a display generated by the
107
+ Derivative Works, if and wherever such third-party notices normally appear.
108
+ The contents of the NOTICE file are for informational purposes only and do
109
+ not modify the License. You may add Your own attribution notices within
110
+ Derivative Works that You distribute, alongside or as an addendum to the
111
+ NOTICE text from the Work, provided that such additional attribution notices
112
+ cannot be construed as modifying the License.
113
+
114
+ You may add Your own copyright statement to Your modifications and may
115
+ provide additional or different license terms and conditions for use,
116
+ reproduction, or distribution of Your modifications, or for any such
117
+ Derivative Works as a whole, provided Your use, reproduction, and distribution
118
+ of the Work otherwise complies with the conditions stated in this License.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
121
+ Contribution intentionally submitted for inclusion in the Work by You to the
122
+ Licensor shall be under the terms and conditions of this License, without any
123
+ additional terms or conditions. Notwithstanding the above, nothing herein
124
+ shall supersede or modify the terms of any separate license agreement you may
125
+ have executed with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade names,
128
+ trademarks, service marks, or product names of the Licensor, except as
129
+ required for reasonable and customary use in describing the origin of the Work
130
+ and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
133
+ writing, Licensor provides the Work (and each Contributor provides its
134
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
135
+ KIND, either express or implied, including, without limitation, any warranties
136
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
137
+ PARTICULAR PURPOSE. You are solely responsible for determining the
138
+ appropriateness of using or redistributing the Work and assume any risks
139
+ associated with Your exercise of permissions under this License.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
142
+ tort (including negligence), contract, or otherwise, unless required by
143
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
144
+ writing, shall any Contributor be liable to You for damages, including any
145
+ direct, indirect, special, incidental, or consequential damages of any
146
+ character arising as a result of this License or out of the use or inability
147
+ to use the Work (including but not limited to damages for loss of goodwill,
148
+ work stoppage, computer failure or malfunction, or any and all other
149
+ commercial damages or losses), even if such Contributor has been advised of
150
+ the possibility of such damages.
151
+
152
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
153
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
154
+ acceptance of support, warranty, indemnity, or other liability obligations
155
+ and/or rights consistent with this License. However, in accepting such
156
+ obligations, You may act only on Your own behalf and on Your sole
157
+ responsibility, not on behalf of any other Contributor, and only if You agree
158
+ to indemnify, defend, and hold each Contributor harmless for any liability
159
+ incurred by, or claims asserted against, such Contributor by reason of your
160
+ accepting any such warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ APPENDIX: How to apply the Apache License to your work.
165
+
166
+ To apply the Apache License to your work, attach the following boilerplate
167
+ notice, with the fields enclosed by brackets "[]" replaced with your own
168
+ identifying information. (Don't include the brackets!) The text should be
169
+ enclosed in the appropriate comment syntax for the file format. We also
170
+ recommend that a file or class name and description of purpose be included on
171
+ the same "printed page" as the copyright notice for easier identification
172
+ within third-party archives.
173
+
174
+ Copyright [yyyy] [name of copyright owner]
175
+
176
+ Licensed under the Apache License, Version 2.0 (the "License");
177
+ you may not use this file except in compliance with the License.
178
+ You may obtain a copy of the License at
179
+
180
+ http://www.apache.org/licenses/LICENSE-2.0
181
+
182
+ Unless required by applicable law or agreed to in writing, software
183
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
184
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185
+ See the License for the specific language governing permissions and
186
+ limitations under the License.
@@ -0,0 +1,264 @@
1
+ Metadata-Version: 2.5
2
+ Name: ultrastiching-sdk
3
+ Version: 0.1.3
4
+ Summary: UltraStiching SDK for the UltraStiching Data API
5
+ Project-URL: Homepage, https://www.ultrastiching.com
6
+ Author: UltraStiching
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.9
14
+ Requires-Dist: requests<3,>=2.31
15
+ Requires-Dist: urllib3<2,>=1.26.20; python_version < '3.10'
16
+ Requires-Dist: websocket-client<1.9,>=1.8
17
+ Provides-Extra: arrow
18
+ Requires-Dist: pyarrow>=14; extra == 'arrow'
19
+ Provides-Extra: marketdb
20
+ Requires-Dist: duckdb<1.6,>=1.4.1; extra == 'marketdb'
21
+ Provides-Extra: test
22
+ Requires-Dist: duckdb<1.6,>=1.4.1; extra == 'test'
23
+ Requires-Dist: pyarrow>=14; extra == 'test'
24
+ Requires-Dist: pytest<10,>=8; extra == 'test'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # UltraStiching SDK for Python
28
+
29
+ `ultrastiching-sdk` 是 UltraStiching 数据 API 的 Python 客户端,导入名为 `meridian_kit_sdk`。它包含从 [2026-10-07 API 目录](https://www.ultrastiching.com/api-catalog/endpoints.json)生成的 2049 个同步 HTTP 方法(2040 POST、9 GET;另有 2 项 SSE 仅入目录)、1 个 WebSocket 快讯方法、离线端点与字段发现、JSON/Arrow 结果工具,以及可选的 DuckDB marketdb。
30
+
31
+ 目录是当日生产元数据的导出,不是当前账号权限或全部端点现时可用性的证明。本版按当前公开字段生成平铺请求;既有方法名按 UUID 保留,新增名称为已确认的 SDK 约定,来源和差异标记在包内注册表中,可通过 `MeridianClient.endpoints()` 查询。在线示例需要有效 API Key;尚未逐项验收示例端点、权限和服务端限制。
32
+
33
+ ## 安装与依赖
34
+
35
+ 要求 Python 3.9 或更高版本。从 PyPI 安装基础客户端:
36
+
37
+ ```bash
38
+ python -m pip install ultrastiching-sdk==0.1.3
39
+ python -c "import meridian_kit_sdk; print(meridian_kit_sdk.__version__)"
40
+ ```
41
+
42
+ 基础依赖是 `requests` 和 `websocket-client`;Python 3.9 的 `urllib3` 约束由包元数据处理。需要 Arrow 转换和本地数据库时,执行 `python -m pip install "ultrastiching-sdk[arrow,marketdb]==0.1.3"`;`arrow` 额外安装 `pyarrow`,`marketdb` 额外安装 `duckdb`。
43
+
44
+ `ultrastiching-sdk` 是安装包名;Python 导入名仍为 `meridian_kit_sdk`,客户端类仍为 `MeridianClient`,现有环境变量和用户配置目录也继续使用原名称。
45
+
46
+ 如果当前环境安装过旧发行包 `meridian-kit-sdk`,请先执行 `python -m pip uninstall meridian-kit-sdk`,再安装新包,并将依赖文件中的名称改为 `ultrastiching-sdk`。两个发行包提供相同的 `meridian_kit_sdk` 模块,不应同时安装。`pip install --upgrade meridian-kit-sdk` 只更新旧名称下的版本,不会切换到新名称。
47
+
48
+ 拿到 wheel 时可直接安装 `python -m pip install ./ultrastiching_sdk-0.1.3-py3-none-any.whl`。源码交付 ZIP 包含源码归档、`demo.py` 和本说明,解压后执行 `python -m pip install ./ultrastiching_sdk-0.1.3.tar.gz`。维护仓库的开发安装方式为 `python -m pip install -e "./python[arrow,marketdb]"`。
49
+
50
+ ## 配置 API Key 和地址
51
+
52
+ Python 客户端的 Key 优先级:显式 `api_key=`、`MERIDIAN_API_KEY`、`~/.meridian/credentials.env`。默认 HTTP 地址是 `https://api.ultrastiching.com`,显式 `base_url=` 优先于 `MERIDIAN_BASE_URL`。`base_url` 必须是纯 HTTP(S) origin,不要附带 `/api/wd`、查询参数或片段;生成方法会使用注册表中的完整相对路径。
53
+
54
+ 环境变量与私有文件任选一种;项目 `.env` 不会自动加载。维护仓库的 `.env.example` 只是模板。只由用户在 SDK 实际执行环境配置 Key。
55
+
56
+ ```bash
57
+ export MERIDIAN_API_KEY="<your-api-key>"
58
+ ```
59
+
60
+ 也可以把一行 `MERIDIAN_API_KEY=<your-api-key>` 写入 `~/.meridian/credentials.env`。用户文件回退要求 POSIX 当前用户拥有该文件、文件权限为 `0600` 或更严,且 `~/.meridian` 目录不能被其他用户写入;平台无法提供安全的不跟随符号链接读取时,请使用显式 Key 或环境变量。不要把真实 Key 写进仓库、URL、日志或截图。
61
+
62
+ 测试环境与正式环境使用同一个 `MeridianClient`、相同方法和错误语义,只通过地址与 Key 等配置区分。
63
+
64
+ ## 离线查端点和字段
65
+
66
+ 注册表随包安装,以下示例无需 API Key 或网络;类上的发现方法不必构造客户端。
67
+
68
+ ```python
69
+ from meridian_kit_sdk import MeridianClient
70
+
71
+ meta = MeridianClient.endpoints()["plasma_daily"]
72
+ print(meta["path"]) # /api/wd/v1/data/daily
73
+ print(meta["response"]["return_format"]) # JSON
74
+ print(MeridianClient.fields("plasma_daily")[:3])
75
+ print(MeridianClient.fields("plasma_daily", search="收盘"))
76
+ ```
77
+
78
+ `endpoints()` 返回按生成方法名索引的端点资料;`fields(name, search=...)` 查该端点在目录中记录的响应字段,未知名称会提供近似名称建议。函数名、参数、请求映射、地址和来源示例均在 `endpoints()` 返回的同一份资料中;方法签名也可通过 `help(MeridianClient.<方法名>)` 查看。字段目录只说明已记录的元数据,不能替代当前服务端的在线返回检查。
79
+
80
+ ## 调用 JSON 和 Arrow 端点
81
+
82
+ **以下代码会发送真实请求。本轮无 Key,未对线上返回值和账号权限进行验收。**
83
+
84
+ ```python
85
+ from meridian_kit_sdk import MeridianClient
86
+
87
+ with MeridianClient() as client:
88
+ # JSON 响应保持服务端对象形状;rows() 提取 data_frame 行列表。
89
+ result = client.get_s_stockname(code=["600745.SH"])
90
+ print(client.rows(result))
91
+
92
+ # 通用 Arrow 下载接口返回 bytes,需显式转成 Arrow Table。
93
+ raw = client.arrow(
94
+ handler="get_s_stockname", params={"code": ["600745.SH"]}, fields=["code", "sename"]
95
+ )
96
+ table = client.arrow_to_table(raw)
97
+ print(table.num_rows)
98
+ ```
99
+
100
+ `rows()` 仅接受含 `data_frame` 列表的 JSON 结果;错误或非预期形状会抛出 `MeridianResultError`,不会伪装为空表。`arrow_to_table()` 需要安装 `pyarrow`,未安装时提示安装 `ultrastiching-sdk[arrow]`。HTTP 核心按响应 `Content-Type` 处理:JSON 解码为 Python 对象,Arrow IPC 保留原始 bytes。默认不自动重试,也不自动转换成 pandas DataFrame。
101
+
102
+ SDK 业务函数按注册表路径发送请求。例如 `get_s_stockname` 使用 `/api/wd/v1/data/get_s_stockname`,`plasma_daily` 使用 `/api/wd/v1/data/daily`。调用通用下载接口 `client.arrow(handler="get_s_stockname", params=..., fields=...)` 时,`params` 按目标端点的当前平铺参数提供,`fields` 选择输出列;当前 `plasma_*` 返回格式为 JSON;按目录和实际响应 Content-Type 处理。
103
+
104
+ 如果需要直接调用路径,`request()` 返回原始 `requests.Response`。它要求以单个 `/` 开头的相对路径,并限制请求体最大 1 MiB:
105
+
106
+ ```python
107
+ from meridian_kit_sdk import MeridianClient
108
+
109
+ with MeridianClient() as client:
110
+ response = client.request(
111
+ "POST",
112
+ "/api/wd/v1/data/get_s_stockname",
113
+ json={"code": ["600745.SH"]},
114
+ )
115
+ print(response.json())
116
+ ```
117
+
118
+ ## 读取主题跟踪资讯
119
+
120
+ 主题跟踪公开 API 包含 9 项内容查询和 2 项 SSE 推送,全部使用 GET 与同一个 UltraStiching API Key。2026-10-07 的 0.2.46 生产发布已启用 `/v1/tracer/feed`、`/v1/tracer/search` 和快讯最多 50 条窗口;0.2.47 已更新纪要预览标记。以下路径按该接口版本使用,账号权限与实际返回仍需单独核验。
121
+
122
+ | 内容 | 路径 |
123
+ | --- | --- |
124
+ | 关注范围新闻与快讯 | `/v1/tracer/feed` |
125
+ | 已入库新闻与快讯搜索 | `/v1/tracer/search` |
126
+ | 合并快讯列表 | `/v1/tracer/newsflash` |
127
+ | 纪要列表/整理正文 | `/v1/tracer/library/minutes`、`/v1/tracer/library/minutes/{id}` |
128
+ | 研报列表/摘要与整理稿 | `/v1/tracer/library/report`、`/v1/tracer/library/report/{id}` |
129
+ | X/公众号列表;X 正文详情 | `/v1/tracer/library/media`、`/v1/tracer/library/media/{id}` |
130
+ | 快讯/媒体 SSE | `/v1/tracer/newsflash/events`、`/v1/tracer/library/media/events` |
131
+
132
+ 这 11 项已纳入统一目录,可通过 `endpoints()/fields()` 和 CLI `list/info` 查询。9 项普通 GET 使用 `tracer_` 前缀的生成方法,也支持 CLI `call`。这只是 SDK 名称约定,例如 `tracer_feed()` 对应 `/v1/tracer/feed`,`tracer_report(id=123)` 对应 `/v1/tracer/library/report/123`;服务器路径保持原样。两个 SSE 不生成同步方法,CLI `call` 明确拒绝。通用 `request()` 仍可读取普通 GET;按服务端 `items` 读取,不用金融表格的 `rows()` 提取。
133
+
134
+ 以下示例会请求在线服务并使用账号额度:
135
+
136
+ ```python
137
+ from meridian_kit_sdk import MeridianClient
138
+
139
+ # Key 由既有环境变量或用户凭据文件读取。
140
+ with MeridianClient() as client:
141
+ params = {
142
+ "q": "美债",
143
+ "scope": "following",
144
+ "from": "2026-10-06T00:00:00+08:00",
145
+ "to": "2026-10-06T23:59:59+08:00",
146
+ "limit": 20,
147
+ }
148
+ page = client.request("GET", "/v1/tracer/search", params=params).json()
149
+ if page["has_more"]:
150
+ # 保持查询条件,并使用服务端返回的固定时间窗续页。
151
+ next_page = client.request(
152
+ "GET", "/v1/tracer/search",
153
+ params={
154
+ **params,
155
+ "from": page["window"]["from"],
156
+ "to": page["window"]["to"],
157
+ "cursor": page["next_cursor"],
158
+ },
159
+ ).json()
160
+
161
+ newsflash = client.request(
162
+ "GET", "/v1/tracer/newsflash",
163
+ params={"limit": 50, "important_only": "true"},
164
+ ).json()
165
+ minutes = client.request(
166
+ "GET", "/v1/tracer/library/minutes",
167
+ params={"subtype": "meeting_minute", "days": 7, "limit": 30, "offset": 0},
168
+ ).json()
169
+ for item in minutes["items"][:1]:
170
+ detail = client.request(
171
+ "GET", f"/v1/tracer/library/minutes/{item['id']}",
172
+ ).json()
173
+ print(detail["content"], detail["content_truncated"])
174
+ ```
175
+
176
+ `feed` 仅读取网站中当前账号的关注范围,不传 `q`;`search` 必填 `q`,支持 `scope=following/global`,其中 `global` 只表示公开已入库内容。新闻查询使用 `cursor`,续页保留全部筛选及响应时间窗,游标 15 分钟有效;默认读取范围分别为最近 7 天与 30 天。`topic_id` 只用于已经关注的主题,使用 UUID 或 `catalog:<slug>`,不是资料内容 ID。公开 API 不提供关注列表、主题管理或新闻正文详情。
177
+
178
+ 快讯 `limit` 默认 50,最多 50 条,没有历史游标。生成方法 `client.tracer_newsflash(important_only=True)` 会自动编码为小写 `true`;使用通用 `request()` 时传字符串 `"true"/"false"`。资料列表按 `offset` 分页,默认 `limit=30`、最多 60 条;`days` 只取 `0/7/30/365`,0 表示不限时间。媒体列表必须传 `platform=x/wechat`,公众号只有标题与原文链接,详情只允许 X。
179
+
180
+ 纪要列表预览最多 700 字符,`content_truncated` 按当前正文长度判断;详情的 `content` 是整理正文。研报详情分别返回 `summary` 与 `edited_content`,不返回原文 `content` 或附件;X 使用已采集的 `content`。保留空值与实际截断标记,不把预览或空整理稿当作完整原文。
181
+
182
+ 两个 SSE 接口返回 `text/event-stream`。当前 `request()` 缓冲响应且没有 `stream` 参数,持续订阅须使用能带 Authorization 请求头并逐帧读取的 HTTP 流式传输。先读取同筛选列表,再以 `snapshot_revision` 作为 `baseline_revision` 建连;媒体基线列表固定 `limit=50&offset=0`。断线或 `refresh` 后重读列表并重建基线,不提供离线历史回放。金融数据的 `ws_newsflash()` 属于另一套 WebSocket 接口。
183
+
184
+ ## 订阅实时快讯
185
+
186
+ WebSocket 使用同一个 API Key,在握手时发送 `Authorization: Bearer <key>`。目录中的地址为 `wss://ws.ultrastiching.com/api/wd/ws/newsflash`;可以用 `websocket_base_url=` 覆盖 origin。以下也属于未在线验收的真实请求:
187
+
188
+ ```python
189
+ from meridian_kit_sdk import MeridianClient
190
+
191
+ with MeridianClient() as client:
192
+ with client.ws_newsflash(limit=10) as stream:
193
+ message = stream.receive_json()
194
+ print(message)
195
+ ```
196
+
197
+ SDK 不自动重连或重发订阅。需要补取时,由调用方保存**已处理完成**消息的游标,并自行决定何时重连。测试和正式环境使用同一接口。
198
+
199
+ ## 本地 DuckDB marketdb
200
+
201
+ `MarketDB` 位于 `meridian_kit_sdk.marketdb`,与 Node.js CLI 的 `ultrastiching db` 共用同一个 DuckDB 文件。默认路径为 `~/.meridian/marketdb.duckdb`;显式 `path=`、`MERIDIAN_DB`、默认路径依次决定位置。`duckdb` 是可选依赖,使用前执行 `python -m pip install "ultrastiching-sdk[marketdb]"`。
202
+
203
+ 以下示例只操作临时本地文件,可离线运行:
204
+
205
+ ```python
206
+ from pathlib import Path
207
+ from tempfile import TemporaryDirectory
208
+ from meridian_kit_sdk.marketdb import MarketDB
209
+
210
+ with TemporaryDirectory() as directory:
211
+ db = MarketDB(path=str(Path(directory) / "marketdb.duckdb"))
212
+ print(db.init())
213
+ print(db.sql("SELECT schema_version FROM _marketdb_meta"))
214
+ print(db.status())
215
+ print(db.validate())
216
+ ```
217
+
218
+ `sync(dataset, **overrides)` 会访问远端;`repair(dataset=None)` 在存在最新的失败或未完整同步时,按日志中的原参数重试。`sql(query, limit=None)` 只执行单条只读查询,`export(table, path, fmt=None)` 支持 CSV/Parquet。`status()` 查看本地表和最近同步记录,`validate()` 检查本地日志、类型、键及完整性证据;它不能仅凭本地行数证明远端历史已完整。
219
+
220
+ **14 个预设数据集的服务端分页、截断和键唯一性还缺当前环境的逐项证据;真实服务端验证留待后续。** `sync` 只有在服务端分页元数据与请求范围逐页吻合时,才写入数据并报告 `complete`;否则记录 `incomplete`、写入 0 行。一次同步在受控内存中缓存结果,上限为 100,000 行或约 64 MiB 规范 JSON;超限报错且不写入正式业务表。请检查返回对象中的 `status`、`reason`、`received_rows` 和 `written_rows`,不要把 HTTP 成功或原型中的固定行数上限当成完整性证明。
221
+
222
+ ## 错误与诊断
223
+
224
+ ```python
225
+ from meridian_kit_sdk import (
226
+ MeridianApiError,
227
+ MeridianClient,
228
+ MeridianResponseError,
229
+ MeridianResultError,
230
+ MeridianTransportError,
231
+ )
232
+
233
+ try:
234
+ with MeridianClient() as client:
235
+ result = client.get_s_stockname(code=["600745.SH"])
236
+ print(client.rows(result))
237
+ except MeridianApiError as error:
238
+ print(error.status_code, error.error_code, error.request_id)
239
+ except MeridianTransportError as error:
240
+ print(error.cause)
241
+ except MeridianResponseError as error:
242
+ print(error.request_id)
243
+ except MeridianResultError as error:
244
+ print(error.error_code)
245
+ ```
246
+
247
+ `MeridianApiError` 保留 HTTP 状态、服务端错误码、request ID 和原始 `requests.Response`。`MeridianTransportError` 保留底层原因;成功状态但 JSON 非法、或 JSON 结果形状不合预期,分别由响应和结果异常指出。不要将 `401`、`403`、`429` 统一归成一种“认证失败”。默认不自动重试;是否重试要结合端点语义、限流和计费规则判断。记录诊断信息时,只脱敏真实 Key 等必要字段,不要丢弃错误链路。
248
+
249
+ ## 旧凭证迁移与验证
250
+
251
+ SDK 使用 API Key,不再接收旧 `access_key` / `secret_key` 签名参数;旧 SK 不能直接充当新 API Key。新 Key 在 [UltraStiching 网站](https://www.ultrastiching.com)的账号 API Key 页面创建,再按上面的配置说明提供给客户端。
252
+
253
+ 在仓库根目录运行离线测试:
254
+
255
+ ```bash
256
+ python -m pip install -e './python[test]'
257
+ python -m pytest python
258
+ ```
259
+
260
+ 本地测试和注册表对账不代表测试环境或正式环境的在线验收。许可证为 [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0),发行包内也包含完整许可证文件。
261
+
262
+ ## 2026-10-07 参数更新
263
+
264
+ 金融 POST 改用当前公开平铺字段,例如 `{"code":["600745.SH"]}`,不再套用旧 `symbols` 模型或 `params` 外层对象。按新签名使用关键字参数;`get_s_tdaysoffset` 的日期和频率参数为 `calendar_date/frequency`,`get_fd_getfundid` 使用 `code_format`。旧目录已移出的 44 个接口不生成方法;因子分析的 `horizon_days` 按当前目录使用整数。生成验证不能代替线上调用验收。