doridata 0.2.0__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.
- doridata-0.2.0/.gitignore +11 -0
- doridata-0.2.0/LICENSE +201 -0
- doridata-0.2.0/PKG-INFO +121 -0
- doridata-0.2.0/README.md +92 -0
- doridata-0.2.0/docs/configuration.md +89 -0
- doridata-0.2.0/docs/sources.md +85 -0
- doridata-0.2.0/examples/doribt_etf.py +75 -0
- doridata-0.2.0/examples/profiles.toml +36 -0
- doridata-0.2.0/pyproject.toml +54 -0
- doridata-0.2.0/src/doridata/__init__.py +76 -0
- doridata-0.2.0/src/doridata/archive.py +262 -0
- doridata-0.2.0/src/doridata/backtest.py +69 -0
- doridata-0.2.0/src/doridata/catalog.py +15 -0
- doridata-0.2.0/src/doridata/cli.py +65 -0
- doridata-0.2.0/src/doridata/client.py +485 -0
- doridata-0.2.0/src/doridata/config/__init__.py +5 -0
- doridata-0.2.0/src/doridata/config/control.py +157 -0
- doridata-0.2.0/src/doridata/config/profile.py +241 -0
- doridata-0.2.0/src/doridata/contracts/__init__.py +1 -0
- doridata-0.2.0/src/doridata/contracts/provider.py +103 -0
- doridata-0.2.0/src/doridata/contracts/records.py +86 -0
- doridata-0.2.0/src/doridata/journal.py +154 -0
- doridata-0.2.0/src/doridata/model.py +153 -0
- doridata-0.2.0/src/doridata/providers/__init__.py +1 -0
- doridata-0.2.0/src/doridata/providers/akshare/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/akshare/daily.py +47 -0
- doridata-0.2.0/src/doridata/providers/akshare/definition.py +22 -0
- doridata-0.2.0/src/doridata/providers/baostock/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/baostock/daily.py +82 -0
- doridata-0.2.0/src/doridata/providers/baostock/definition.py +24 -0
- doridata-0.2.0/src/doridata/providers/baostock/events.py +113 -0
- doridata-0.2.0/src/doridata/providers/eastmoney/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/eastmoney/contract.py +5 -0
- doridata-0.2.0/src/doridata/providers/eastmoney/daily.py +49 -0
- doridata-0.2.0/src/doridata/providers/eastmoney/definition.py +21 -0
- doridata-0.2.0/src/doridata/providers/http_daily.py +37 -0
- doridata-0.2.0/src/doridata/providers/qmt/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/qmt/daily.py +67 -0
- doridata-0.2.0/src/doridata/providers/qmt/definition.py +24 -0
- doridata-0.2.0/src/doridata/providers/qmt/minute.py +97 -0
- doridata-0.2.0/src/doridata/providers/registry.py +78 -0
- doridata-0.2.0/src/doridata/providers/sdk_frames.py +41 -0
- doridata-0.2.0/src/doridata/providers/sina/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/sina/contract.py +5 -0
- doridata-0.2.0/src/doridata/providers/sina/daily.py +38 -0
- doridata-0.2.0/src/doridata/providers/sina/definition.py +24 -0
- doridata-0.2.0/src/doridata/providers/tdx/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/tdx/daily.py +74 -0
- doridata-0.2.0/src/doridata/providers/tdx/definition.py +30 -0
- doridata-0.2.0/src/doridata/providers/tencent/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/tencent/contract.py +5 -0
- doridata-0.2.0/src/doridata/providers/tencent/daily.py +31 -0
- doridata-0.2.0/src/doridata/providers/tencent/definition.py +28 -0
- doridata-0.2.0/src/doridata/providers/tushare/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/tushare/account.py +52 -0
- doridata-0.2.0/src/doridata/providers/tushare/api.py +116 -0
- doridata-0.2.0/src/doridata/providers/tushare/daily.py +65 -0
- doridata-0.2.0/src/doridata/providers/tushare/definition.py +24 -0
- doridata-0.2.0/src/doridata/providers/tushare/fundamentals.py +184 -0
- doridata-0.2.0/src/doridata/providers/tushare/sdk.py +62 -0
- doridata-0.2.0/src/doridata/providers/yahoo/__init__.py +5 -0
- doridata-0.2.0/src/doridata/providers/yahoo/contract.py +3 -0
- doridata-0.2.0/src/doridata/providers/yahoo/daily.py +44 -0
- doridata-0.2.0/src/doridata/providers/yahoo/definition.py +23 -0
- doridata-0.2.0/src/doridata/quota.py +91 -0
- doridata-0.2.0/src/doridata/routing/__init__.py +1 -0
- doridata-0.2.0/src/doridata/routing/collect.py +268 -0
- doridata-0.2.0/src/doridata/routing/facts.py +154 -0
- doridata-0.2.0/src/doridata/routing/plan.py +202 -0
- doridata-0.2.0/src/doridata/runtime.py +231 -0
- doridata-0.2.0/src/doridata/sdk.py +7 -0
- doridata-0.2.0/src/doridata/selection.py +27 -0
- doridata-0.2.0/src/doridata/shared_quota.py +119 -0
- doridata-0.2.0/src/doridata/source.py +132 -0
- doridata-0.2.0/src/doridata/tdx.py +5 -0
- doridata-0.2.0/src/doridata/transport/__init__.py +1 -0
- doridata-0.2.0/src/doridata/transport/http.py +265 -0
- doridata-0.2.0/src/doridata/tushare.py +6 -0
- doridata-0.2.0/src/doridata/version.py +1 -0
- doridata-0.2.0/src/doridata/web.py +9 -0
- doridata-0.2.0/tests/http_fixture.py +24 -0
- doridata-0.2.0/tests/test_archive.py +156 -0
- doridata-0.2.0/tests/test_client.py +187 -0
- doridata-0.2.0/tests/test_control.py +97 -0
- doridata-0.2.0/tests/test_products.py +205 -0
- doridata-0.2.0/tests/test_providers.py +232 -0
- doridata-0.2.0/tests/test_quota.py +128 -0
- doridata-0.2.0/tests/test_registration.py +49 -0
- doridata-0.2.0/tests/test_routing.py +258 -0
- doridata-0.2.0/tests/test_transport_sessions.py +83 -0
doridata-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising 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
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
doridata-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: doridata
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Auditable multi-source market data for mainland Chinese stocks and ETFs
|
|
5
|
+
Project-URL: Repository, https://github.com/DorisLab/DoriData
|
|
6
|
+
Project-URL: Issues, https://github.com/DorisLab/DoriData/issues
|
|
7
|
+
Author: DorisLab
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: anyio<5,>=4.14.1
|
|
12
|
+
Requires-Dist: httpx<0.29,>=0.28.1
|
|
13
|
+
Requires-Dist: pydantic<3,>=2.13.4; python_version < '3.15'
|
|
14
|
+
Requires-Dist: pydantic<3,>=2.14.4; python_version >= '3.15'
|
|
15
|
+
Requires-Dist: tenacity<10,>=9.2.1
|
|
16
|
+
Requires-Dist: tomli-w<2,>=1.2
|
|
17
|
+
Provides-Extra: akshare
|
|
18
|
+
Requires-Dist: akshare<2,>=1.20.71; (python_full_version >= '3.11.5') and extra == 'akshare'
|
|
19
|
+
Provides-Extra: baostock
|
|
20
|
+
Requires-Dist: baostock<1,>=0.9.4; extra == 'baostock'
|
|
21
|
+
Provides-Extra: qmt
|
|
22
|
+
Requires-Dist: numpy<3,>=1.26; (sys_platform == 'win32' and platform_machine == 'AMD64') and extra == 'qmt'
|
|
23
|
+
Requires-Dist: pandas<4,>=2.2; (sys_platform == 'win32' and platform_machine == 'AMD64') and extra == 'qmt'
|
|
24
|
+
Requires-Dist: xtquant>=250807.1.2; (sys_platform == 'win32' and platform_machine == 'AMD64') and extra == 'qmt'
|
|
25
|
+
Provides-Extra: tushare
|
|
26
|
+
Requires-Dist: six<2,>=1.17; extra == 'tushare'
|
|
27
|
+
Requires-Dist: tushare<2,>=1.4.29; extra == 'tushare'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# DoriData
|
|
31
|
+
|
|
32
|
+
DoriData 是面向 A 股和场内 ETF 的 Python 多源行情连接器。个人可以从免费日线和分红开始。有终端或账号的用户可在同一批请求中读取分钟、估值、因子和财报,按字段追溯来源。当前正式版为 0.2.0。[配置、字段与运行回执](docs/configuration.md)
|
|
33
|
+
|
|
34
|
+
## 从免费日线开始
|
|
35
|
+
|
|
36
|
+
需要 Python 3.11 或以上版本。基础包包括 HTTPX、AnyIO、Pydantic、Tenacity 与 Tomli-W。以下安装方式额外启用 BaoStock。
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m pip install "doridata[baostock]==0.2.0"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from doridata import Client, Query
|
|
44
|
+
|
|
45
|
+
client = Client()
|
|
46
|
+
query = Query.daily("510300.SH", "2025-06-17", "2025-06-20", asset="etf")
|
|
47
|
+
result = client.fetch(query)
|
|
48
|
+
|
|
49
|
+
if result.status == "ok":
|
|
50
|
+
print(result.selected)
|
|
51
|
+
for bar in result.bars:
|
|
52
|
+
print(bar.session, bar.close, bar.volume)
|
|
53
|
+
else:
|
|
54
|
+
for attempt in result.attempts:
|
|
55
|
+
print(attempt.source, attempt.status, attempt.message)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
默认依次尝试 BaoStock、新浪、腾讯、东方财富。第一个符合要求的来源提供整个窗口。价格为未复权人民币元,股票成交量为股,ETF 成交量为份。成交额以人民币元计,源端缺少时返回 `None`。未提供应有交易日时,`calendar_verified` 为 `False`。
|
|
59
|
+
|
|
60
|
+
## 给日线加一道核验
|
|
61
|
+
|
|
62
|
+
同一个例子跨过 510300 的除息日。这里要求四天齐全,并用腾讯逐日核验候选的开、高、低、收。日历由调用方提供,可以包含停牌、上市或退市安排所要求的证券级日期。
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from doridata import Client, Policy, Query
|
|
66
|
+
|
|
67
|
+
sessions = ("2025-06-17", "2025-06-18", "2025-06-19", "2025-06-20")
|
|
68
|
+
query = Query.daily("510300.SH", sessions[0], sessions[-1],
|
|
69
|
+
asset="etf", expected_sessions=sessions)
|
|
70
|
+
policy = Policy(sources=("baostock", "sina"), references=("tencent",))
|
|
71
|
+
result = Client().fetch(query, policy)
|
|
72
|
+
print(result.status, result.selected, result.calendar_verified)
|
|
73
|
+
|
|
74
|
+
for diff in result.differences:
|
|
75
|
+
print(diff.session, diff.field, diff.candidate_value, diff.reference_value, diff.blocking)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
实采时,两源在这四天的 OHLC 一致。6 月 18 日 BaoStock 的成交量比腾讯多 10 份。默认记录成交量差异,配置 `volume_tolerance=0` 会要求精确一致。价格比较使用绝对容差,默认每股或每份 `0.000001` 元。若发现超出容差的价格冲突,结果为 `conflict`,行情行为空。AKShare 当前的两个适配接口都使用新浪,选源时会识别这个共同上游。
|
|
79
|
+
|
|
80
|
+
## 给数据服务使用
|
|
81
|
+
|
|
82
|
+
- `client.observe(query, "tushare")` 单独读取指定来源。可查看该来源实际返回的行、缺失日期和验收结果。
|
|
83
|
+
- `client.fetch(query, policy)` 执行选源与核验。各次尝试记录来源、已知上游、UTC 观察时间、耗时、缺失日期和证据摘要。配置了对照源后,至少需要一个不同上游覆盖相同日期并通过核验。
|
|
84
|
+
- `Client(evidence=save)` 将证据交给调用方的 `save(receipt, payload)` 函数,`payload` 为字节。每份证据带 SHA-256,适合按内容去重。证据存储失败会抛出 `EvidenceError`。未配置回调时只生成摘要。
|
|
85
|
+
- Tushare 根据账号积分和接口分别限流,可覆盖账号总预算、接口预算和最长等待时间。持密钥的适配器和终端 SDK 都按需启用。见[来源、额度与实采结果](docs/sources.md)。
|
|
86
|
+
- 使用固定 Git 提交或内部镜像可以复现实验。数据湖负责维护自己的交易日历、允许来源、原件存储和发布规则。回测程序可把开高低收及成交量接入行情表,交易状态、历史涨跌停价和分红另行取得。
|
|
87
|
+
|
|
88
|
+
### 从原始响应重放一次选源
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from doridata import Client, Policy, Query, RunArchive, capabilities
|
|
92
|
+
|
|
93
|
+
q = Query.daily("510300.SH", "2025-06-18", "2025-06-18",
|
|
94
|
+
asset="etf", expected_sessions=("2025-06-18",))
|
|
95
|
+
print([(c.channel, c.upstream, c.native_volume) for c in capabilities(q)])
|
|
96
|
+
store = RunArchive("./market-evidence")
|
|
97
|
+
policy = Policy(sources=("baostock", "sina"), references=("tencent",),
|
|
98
|
+
unavailable_only=("sina",))
|
|
99
|
+
result, run_id = store.record(Client(), q, policy, policy_id="research/1")
|
|
100
|
+
checked = store.replay(run_id, reparse=True)
|
|
101
|
+
print(run_id, checked.status, checked.selected)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`run_id` 标识一次观察及其策略版本。相同原件按 SHA-256 去重。再次采集遇到供应商修订时可以分别重放两次决定。内置适配器可以从已归档的 HTTP 响应、SDK 表或本地日线文件离线解析。限流、缺权限及网络失败按当时的观察重放。调用方负责证据目录的访问、保留期和备份。
|
|
105
|
+
|
|
106
|
+
### 在 DoriBT 中读取跨除息日的 ETF 行情
|
|
107
|
+
|
|
108
|
+
安装 `doribt==0.6.2` 和本包的 `baostock` 可选依赖后,在仓库根目录运行以下命令。示例免费获取 510300 的原价和交易状态,按这只 ETF 在样本期适用的规则计算涨跌停价,向 DoriBT 单独传入每份 0.088 元的分红事件。其他证券可以用 `SessionFacts` 传入各自的历史交易状态和涨跌停价。[完整示例](examples/doribt_etf.py) · [基金分红公告](https://www.sse.com.cn/disclosure/fund/announcement/c/new/2025-06-11/510300_20250611_ZAU4.pdf) · [基金交易规则](https://www.sse.com.cn/disclosure/fund/announcement/c/new/2022-06-11/510300_20220611_1_i59GRWtC.pdf) · [样本期上交所交易规则](https://www.sse.com.cn/lawandrules/sselawsrules2025/repeal/rules/c/c_20250612_10824490.shtml)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
python examples/doribt_etf.py ./market-evidence
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 开发与许可
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
python -m pip install -e .
|
|
118
|
+
python -m unittest discover -s tests -v
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
离线测试使用合成输入。实采结果及每个渠道的限制见[验收记录](docs/sources.md#首轮样本)。连接器代码采用 [Apache-2.0](LICENSE)。各来源的访问条件和行情使用权按各自约定执行。
|
doridata-0.2.0/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# DoriData
|
|
2
|
+
|
|
3
|
+
DoriData 是面向 A 股和场内 ETF 的 Python 多源行情连接器。个人可以从免费日线和分红开始。有终端或账号的用户可在同一批请求中读取分钟、估值、因子和财报,按字段追溯来源。当前正式版为 0.2.0。[配置、字段与运行回执](docs/configuration.md)
|
|
4
|
+
|
|
5
|
+
## 从免费日线开始
|
|
6
|
+
|
|
7
|
+
需要 Python 3.11 或以上版本。基础包包括 HTTPX、AnyIO、Pydantic、Tenacity 与 Tomli-W。以下安装方式额外启用 BaoStock。
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
python -m pip install "doridata[baostock]==0.2.0"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from doridata import Client, Query
|
|
15
|
+
|
|
16
|
+
client = Client()
|
|
17
|
+
query = Query.daily("510300.SH", "2025-06-17", "2025-06-20", asset="etf")
|
|
18
|
+
result = client.fetch(query)
|
|
19
|
+
|
|
20
|
+
if result.status == "ok":
|
|
21
|
+
print(result.selected)
|
|
22
|
+
for bar in result.bars:
|
|
23
|
+
print(bar.session, bar.close, bar.volume)
|
|
24
|
+
else:
|
|
25
|
+
for attempt in result.attempts:
|
|
26
|
+
print(attempt.source, attempt.status, attempt.message)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
默认依次尝试 BaoStock、新浪、腾讯、东方财富。第一个符合要求的来源提供整个窗口。价格为未复权人民币元,股票成交量为股,ETF 成交量为份。成交额以人民币元计,源端缺少时返回 `None`。未提供应有交易日时,`calendar_verified` 为 `False`。
|
|
30
|
+
|
|
31
|
+
## 给日线加一道核验
|
|
32
|
+
|
|
33
|
+
同一个例子跨过 510300 的除息日。这里要求四天齐全,并用腾讯逐日核验候选的开、高、低、收。日历由调用方提供,可以包含停牌、上市或退市安排所要求的证券级日期。
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from doridata import Client, Policy, Query
|
|
37
|
+
|
|
38
|
+
sessions = ("2025-06-17", "2025-06-18", "2025-06-19", "2025-06-20")
|
|
39
|
+
query = Query.daily("510300.SH", sessions[0], sessions[-1],
|
|
40
|
+
asset="etf", expected_sessions=sessions)
|
|
41
|
+
policy = Policy(sources=("baostock", "sina"), references=("tencent",))
|
|
42
|
+
result = Client().fetch(query, policy)
|
|
43
|
+
print(result.status, result.selected, result.calendar_verified)
|
|
44
|
+
|
|
45
|
+
for diff in result.differences:
|
|
46
|
+
print(diff.session, diff.field, diff.candidate_value, diff.reference_value, diff.blocking)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
实采时,两源在这四天的 OHLC 一致。6 月 18 日 BaoStock 的成交量比腾讯多 10 份。默认记录成交量差异,配置 `volume_tolerance=0` 会要求精确一致。价格比较使用绝对容差,默认每股或每份 `0.000001` 元。若发现超出容差的价格冲突,结果为 `conflict`,行情行为空。AKShare 当前的两个适配接口都使用新浪,选源时会识别这个共同上游。
|
|
50
|
+
|
|
51
|
+
## 给数据服务使用
|
|
52
|
+
|
|
53
|
+
- `client.observe(query, "tushare")` 单独读取指定来源。可查看该来源实际返回的行、缺失日期和验收结果。
|
|
54
|
+
- `client.fetch(query, policy)` 执行选源与核验。各次尝试记录来源、已知上游、UTC 观察时间、耗时、缺失日期和证据摘要。配置了对照源后,至少需要一个不同上游覆盖相同日期并通过核验。
|
|
55
|
+
- `Client(evidence=save)` 将证据交给调用方的 `save(receipt, payload)` 函数,`payload` 为字节。每份证据带 SHA-256,适合按内容去重。证据存储失败会抛出 `EvidenceError`。未配置回调时只生成摘要。
|
|
56
|
+
- Tushare 根据账号积分和接口分别限流,可覆盖账号总预算、接口预算和最长等待时间。持密钥的适配器和终端 SDK 都按需启用。见[来源、额度与实采结果](docs/sources.md)。
|
|
57
|
+
- 使用固定 Git 提交或内部镜像可以复现实验。数据湖负责维护自己的交易日历、允许来源、原件存储和发布规则。回测程序可把开高低收及成交量接入行情表,交易状态、历史涨跌停价和分红另行取得。
|
|
58
|
+
|
|
59
|
+
### 从原始响应重放一次选源
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from doridata import Client, Policy, Query, RunArchive, capabilities
|
|
63
|
+
|
|
64
|
+
q = Query.daily("510300.SH", "2025-06-18", "2025-06-18",
|
|
65
|
+
asset="etf", expected_sessions=("2025-06-18",))
|
|
66
|
+
print([(c.channel, c.upstream, c.native_volume) for c in capabilities(q)])
|
|
67
|
+
store = RunArchive("./market-evidence")
|
|
68
|
+
policy = Policy(sources=("baostock", "sina"), references=("tencent",),
|
|
69
|
+
unavailable_only=("sina",))
|
|
70
|
+
result, run_id = store.record(Client(), q, policy, policy_id="research/1")
|
|
71
|
+
checked = store.replay(run_id, reparse=True)
|
|
72
|
+
print(run_id, checked.status, checked.selected)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`run_id` 标识一次观察及其策略版本。相同原件按 SHA-256 去重。再次采集遇到供应商修订时可以分别重放两次决定。内置适配器可以从已归档的 HTTP 响应、SDK 表或本地日线文件离线解析。限流、缺权限及网络失败按当时的观察重放。调用方负责证据目录的访问、保留期和备份。
|
|
76
|
+
|
|
77
|
+
### 在 DoriBT 中读取跨除息日的 ETF 行情
|
|
78
|
+
|
|
79
|
+
安装 `doribt==0.6.2` 和本包的 `baostock` 可选依赖后,在仓库根目录运行以下命令。示例免费获取 510300 的原价和交易状态,按这只 ETF 在样本期适用的规则计算涨跌停价,向 DoriBT 单独传入每份 0.088 元的分红事件。其他证券可以用 `SessionFacts` 传入各自的历史交易状态和涨跌停价。[完整示例](examples/doribt_etf.py) · [基金分红公告](https://www.sse.com.cn/disclosure/fund/announcement/c/new/2025-06-11/510300_20250611_ZAU4.pdf) · [基金交易规则](https://www.sse.com.cn/disclosure/fund/announcement/c/new/2022-06-11/510300_20220611_1_i59GRWtC.pdf) · [样本期上交所交易规则](https://www.sse.com.cn/lawandrules/sselawsrules2025/repeal/rules/c/c_20250612_10824490.shtml)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python examples/doribt_etf.py ./market-evidence
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 开发与许可
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
python -m pip install -e .
|
|
89
|
+
python -m unittest discover -s tests -v
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
离线测试使用合成输入。实采结果及每个渠道的限制见[验收记录](docs/sources.md#首轮样本)。连接器代码采用 [Apache-2.0](LICENSE)。各来源的访问条件和行情使用权按各自约定执行。
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# 配置、采集与回放
|
|
2
|
+
|
|
3
|
+
本页适用于正式版 0.2.0。最短路径是加载示例里的 free 策略,给出证券、时间和字段。下例拿到沪深 300 ETF 的未复权收盘和成交份数,并说明每个字段来自哪里。
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from doridata import Client, Configuration, DataQuery, Query
|
|
7
|
+
|
|
8
|
+
profiles = Configuration.load("examples/profiles.toml").profiles
|
|
9
|
+
client = Client.from_profile(profiles["free"])
|
|
10
|
+
instrument = Query.daily("510300.SH", "2025-06-17", "2025-06-20", asset="etf",
|
|
11
|
+
expected_sessions=("2025-06-17", "2025-06-18", "2025-06-19", "2025-06-20"))
|
|
12
|
+
request = DataQuery(instrument, "cn.etf.daily", ("close", "volume"))
|
|
13
|
+
result = client.collect(request)
|
|
14
|
+
for row in result.rows:
|
|
15
|
+
print(row.session, row.values, row.origins["close"].upstream, row.missing)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### 安装与诊断
|
|
19
|
+
|
|
20
|
+
AKShare 可选组件要求 Python 3.11.5 或更高版本。Python 3.11.0 至 3.11.4 可以使用基础包和兼容的其他来源。
|
|
21
|
+
|
|
22
|
+
从源码安装使用 `python -m pip install .`。免费 HTTP 日线随基础包安装。按需选择 `".[baostock]"`、`".[akshare]"`、`".[tushare]"` 或 Windows x64 的 `".[qmt]"`。迅投行情由已连接的 MiniQMT 提供。终端磁盘没有某段历史时,默认读取会报告缺口。需要向终端请求下载时,可显式配置 `providers.qmt.download = true`。通达信读取已下载的 vipdoc 日线,ETF 文件的价格除数与量单位需要按文件版本声明。
|
|
23
|
+
|
|
24
|
+
| 命令 | 可以回答的问题 |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `doridata describe --source tushare` | 有哪些接口,原始字段怎样映射,字段的类型、单位、主键和披露日期精度是什么。省略来源可列出全部九个渠道。 |
|
|
27
|
+
| `doridata validate --config examples/profiles.toml --profile free` | 这份策略能否构造,显式启用的凭据引用是否可用,字段名和来源接口是否匹配。 |
|
|
28
|
+
| `doridata plan --asset etf --symbol 510300.SH --start 2025-06-17 --end 2025-06-20` | 会先访问谁、用谁对照、哪些源缺 SDK 或配置。预览的上游调用数为零。 |
|
|
29
|
+
| `doridata doctor --source baostock --asset etf --symbol 510300.SH --start 2025-06-17 --end 2025-06-20` | 在当前节点实际读取指定来源,返回状态、实到行数和证据。调用会使用账号额度。 |
|
|
30
|
+
|
|
31
|
+
配置文件与 Python 共用类型约束。可通过 `Configuration.model_json_schema()` 生成表单,通过 `profile.model_dump(mode="json")` 查看生效值,通过 `Configuration.to_toml()` 导出。填错字段时读取 `ConfigurationError.issues` 中的 path 和 code。凭据字段保存环境变量名称。Tushare 的 points 是用户声明的积分,endpoints 是该账号实有权限的显式清单。预算可按账号和接口同时收紧,每次真实请求都要取得这两份额度。上游授权最终以实际响应为准。[可直接加载的两份策略](../examples/profiles.toml)
|
|
32
|
+
|
|
33
|
+
### 多品类和单字段
|
|
34
|
+
|
|
35
|
+
| 数据集 | 本版已接入的接口及口径 |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| cn.stock.daily、cn.etf.daily | 九个渠道的适用市场、原价或 Yahoo 原生价、数量单位和历史边界可按 describe 查询。日线默认返回四价和成交量。 |
|
|
38
|
+
| cn.stock.minute、cn.etf.minute | QMT XtData 的 1 分钟未复权行情,保留交易所当地时间戳和原始返回行。传入应有交易日可按日查漏,校验日内所有分钟须提供市场的具体时段规则。 |
|
|
39
|
+
| cn.stock.valuation_daily | Tushare daily_basic 的 pe_ttm、pb、turnover_rate、total_mv。市值换算成人民币元。亏损时的 PE 空值具有业务含义。 |
|
|
40
|
+
| cn.stock.adjustment、cn.etf.adjustment | Tushare adj_factor、fund_adj 的供应商日因子。 |
|
|
41
|
+
| cn.stock.adjustment_events、cn.etf.adjustment_events | BaoStock 除权事件上的前、后复权及调整系数。保留原乘数定义和事件粒度。 |
|
|
42
|
+
| cn.stock.dividends、cn.etf.dividends | BaoStock 分红数据和 Tushare dividend、fund_div 的实施事件。按登记、派息及公告等业务键识别同一次支付。同一支付有多个供应商原行时,保留共同值,出现分歧的请求字段返回 partial 与原因。 |
|
|
43
|
+
| cn.stock.financials | Tushare fina_indicator 的 EPS、稀释 EPS 与 ROE,保留报告期、公告日期和更新标记。 |
|
|
44
|
+
| cn.stock.trading_limits | Tushare stk_limit 的历史涨跌停价。免费日线中可读交易状态的来源见字段目录。需要历史限价时可在有该权限的账号下请求。 |
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import anyio
|
|
48
|
+
from doridata import Configuration, ConfiguredClient, DataQuery, Query
|
|
49
|
+
|
|
50
|
+
policy = Configuration.load("examples/profiles.toml").profiles["research"]
|
|
51
|
+
client = ConfiguredClient(policy)
|
|
52
|
+
stock = Query.daily("600519.SH", "2025-06-17", "2025-06-20", asset="stock")
|
|
53
|
+
quarter = Query.daily("600519.SH", "2025-03-31", "2025-03-31", asset="stock")
|
|
54
|
+
requests = [
|
|
55
|
+
DataQuery(stock, "cn.stock.daily", ("open", "close", "volume")),
|
|
56
|
+
DataQuery(stock, "cn.stock.minute", ("timestamp", "close", "volume")),
|
|
57
|
+
DataQuery(stock, "cn.stock.valuation_daily", ("pe_ttm", "pb")),
|
|
58
|
+
DataQuery(stock, "cn.stock.adjustment", ("adj_factor",)),
|
|
59
|
+
DataQuery(quarter, "cn.stock.financials", ("end_date", "ann_date", "eps", "roe")),
|
|
60
|
+
]
|
|
61
|
+
results = anyio.run(client.collect_many, requests)
|
|
62
|
+
for r in results:
|
|
63
|
+
print(r.query.dataset, r.status, len(r.rows), r.run_id)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
日线四价作为一组。同一交易日的 OHLC 来自同一渠道。whole_window 要求候选覆盖整个窗口,per_session 按传入的证券级应有交易日选择,每个供应商的原窗口只读一次。compare 配置独立对照,Sina 与经 AKShare 访问的 Sina 共用上游身份。真实价差返回 conflict 和逐字段差额。只允许在主源不可用时使用的后备,可列入 unavailable_only。
|
|
67
|
+
|
|
68
|
+
成交量、成交额和交易状态可在 fields 下显式指定来源。补值跨越来源时填写 comparability,引用本机构已核实的单位、成交范围和交易时段证据。四价一致只能确认相应价格。每字段回执列出原名、原单位、规范单位、上游、观察时间、解析版本和原件摘要。
|
|
69
|
+
|
|
70
|
+
```toml
|
|
71
|
+
[profiles.research.datasets."cn.stock.daily".fields.amount]
|
|
72
|
+
sources = ["qmt", "tushare.daily"]
|
|
73
|
+
fill = "missing_only"
|
|
74
|
+
# 核实相同成交范围后填写自己的证据编号
|
|
75
|
+
# comparability = "..."
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Tushare 的日线和基本面走带凭据的 HTTPS 原生查询。装有官方 SDK 时,`frame, receipts = client.pro_bar(stock, adjustment="qfq")` 使用供应商的前复权算法。底层日线和因子请求都按同一账号计量,原件可由 evidence 回调保存。OHLC 回测、除权现金和股数变化分别取所需字段。
|
|
79
|
+
|
|
80
|
+
Tushare 已实施的分红按证券、登记日、除息日、支付日及实施公告区分,股票还核对报告期。同次支付的前期公告日期可以不同。原件保留各行,申请不同值的公告日期会收到 `native_variants_disagree`。同组出现多行且支付身份不完整时,现金及送股字段返回 `incomplete_payment_identity`。不同支付日或实施公告各自保留。股票和基金分红使用产品结构第 2 版。
|
|
81
|
+
|
|
82
|
+
### 宿主接入
|
|
83
|
+
|
|
84
|
+
- **日志与证据。** 用 `logging.getLogger("doridata")` 配置标准日志处理器。运行回执含 run_id、配置摘要、来源结果与物理 HTTP 尝试。用 `RunArchive(directory).keep` 作 evidence 回调可按 SHA-256 保存原件。默认仅生成摘要。日志和目录中只出现凭据引用。
|
|
85
|
+
- **历史观察。** 构造 `ConfiguredClient(profile, journal=FactJournal("observations.sqlite"))` 开始保存本次及以后的观察。为同一请求传入带时区的 as_of,只会返回截点前实际留存的版本。策略、字段或来源限制不同,或截点早于首次观察,返回 not_observed_as_of。报告期与首次观察时间分别保留,同披露日仍有多个版本时供调用方检查。
|
|
86
|
+
- **续跑。** 同一客户端使用 `await client.collect_many(requests, batch_id="research-june", progress=callback)`。成功分片及其 run_id 随数据库留存,失败的分片下次按同一配置和请求清单重试。重新采集一批新行情请分配新的批次 ID。
|
|
87
|
+
- **配置管理。** ConfigStore 的 preview 能比较两份配置对真实请求的影响。activate 以基准版本、操作者、变更原因为参数,旧版本冲突会抛 RevisionConflict。acknowledge 记录节点实际加载结果,status 可区分已生效、待加载及尚无观测。rollback 追加新的审计版本。访问控制由接入界面的宿主实施。
|
|
88
|
+
- **共享预算。** 默认 RateLimiter 在进程内按账号与接口共同扣额。多个进程在同一节点可注入 SQLiteRateLimiter 并共用本地文件。apply_budget 让仍持旧配置的 worker 在下一次请求时遵守收紧的预算,已用次数和供应商冷却期继续生效。多机部署通过相同接口接入集中额度服务。
|
|
89
|
+
- **扩展与回放。** ProviderRegistry.register 同时登记创建入口、原生产品及解析器版本。外部插件通过 doridata.providers entry point 显式载入。RunArchive.replay 可逐件验证老版本日线归档及其选择。用 RunArchive.keep 留存分钟、估值、事件或财报原件后,可用 archive.reparse_product(result) 离线核对本次规范值。公司行动的支付日期、分红基准份额和股票的税前每股金额遵循各接口字段定义。[九个来源的基础能力](sources.md) · [基金分红字段](https://tushare.pro/document/2?doc_id=120) · [股票分红字段](https://tushare.pro/document/2?doc_id=103)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# 来源、额度与实采结果
|
|
2
|
+
|
|
3
|
+
## 0.2.0 的验证范围
|
|
4
|
+
|
|
5
|
+
| 入口 | 本版验证 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| 免费股票与 ETF | 在无凭据配置下,BaoStock 和腾讯分别取得沪深 300 ETF 与贵州茅台各四个交易日的未复权行情。DoriBT 0.6.2 实际读入跨除息窗口。 |
|
|
8
|
+
| 分红与因子 | BaoStock 股、基均取得分红和除权系数事件。部分同次支付的原始行在税前值上有分歧。接口按请求字段交付共同值及分歧原因。 |
|
|
9
|
+
| Tushare | 在有相应权限的账号下实际取得股票日线、估值、日因子、季度 EPS/ROE 和 ETF 现金分红。官方 SDK 的前复权日线使用相同的两个底层读取通道。 |
|
|
10
|
+
| 迅投 | Windows x64、CPython 3.11、xtquant 250807.1.2 与已登录终端实取股票和 ETF。近期样本每只证券有 241 根分钟线。更早的同一证券样本在该终端只有日线。SDK 的适用 Python 组合需与券商客户端一起验收。 |
|
|
11
|
+
| 通达信及其他 HTTP 入口 | 当前解析器从 0.1.0 日线归档重读五个交易日并核对 SHA。九个渠道均有离线入口测试。下表及首轮实采记录说明其他渠道已有的实际覆盖。 |
|
|
12
|
+
|
|
13
|
+
[按品类选择、配置与取证](configuration.md)
|
|
14
|
+
|
|
15
|
+
## 首版覆盖
|
|
16
|
+
|
|
17
|
+
使用 `600519.SH`、`000001.SZ` 这样的完整代码,并显式指定 `asset="stock"` 或 `"etf"`。传入前请根据证券目录确认身份。首轮真实样本覆盖沪深,北交所股票可向 Tushare、QMT 或自有通达信文件请求,本轮未实证北交所覆盖。
|
|
18
|
+
|
|
19
|
+
| 渠道名 | 入口与价格口径 | 成交量、使用条件与覆盖限制 |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `baostock` | 官方 SDK,`query_history_k_data_plus`,`adjustflag="3"` | 股/份,成交额为元,提供交易状态。安装 `.[baostock]` 后即可查询,SDK 会话在进程内串行使用。[BaoStock 接口](http://baostock.com/baostock/index.php/Python_API%E6%96%87%E6%A1%A3) |
|
|
22
|
+
| `sina` | 新浪公开日 K,原价 | 股/份,当前入口缺成交额。最多请求最近 1023 根,过早的窗口会报告覆盖不足。[新浪行情](https://finance.sina.com.cn/realstock/) |
|
|
23
|
+
| `tencent` | 腾讯日 K,仅接受原价 `day` 序列 | 沪深常见股票和 ETF 按手换算,沪市 688/689 段按股。部分日子的量已在上游舍入,当前入口缺成交额。[腾讯行情](https://gu.qq.com/) |
|
|
24
|
+
| `eastmoney` | 东方财富历史 K 线,日线 `klt=101`、不复权 `fqt=0` | 按手换算,成交额为元。会校验返回的交易所及代码。公开端点曾出现断连。[东方财富行情](https://quote.eastmoney.com/) |
|
|
25
|
+
| `akshare` | 股票用 `stock_zh_a_hist_sina`,ETF 用 `fund_etf_hist_sina` | 股/份,金额为元,安装 `.[akshare]`。两个接口的实际来源都登记为新浪。[AKShare 项目](https://github.com/akfamily/akshare) |
|
|
26
|
+
| `tushare` | Pro 的 `daily`、`fund_daily`,官方 HTTPS 接口 | 按手和千元换算,使用自己的 Token 和接口权限。下节给出预算配置。[股票日线](https://tushare.pro/document/2?doc_id=27) · [ETF 日线](https://tushare.pro/document/2?doc_id=127) |
|
|
27
|
+
| `qmt` | XtData 的本地日线,`dividend_type="none"`、`fill_data=False` | 按手换算,成交额为元。需要可连接的 QMT 行情服务及对应 SDK。默认读取现有记录,传入 `QMT(download=True)` 才会请求下载历史。[XtData 文档](https://dict.thinktrader.net/nativeApi/xtdata.html) |
|
|
28
|
+
| `yahoo` | Yahoo Finance Chart 的 `quote` 序列,必须显式请求 `basis="yahoo_native"` | 使用供应商报告的股/份,成交额缺失。Yahoo 的历史收盘价会按拆股处理,此序列只在自己的价格口径内使用。[Yahoo 历史价格说明](https://help.yahoo.com/kb/SLN28256.html) |
|
|
29
|
+
| `tdx` | 通达信本地 `vipdoc/<市场>/lday/*.day` 文件 | 通过 `DORIDATA_TDX_VIPDOC` 或构造参数指定自己的原始日线目录。股票样本已验。ETF 要显式给出在自己文件上核准的 `etf_price_divisor`,要读取成交量还需 `etf_volume_unit="shares"` 或 `"lots"`。[通达信数据下载](https://www.tdx.com.cn/article/vipdata.html) |
|
|
30
|
+
|
|
31
|
+
## Tushare 账号和额度
|
|
32
|
+
|
|
33
|
+
设置 `TUSHARE_TOKEN` 和 `TUSHARE_POINTS` 即可在 `Policy.sources` 中启用 `tushare`。也可以为服务显式构造账号。下例将账号约束得比公开上限更严格,以便给同账号的其他应用留出额度。
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import os
|
|
37
|
+
from doridata import Budget, Client, Policy, Tushare, TushareAccount
|
|
38
|
+
|
|
39
|
+
account = TushareAccount(
|
|
40
|
+
token=os.environ["TUSHARE_TOKEN"],
|
|
41
|
+
points=int(os.environ["TUSHARE_POINTS"]),
|
|
42
|
+
budgets={"daily": Budget(per_minute=80), "fund_daily": Budget(per_minute=40)},
|
|
43
|
+
account_budget=Budget(per_minute=100),
|
|
44
|
+
)
|
|
45
|
+
client = Client([Tushare(account, max_wait=2)])
|
|
46
|
+
policy = Policy(sources=("tushare",))
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
默认按声明的积分级别设置 50、200 或 500 次/分钟,并保留适用的每日接口上限。ETF 日线要求至少 5000 积分。对 8000 积分以上的实际提额,可以按账号已知权益单独配置。配置描述本地预算,服务端返回的权限或频率错误仍会记录在结果中。[Tushare 积分与频次](https://tushare.pro/document/1?doc_id=290) · [ETF 接口权限](https://tushare.pro/document/2?doc_id=127)
|
|
50
|
+
|
|
51
|
+
默认限流器按 Token 身份在同一进程的多个客户端之间共享。每个实际分页请求同时消耗账号和接口预算。分钟窗口按滚动 60 秒计,每日预算按北京时间零点重置。默认 `max_wait=0`,额度用尽会立即交回 `rate_limited`,本地额度会提供 `retry_after` 秒数。多进程服务可注入共用的限流器,实现 `acquire(identity, limits, max_wait)`。
|
|
52
|
+
|
|
53
|
+
## 读取结果
|
|
54
|
+
|
|
55
|
+
| `fetch` 状态 | 含义 |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `ok` | 一家来源提供整个窗口并符合本次策略,可从 `selected` 取得渠道名。 |
|
|
58
|
+
| `no_sessions` | 调用方显式传入空的应有日期,本次没有交易日需要采集。 |
|
|
59
|
+
| `no_candidate` | 配置的渠道均未取得可用窗口,逐次原因在 `attempts` 中。 |
|
|
60
|
+
| `unconfirmed` | 至少有一个候选可用,但独立对照未就绪。 |
|
|
61
|
+
| `conflict` | 候选与对照有超容差差异,字段、日期和双方数值在 `differences` 中。 |
|
|
62
|
+
| `invalid` | 来源返回了重复日期、身份冲突、OHLC 越界等无效记录,需检查该次采集。 |
|
|
63
|
+
|
|
64
|
+
`expected_sessions` 由使用方提供。当未给日历时,只能验证实际返回的行。对照源此时仍需与候选覆盖完全相同的日期。采集当日的生产应用还需根据交易所时区、收市时间和供方发布时间决定何时运行。证据时间表示本次观察时刻。
|
|
65
|
+
|
|
66
|
+
默认比较 OHLC 并记录可比的量差。成交额和交易状态随所选源原样提供,缺字段保留为空或 `unknown`。如需强制成交额、官方身份、首次可见时间等发布条件,由使用方依据这些观察追加验收。指定 `references` 时,已知共享上游会跳过。不同渠道的上游登记不构成对终极分发链的认证,严格验收应选用调用方认可的对照。
|
|
67
|
+
|
|
68
|
+
## 首轮样本
|
|
69
|
+
|
|
70
|
+
2026-12-02,使用同一套适配器读取 `600519.SH` 和 `510300.SH` 在 2025-06-17 至 2025-06-20 的四个交易日。ETF 窗口跨除息日,适合观察相邻两天是否保留原价跳变。
|
|
71
|
+
|
|
72
|
+
| 实际验证 | 观察 |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| BaoStock、新浪、腾讯、AKShare、东方财富 | 均取到股票和 ETF 各 4 行。东方财富在不同尝试中既有成功也有断连。BaoStock 与腾讯的两个窗口逐日四价完全一致,两只证券都有成交量尾差。 |
|
|
75
|
+
| Tushare、QMT | 分别通过已配置的账户、已连接的终端读到两个完整窗口。ETF 除息日两个来源的收盘均为 3.904,成交量相差 10 份。 |
|
|
76
|
+
| Yahoo | 两个窗口均有 4 行,按 `yahoo_native` 观察。此样本只覆盖现金分红附近的报价。 |
|
|
77
|
+
| 通达信 | 从 2026-12-01 官方盘后包取两只股票(600519、000001)和两只 ETF(510300、159915)的原文件,保留 ZIP 成员名、CRC32、长度与 SHA-256。四个交易日共 16 行,64 个 OHLC 和 16 个成交量逐值与 BaoStock 相符。这一版文件的 ETF 价格除数为 1000,量为份,可传 `TongdaXin(vipdoc, etf_price_divisor=1000, etf_volume_unit="shares")`。原件由使用者取得。[通达信官方盘后包](https://www.tdx.com.cn/article/vipdata.html) |
|
|
78
|
+
|
|
79
|
+
这些实采覆盖单证券短窗。全市场覆盖率、历史回填速度和长期可用性仍需按实际运行环境测量。
|
|
80
|
+
|
|
81
|
+
`TushareAccount(endpoints=..., expires_on=...)` 可以表达账号已核实的单项授权,日期按北京时间判断。接口达到 HTTP 429 且返回 Retry-After 时,同一凭据和接口后续请求共用冷却期。`Attempt.next_attempt_at` 给出有等待依据的下一次尝试时间。多进程限流器可同时实现 `acquire` 和 `cooldown`。
|
|
82
|
+
|
|
83
|
+
2021-05-14 的 000001 超出本次新浪接口能返回的最近 1023 根日线。指定通达信为仅在主源不可用时启用的备用,并指定 BaoStock 为对照,连接器从原文件选回该日,经离线重放得到相同决定。对停牌样本,来源给出状态而成交量留空时,要求成交量的策略会报告缺字段。退市后和上市前请求的空表保留为缺口;掌握证券存续期的调用方可以显式传入空的预期日历。
|
|
84
|
+
|
|
85
|
+
在贵州茅台的一个历史交易日,通达信与 BaoStock 的原始收盘相差 0.08 元,成交量相差 400 股。逐源保留原件和双方数值后,在线选择与断网重放都返回 `conflict`,所选行情为空。实测的账号额度场景中,新浪窗口未覆盖目标日,Tushare 达到调用方配置的每分钟一次预算,第三个候选通达信返回当日行情。HTTP 429 和供应商事后改值另有离线回归用例。
|