stocksenate 0.1.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.
Files changed (116) hide show
  1. stocksenate-0.1.0/LICENSE +201 -0
  2. stocksenate-0.1.0/NOTICE +29 -0
  3. stocksenate-0.1.0/PKG-INFO +402 -0
  4. stocksenate-0.1.0/README.md +353 -0
  5. stocksenate-0.1.0/pyproject.toml +104 -0
  6. stocksenate-0.1.0/setup.cfg +4 -0
  7. stocksenate-0.1.0/src/stock_senate/__init__.py +6 -0
  8. stocksenate-0.1.0/src/stock_senate/__main__.py +6 -0
  9. stocksenate-0.1.0/src/stock_senate/alerts/__init__.py +1 -0
  10. stocksenate-0.1.0/src/stock_senate/alerts/channels/__init__.py +47 -0
  11. stocksenate-0.1.0/src/stock_senate/alerts/channels/console.py +24 -0
  12. stocksenate-0.1.0/src/stock_senate/alerts/channels/webhook.py +91 -0
  13. stocksenate-0.1.0/src/stock_senate/alerts/channels/webui.py +51 -0
  14. stocksenate-0.1.0/src/stock_senate/alerts/engine.py +394 -0
  15. stocksenate-0.1.0/src/stock_senate/alerts/rules.py +378 -0
  16. stocksenate-0.1.0/src/stock_senate/alerts/state.py +215 -0
  17. stocksenate-0.1.0/src/stock_senate/backtest/__init__.py +1 -0
  18. stocksenate-0.1.0/src/stock_senate/backtest/engine.py +773 -0
  19. stocksenate-0.1.0/src/stock_senate/backtest/models.py +243 -0
  20. stocksenate-0.1.0/src/stock_senate/cli.py +710 -0
  21. stocksenate-0.1.0/src/stock_senate/config/__init__.py +1 -0
  22. stocksenate-0.1.0/src/stock_senate/config/edit.py +130 -0
  23. stocksenate-0.1.0/src/stock_senate/config/loader.py +501 -0
  24. stocksenate-0.1.0/src/stock_senate/config/schema.py +690 -0
  25. stocksenate-0.1.0/src/stock_senate/data/__init__.py +6 -0
  26. stocksenate-0.1.0/src/stock_senate/data/codes.py +32 -0
  27. stocksenate-0.1.0/src/stock_senate/data/envelope.py +189 -0
  28. stocksenate-0.1.0/src/stock_senate/data/providers/__init__.py +96 -0
  29. stocksenate-0.1.0/src/stock_senate/data/providers/base.py +227 -0
  30. stocksenate-0.1.0/src/stock_senate/data/providers/composite.py +66 -0
  31. stocksenate-0.1.0/src/stock_senate/data/providers/local_json.py +97 -0
  32. stocksenate-0.1.0/src/stock_senate/data/providers/sql.py +94 -0
  33. stocksenate-0.1.0/src/stock_senate/data/providers/text_doc.py +110 -0
  34. stocksenate-0.1.0/src/stock_senate/data/providers/tickhub.py +255 -0
  35. stocksenate-0.1.0/src/stock_senate/data/router.py +299 -0
  36. stocksenate-0.1.0/src/stock_senate/data/sanitize.py +128 -0
  37. stocksenate-0.1.0/src/stock_senate/graph/__init__.py +5 -0
  38. stocksenate-0.1.0/src/stock_senate/graph/senate_graph.py +396 -0
  39. stocksenate-0.1.0/src/stock_senate/mcp_server/__init__.py +1 -0
  40. stocksenate-0.1.0/src/stock_senate/mcp_server/server.py +307 -0
  41. stocksenate-0.1.0/src/stock_senate/mcp_server/tools.py +349 -0
  42. stocksenate-0.1.0/src/stock_senate/observability/__init__.py +1 -0
  43. stocksenate-0.1.0/src/stock_senate/observability/logging.py +220 -0
  44. stocksenate-0.1.0/src/stock_senate/py.typed +1 -0
  45. stocksenate-0.1.0/src/stock_senate/queue/__init__.py +1 -0
  46. stocksenate-0.1.0/src/stock_senate/queue/locks.py +150 -0
  47. stocksenate-0.1.0/src/stock_senate/queue/manager.py +1091 -0
  48. stocksenate-0.1.0/src/stock_senate/report/__init__.py +1 -0
  49. stocksenate-0.1.0/src/stock_senate/report/diff.py +176 -0
  50. stocksenate-0.1.0/src/stock_senate/report/performance.py +141 -0
  51. stocksenate-0.1.0/src/stock_senate/report/render.py +373 -0
  52. stocksenate-0.1.0/src/stock_senate/report/store.py +209 -0
  53. stocksenate-0.1.0/src/stock_senate/roles/__init__.py +1 -0
  54. stocksenate-0.1.0/src/stock_senate/roles/llm.py +420 -0
  55. stocksenate-0.1.0/src/stock_senate/roles/registry.py +256 -0
  56. stocksenate-0.1.0/src/stock_senate/roles/schemas.py +150 -0
  57. stocksenate-0.1.0/src/stock_senate/roles/tool_gate.py +86 -0
  58. stocksenate-0.1.0/src/stock_senate/screening/__init__.py +1 -0
  59. stocksenate-0.1.0/src/stock_senate/screening/dedup.py +102 -0
  60. stocksenate-0.1.0/src/stock_senate/version.py +1 -0
  61. stocksenate-0.1.0/src/stock_senate/webui/__init__.py +14 -0
  62. stocksenate-0.1.0/src/stock_senate/webui/auth.py +317 -0
  63. stocksenate-0.1.0/src/stock_senate/webui/launch.py +88 -0
  64. stocksenate-0.1.0/src/stock_senate/webui/pages/__init__.py +42 -0
  65. stocksenate-0.1.0/src/stock_senate/webui/pages/alerts.py +216 -0
  66. stocksenate-0.1.0/src/stock_senate/webui/pages/analysis.py +127 -0
  67. stocksenate-0.1.0/src/stock_senate/webui/pages/backtest.py +162 -0
  68. stocksenate-0.1.0/src/stock_senate/webui/pages/common.py +48 -0
  69. stocksenate-0.1.0/src/stock_senate/webui/pages/diff.py +131 -0
  70. stocksenate-0.1.0/src/stock_senate/webui/pages/history.py +161 -0
  71. stocksenate-0.1.0/src/stock_senate/webui/pages/ops.py +97 -0
  72. stocksenate-0.1.0/src/stock_senate/webui/pages/progress.py +131 -0
  73. stocksenate-0.1.0/src/stock_senate/webui/pages/queue.py +301 -0
  74. stocksenate-0.1.0/src/stock_senate/webui/pages/reports.py +164 -0
  75. stocksenate-0.1.0/src/stock_senate/webui/pages/settings.py +201 -0
  76. stocksenate-0.1.0/src/stock_senate/webui/state.py +243 -0
  77. stocksenate-0.1.0/src/stock_senate/webui/templates.py +237 -0
  78. stocksenate-0.1.0/src/stock_senate/workflow/__init__.py +1 -0
  79. stocksenate-0.1.0/src/stock_senate/workflow/budget.py +77 -0
  80. stocksenate-0.1.0/src/stock_senate/workflow/context.py +58 -0
  81. stocksenate-0.1.0/src/stock_senate/workflow/debate.py +84 -0
  82. stocksenate-0.1.0/src/stock_senate/workflow/digest.py +465 -0
  83. stocksenate-0.1.0/src/stock_senate/workflow/hitl.py +98 -0
  84. stocksenate-0.1.0/src/stock_senate/workflow/nodes/__init__.py +32 -0
  85. stocksenate-0.1.0/src/stock_senate/workflow/nodes/analysts.py +91 -0
  86. stocksenate-0.1.0/src/stock_senate/workflow/nodes/base.py +202 -0
  87. stocksenate-0.1.0/src/stock_senate/workflow/nodes/debate_nodes.py +251 -0
  88. stocksenate-0.1.0/src/stock_senate/workflow/nodes/managers.py +139 -0
  89. stocksenate-0.1.0/src/stock_senate/workflow/nodes/quality.py +79 -0
  90. stocksenate-0.1.0/src/stock_senate/workflow/offline.py +498 -0
  91. stocksenate-0.1.0/src/stock_senate/workflow/verify.py +186 -0
  92. stocksenate-0.1.0/src/stocksenate.egg-info/PKG-INFO +402 -0
  93. stocksenate-0.1.0/src/stocksenate.egg-info/SOURCES.txt +114 -0
  94. stocksenate-0.1.0/src/stocksenate.egg-info/dependency_links.txt +1 -0
  95. stocksenate-0.1.0/src/stocksenate.egg-info/entry_points.txt +3 -0
  96. stocksenate-0.1.0/src/stocksenate.egg-info/requires.txt +31 -0
  97. stocksenate-0.1.0/src/stocksenate.egg-info/top_level.txt +1 -0
  98. stocksenate-0.1.0/tests/test_alerts.py +461 -0
  99. stocksenate-0.1.0/tests/test_backtest.py +252 -0
  100. stocksenate-0.1.0/tests/test_cli.py +191 -0
  101. stocksenate-0.1.0/tests/test_cli_exit_codes.py +319 -0
  102. stocksenate-0.1.0/tests/test_code_traversal.py +152 -0
  103. stocksenate-0.1.0/tests/test_config_schema.py +222 -0
  104. stocksenate-0.1.0/tests/test_contracts.py +61 -0
  105. stocksenate-0.1.0/tests/test_digest_quality.py +162 -0
  106. stocksenate-0.1.0/tests/test_dotenv.py +152 -0
  107. stocksenate-0.1.0/tests/test_e2e_cli.py +379 -0
  108. stocksenate-0.1.0/tests/test_external_sanitization.py +102 -0
  109. stocksenate-0.1.0/tests/test_integration_data_layer.py +403 -0
  110. stocksenate-0.1.0/tests/test_mcp.py +242 -0
  111. stocksenate-0.1.0/tests/test_ports_contract.py +92 -0
  112. stocksenate-0.1.0/tests/test_queue.py +263 -0
  113. stocksenate-0.1.0/tests/test_role_contract.py +243 -0
  114. stocksenate-0.1.0/tests/test_screening.py +92 -0
  115. stocksenate-0.1.0/tests/test_webui.py +253 -0
  116. stocksenate-0.1.0/tests/test_webui_parity.py +100 -0
@@ -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 2026 QuotaFuse
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.
@@ -0,0 +1,29 @@
1
+ StockSenate
2
+ Copyright 2026 QuotaFuse
3
+
4
+ This product includes software developed by QuotaFuse.
5
+
6
+ Third-party components and their licenses:
7
+
8
+ - LangGraph / LangChain — MIT License, Copyright LangChain, Inc.
9
+ - Typer — MIT License, Copyright Sebastián Ramírez
10
+ - Rich — MIT License, Copyright Will McGugan
11
+ - Pydantic / pydantic-settings — MIT License, Copyright Samuel Colvin
12
+ - Streamlit — Apache License 2.0, Copyright Streamlit Inc.
13
+ - pandas — BSD 3-Clause License, Copyright pandas Development Team
14
+ - NumPy — BSD 3-Clause License, Copyright NumPy Developers
15
+ - mootdx — MIT License (optional, via `[stockdata]` extra)
16
+ - MCP Python SDK — MIT License, Copyright Anthropic, PBC
17
+ - TickHub-CN / TickHub-US / Newsieve — QuotaFuse data services, used via
18
+ documented APIs only. No data source code is vendored into this repository.
19
+
20
+ This project's research framework is inspired by the open-source
21
+ TradingAgents project. StockSenate is an independent implementation and does
22
+ not include TradingAgents source code; behavioural compatibility is limited to
23
+ the public `propagate` contract described in README.md.
24
+
25
+ TradingAgents-astock is referenced for behavioural comparison only.
26
+
27
+ StockSenate performs research analysis and backtest simulation only. It does
28
+ not place orders, connect to brokerages, or produce executable trading
29
+ instructions.
@@ -0,0 +1,402 @@
1
+ Metadata-Version: 2.4
2
+ Name: stocksenate
3
+ Version: 0.1.0
4
+ Summary: StockSenate: multi-role AI investment research senate (analysis and backtest simulation only)
5
+ Author: QuotaFuse
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/QuotaFuse-ai/StockSenate
8
+ Project-URL: Repository, https://github.com/QuotaFuse-ai/StockSenate
9
+ Project-URL: Issues, https://github.com/QuotaFuse-ai/StockSenate/issues
10
+ Keywords: a-share,multi-agent,investment-research,llm,langgraph,mcp
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Office/Business :: Financial :: Investment
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ License-File: NOTICE
22
+ Requires-Dist: typer>=0.12
23
+ Requires-Dist: rich>=13.7
24
+ Requires-Dist: pydantic>=2.5
25
+ Requires-Dist: pydantic-settings>=2.2
26
+ Requires-Dist: python-dotenv>=1.0
27
+ Requires-Dist: toml>=0.10
28
+ Requires-Dist: openai>=1.40
29
+ Requires-Dist: anthropic>=0.34
30
+ Provides-Extra: stockdata
31
+ Requires-Dist: tickhub-cn>=1.0; extra == "stockdata"
32
+ Provides-Extra: mcp
33
+ Requires-Dist: mcp>=2.0; extra == "mcp"
34
+ Provides-Extra: webui
35
+ Requires-Dist: starlette>=0.37; extra == "webui"
36
+ Requires-Dist: uvicorn>=0.30; extra == "webui"
37
+ Provides-Extra: all
38
+ Requires-Dist: stocksenate[mcp,stockdata,webui]; extra == "all"
39
+ Provides-Extra: dev
40
+ Requires-Dist: stocksenate[mcp,webui]; extra == "dev"
41
+ Requires-Dist: pytest>=8.0; extra == "dev"
42
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
43
+ Requires-Dist: ruff>=0.6; extra == "dev"
44
+ Requires-Dist: mypy>=1.10; extra == "dev"
45
+ Requires-Dist: pip-audit>=2.7; extra == "dev"
46
+ Requires-Dist: build>=1.2; extra == "dev"
47
+ Requires-Dist: twine>=5.0; extra == "dev"
48
+ Dynamic: license-file
49
+
50
+ <h1 align="center">StockSenate</h1>
51
+
52
+ <p align="center">
53
+ <b>多角色投研合议系统</b><br>
54
+ 7 角色研报 · 多空辩论 · 三档风控 · 投决终审 · 回测推演
55
+ </p>
56
+
57
+ <p align="center">
58
+ 研究框架,不是投资产品 · 不接实盘 · 不输出可执行价位
59
+ </p>
60
+
61
+ ---
62
+
63
+ StockSenate 是自研的 A 股多角色投研合议系统:
64
+ 7 位分析师并行产出研报,经多空辩论、研究经理汇总、交易员提案、三档风控审查,由组合经理终审;
65
+ 数据采集不在议事层实现,统一交给 `TickHub-CN` / `TickHub-US` / `Newsieve` 提供,
66
+ StockSenate 自身只负责「多智能体合议 + 回测推演」。
67
+
68
+ - **完整合议链路**:7 分析师 → 多空辩论 → 研究经理 → 交易员 → 三档风险辩论 → 投资经理终审 → 质量门控,节点与输出契约稳定。
69
+ - **数据层独立**:议事层不直连东财/巨潮/通达信;`DataAccessLayer` 统一消费 `TickHub-CN`(A 股)、`TickHub-US`(美/港股)、`Newsieve`(资讯),也可离线读取本地 JSON、文本与 SQL。
70
+ - **生产级增强**:Pydantic 输出强约束、单节点局部重试、辩论收敛、增量分析、安全护栏、HITL 审批、LLM-as-a-Judge、全链路追踪、任务熔断、告警引擎、批量队列、独立 WebUI、MCP Server。
71
+ - **一套环境装全部模型**:MiniMax / DeepSeek / Qwen / GLM / OpenAI / Anthropic / Google / xAI / OpenRouter / Ollama / OpenAI 兼容网关。
72
+
73
+ > **定位边界**:本项目面向研究与教学,不构成投资建议,不提供荐股服务。
74
+ > 框架内没有建仓价、止损位、目标价、仓位比例这类输出——不是默认关闭,是设计上不做。
75
+ > 所有 AI 生成内容均可能有误,投资决策请咨询持牌专业机构。
76
+
77
+ ---
78
+
79
+ ## 能力一览
80
+
81
+ | 维度 | StockSenate |
82
+ |------|-------------|
83
+ | 定位 | 多角色投研合议系统(研究 + 回测推演) |
84
+ | 数据来源 | `DataAccessLayer` → `TickHub-CN` / `TickHub-US` / `Newsieve`,可插拔本地 JSON / 文本 / SQL |
85
+ | 数据采集 | 由数据底座负责;议事层不重复实现采集、缓存、代理池、降级 |
86
+ | 分析师 | 7 个(市场/舆情/新闻/基本面 + 政策/游资/解禁),角色提示词内置,输出 Schema 强约束 |
87
+ | 辩论与决策 | 多空辩论 → 研究经理 → 交易员 → 三档风控 → 投决,含收敛打分、可配置拓扑、interrupt 人工审批 |
88
+ | 模型配置 | 快/深两档 + `role_llms` 细粒度,角色键位稳定 |
89
+ | 断点恢复 | SQLite/Postgres checkpoint 与增量分析 |
90
+ | 报告 | `summary.json` + `complete_report.md` + Markdown/PDF,含结构化版本快照、字段级 Diff、多格式输出 |
91
+ | 决策统计 | `performance` 事后归因保持独立口径;回测引擎是单独能力,两者分开验收 |
92
+ | 交互 | CLI + 独立 WebUI(独立进程/端口/鉴权)+ MCP Server(stdio/http) |
93
+ | 工程化 | GitHub Actions + `uv.lock` + pip-audit + 全提供商同环境 import smoke test |
94
+ | 包名 / 命令 | `stocksenate` / `ssenate`(`tradingagents` 为兼容别名) |
95
+
96
+ ---
97
+
98
+ ## 架构
99
+
100
+ ```text
101
+ ┌───────────────────────────┐ ┌───────────────────────────┐ ┌───────────────────────────┐
102
+ │ StockSenate WebUI │ │ StockSenate MCP Server │ │ 数据底座控制台(外部) │
103
+ │ 独立进程 · 127.0.0.1:8788 │ │ stdio / http :8765 │ │ TickHub Admin :8787 │
104
+ └─────────────┬─────────────┘ └─────────────┬─────────────┘ └─────────────┬─────────────┘
105
+ │ │ │
106
+ └───────────────┬───────────────┘ │
107
+ ▼ │
108
+ ┌──────────────────────────┐ │
109
+ │ SenateGraph 工作流 │ 只读展示数据状态 + 跳转 │
110
+ │ 7 分析师 → 多空辩论 │ │
111
+ │ → 研究经理 → 交易员 │ │
112
+ │ → 三档风控 → 投决终审 │ │
113
+ └────────────┬─────────────┘ │
114
+ ▼ │
115
+ ┌──────────────────────────┐ │
116
+ │ DataAccessLayer │ │
117
+ │ DataEnvelope + 路由 + │ │
118
+ │ 溯源 + 降级标记 │ │
119
+ └────────────┬─────────────┘ │
120
+ ▼ │
121
+ ┌─────────────────────┴─────────────────────┐ │
122
+ ▼ ▼ ▼ │
123
+ TickHub-CN (A 股) TickHub-US (美/港股) Newsieve (资讯) ◄──────────────┘
124
+ MCP stdio/http MCP stdio/http MCP stdio/http
125
+ 或 local import 或 local import 或 local import
126
+ │ │ │
127
+ └──────────┬──────────┴──────────┬──────────┘
128
+ ▼ ▼
129
+ 本地 JSON 归档 文本 / SQL(只读)
130
+ ```
131
+
132
+ **职责边界**
133
+
134
+ | 能力 | StockSenate | 数据底座(TickHub / Newsieve) |
135
+ |------|-------------|-------------------------------|
136
+ | 多角色分析、辩论、终审 | ✅ | ❌ |
137
+ | 回测、告警、报告、WebUI | ✅ | ❌ |
138
+ | 数据采集、缓存、代理池、限流 | ❌ 不重复实现 | ✅ |
139
+ | 字段映射、风险事件结构化 | 消费 | ✅ 生产 |
140
+ | 数据源健康与降级 | 消费状态并标注置信度 | ✅ 执行 |
141
+ | LLM 调用与多模型 | ✅ | ❌ |
142
+
143
+ ---
144
+
145
+ ## 角色体系
146
+
147
+ 默认 7 个分析师全部内置,`role_llms` 键位固定如下:
148
+
149
+ | 配置键 | 展示名 | 职责 | 阶段 |
150
+ |---|---|---|---|
151
+ | `fundamentals`(别名 `basic`) | 基本面分析师 | 财报三表、盈利能力、估值 | analyst |
152
+ | `market`(别名 `technical`) | 技术面分析师 | K 线形态、技术指标、量价 | analyst |
153
+ | `social`(别名 `sentiment`) | 情绪分析师 | 讨论热度、散户情绪 | analyst |
154
+ | `news` | 新闻分析师 | 行业新闻、公告、宏观事件 | analyst |
155
+ | `policy` | 政策分析师 | 监管政策、产业政策、窗口指导 | analyst |
156
+ | `hot_money` | 游资龙虎榜分析师 | 龙虎榜、大单流向、主力资金 | analyst |
157
+ | `lockup`(别名 `unlock`) | 解禁监控分析师 | 限售解禁、减持、股权质押 | analyst |
158
+ | `bull` / `bear` | 多空辩手 | 多空辩论 | debate |
159
+ | `research_manager` | 研究经理 | 综合研判、投资计划 | manager |
160
+ | `trader` | 交易员 | A 股约束下的交易方案(方向/评级/理由) | trader |
161
+ | `risk_aggressive` / `risk_neutral` / `risk_conservative` | 三档风控 | 风险辩论 | risk |
162
+ | `portfolio_manager` | 投资经理 | 终审评级 + 理由 | final |
163
+ | `quality_gate` | 质量门控 | 输出质量校验 | gate |
164
+
165
+ 自定义角色通过 `config/agent_roles.toml` 声明,上限默认 12 个(7 内置 + 5 自定义)。
166
+ 新增角色必须定义:名称与提示词、工具白名单、Pydantic 输出 Schema、模型层级、阶段、是否参与辩论及权重。
167
+ 自定义角色失败可跳过主流程,报告标注 `partial`。
168
+
169
+ ---
170
+
171
+ ## 安装
172
+
173
+ 需要 **Python ≥ 3.11**(与 TickHub-CN 保持一致)。
174
+
175
+ ```bash
176
+ pip install stocksenate # 核心
177
+ pip install "stocksenate[all]" # 全功能
178
+ pip install -e ".[dev]" # 开发
179
+ ```
180
+
181
+ 可选 extras:`stockdata`(TickHub 本地直连)、`mcp`(MCP Server)、`webui`(Starlette + uvicorn 控制台,见 DEC-008)、`all`。回测为纯 Python 实现,无独立 extra。
182
+
183
+ ```bash
184
+ cp .env.example .env # 按文件内【必填】备注填写,模板不含任何真实密钥
185
+ ssenate config validate # 启动时自动读取当前目录的 .env;已导出的变量优先
186
+ ```
187
+
188
+ ---
189
+
190
+ ## 快速开始
191
+
192
+ ### 命令行
193
+
194
+ ```bash
195
+ # 单标的分析
196
+ ssenate analyze 600000 --date 2024-12-31
197
+
198
+ # 动态启停角色 / 调权重
199
+ ssenate analyze 600000 --date 2024-12-31 --disable custom_macro
200
+ ssenate analyze 600000 --date 2024-12-31 --enable custom_macro --weight 0.6
201
+
202
+ # 角色管理
203
+ ssenate role list
204
+ ssenate role show fundamentals
205
+ ssenate role validate
206
+ ssenate role enable custom_macro
207
+ ssenate role disable custom_macro
208
+
209
+ # 回测(基于已保存决策记录)
210
+ ssenate backtest run --code 600000 --start 2024-01-01 --end 2024-12-31
211
+
212
+ # 告警
213
+ ssenate alert list
214
+ ssenate alert rules validate
215
+
216
+ # 报告版本 Diff
217
+ ssenate report diff --code 600000 --from 2024-11-30 --to 2024-12-31
218
+
219
+ # 批量队列
220
+ ssenate queue status
221
+ ssenate queue submit --file tasks.csv
222
+
223
+ # 配置
224
+ ssenate config validate
225
+ ssenate config migrate
226
+
227
+ # MCP Server
228
+ ssenate mcp stdio
229
+ ssenate mcp http --port 8765
230
+
231
+ # 独立 WebUI
232
+ ssenate webui --host 127.0.0.1 --port 8788
233
+ ```
234
+
235
+ 完整命令、参数、退出码与 MCP 配置见 [docs/specs/cli-reference.md](docs/specs/cli-reference.md)。
236
+
237
+ ### Python API
238
+
239
+ ```python
240
+ from stock_senate import SenateGraph
241
+
242
+ graph = SenateGraph()
243
+ final_state, decision = graph.propagate(code="600000", date="2024-12-31")
244
+ print(decision["rating"], decision["reason"])
245
+ ```
246
+
247
+ - `propagate(code, date)` 返回 `(final_state, decision)` 二元组,签名稳定。
248
+ - `TradingAgentsGraph` 保留为 `SenateGraph` 的别名。
249
+ - `summary.json`、`complete_report.md` 是衍生输出,不替代返回值。
250
+
251
+ ### 旧命令兼容
252
+
253
+ ```bash
254
+ tradingagents analyze 600000 # 可用,启动时打印弃用警告并提示迁移到 ssenate
255
+ ```
256
+
257
+ ---
258
+
259
+ ## 配置
260
+
261
+ 所有配置集中在 `config/`,运行时合并用户目录 `~/.stock_senate/`:
262
+
263
+ | 文件 | 作用 |
264
+ |------|------|
265
+ | `config/agent_roles.toml` | 角色、提示词、权重、工具白名单、输出 Schema、模型层级 |
266
+ | `config/workflow.toml` | 拓扑、并行组、辩论轮次、收敛阈值、终止条件、interrupt 节点 |
267
+ | `config/output_template.toml` | 报告模块开关与多格式输出 |
268
+ | `config/data_source.toml` | 数据模式、provider 优先级、实时开关、超时与降级 |
269
+ | `config/llm_config.toml` | 提供商、模型、`role_llms`、超时、重试、预算 |
270
+ | `config/alert_rules.toml` | 告警级别、条件、动作、去重、Webhook |
271
+ | `config/budget.toml` | 任务熔断(最大调用数、Token、超时) |
272
+
273
+ - 旧目录 `~/.tradingagents/` 在首次启动时**只读扫描并迁移**到 `~/.stock_senate/`,旧目录不删除。
274
+ - 环境变量前缀 `STOCKSENATE_*`;同时兼容读取旧前缀 `TRADINGAGENTS_*`,新前缀优先。
275
+ - 所有配置文件提供 JSON Schema 校验与迁移脚本(`ssenate config validate` / `ssenate config migrate`)。
276
+
277
+ ---
278
+
279
+ ## 数据接入
280
+
281
+ `DataAccessLayer` 输出统一 `DataEnvelope`:
282
+
283
+ ```python
284
+ class DataEnvelope(BaseModel):
285
+ domain: str # kline / financial / announcement / research / risk_event ...
286
+ code: str
287
+ data_as_of: date
288
+ payload: dict
289
+ source: str # tickhub_cn / tickhub_us / json / text_doc / sql
290
+ source_detail: str
291
+ fetched_at: datetime
292
+ freshness: str # realtime / cached / archive
293
+ confidence: str # high / medium / low
294
+ data_source_status: str # ok / degraded / missing
295
+ ```
296
+
297
+ 四种模式(`config/data_source.toml`):
298
+
299
+ | 模式 | 语义 |
300
+ |------|------|
301
+ | `stockdata` | 只走数据底座(TickHub / Newsieve) |
302
+ | `local` | 只读本地数据,支持断网回放 |
303
+ | `priority` | 按 `[data_source.priority]` 逐级 fallback |
304
+ | `hybrid` | 历史/归档优先本地,实时/缺失/刷新走数据底座 |
305
+
306
+ 硬约束:
307
+
308
+ - 数值类数据(财务、K 线、资金)**只允许**来自数据底座或结构化数据库,禁止从 TXT/PDF/Word 抽取。
309
+ - 文本类数据只用于公告、研报、政策、新闻分析。
310
+ - 实时采集默认关闭;开启后必须带超时、降级与防重复采集锁。
311
+ - 本地源不可用**不得静默返回空**,必须标记 `data_source_status=missing|degraded`。
312
+
313
+ ---
314
+
315
+ ## WebUI 与 MCP
316
+
317
+ ### 独立 WebUI
318
+
319
+ ```bash
320
+ ssenate webui --host 127.0.0.1 --port 8788
321
+ ```
322
+
323
+ 独立进程、独立端口、独立鉴权;默认只监听本机,未配置鉴权令牌时拒绝写操作。
324
+ 页面:分析工作台、辩论过程、最终报告、历史记录、报告 Diff、回测中心、告警面板、角色管理、工作流拓扑、批量队列、配置校验、数据状态只读卡。
325
+
326
+ 运维监控不在本界面重复建设,只做只读展示并跳转数据底座控制台(默认 `:8787`)。
327
+
328
+ ### MCP Server
329
+
330
+ ```bash
331
+ ssenate mcp stdio # 供 Cursor / Claude Desktop 等客户端
332
+ ssenate mcp http --port 8765
333
+ ```
334
+
335
+ - stdio 模式 stdout **只输出 MCP 协议报文**,所有日志走 stderr。
336
+ - http 模式默认 `127.0.0.1`,对外必须鉴权。
337
+ - 与数据底座的 MCP 分开命名、分开鉴权、分开日志,通过 `trace_id` 串联。
338
+ - 暴露工具:分析任务、回测、告警查询、报告查询、配置查询。
339
+
340
+ ---
341
+
342
+ ## 回测与 performance 的区别
343
+
344
+ | | `ssenate backtest` | `ssenate performance` |
345
+ |---|---|---|
346
+ | 性质 | 策略推演(独立能力) | 决策事后归因 |
347
+ | 输入 | 已保存决策记录 + 历史行情 | 已落盘决策记录 |
348
+ | 能力 | 滑点、手续费、仓位、重叠窗口、收益曲线、方向准确率、alpha 分组、Buy→Sell alpha 衰减 | 方向正确率、评级分组、评级区分度 |
349
+ | 时点 | `data_as_of` 历史时点推演,防未来函数 | 固定持有期回看 |
350
+ | 验收 | 固定数据集可复现、无未来函数、无样本泄漏 | 统计口径固定、可复核 |
351
+
352
+ **不要把 performance 当回测,也不要把回测当策略业绩。**
353
+
354
+ ---
355
+
356
+ ## 兼容与迁移
357
+
358
+ | 项 | 新值 | 兼容策略 |
359
+ |---|---|---|
360
+ | PyPI 包 | `stocksenate` | 仅本包;不发布 quotafuse 前缀的包 |
361
+ | Python 包 | `stock_senate` | 不提供 `qf_council` shim(从未发布) |
362
+ | CLI | `ssenate` | 注册旧命令 `tradingagents`,打印弃用警告 |
363
+ | Python API | `SenateGraph` | `TradingAgentsGraph` 别名保留,`propagate` 签名不变 |
364
+ | 配置目录 | `~/.stock_senate/` | 首次启动从 `~/.tradingagents/` 只读迁移 |
365
+ | 环境变量 | `STOCKSENATE_*` | 兼容读取 `TRADINGAGENTS_*`,新前缀优先 |
366
+ | MCP Server 名 | `stock-senate` | 与 `tickhub-cn` 等底座 MCP 分开命名与鉴权 |
367
+ | Docker 服务 | `ssenate` / `stocksenate-webui` | 与 `tickhub` / `tickhub-admin` 分离 |
368
+
369
+ ---
370
+
371
+ ## 文档
372
+
373
+ | 文档 | 内容 |
374
+ |---|---|
375
+ | [docs/specs/PRD.md](docs/specs/PRD.md) | 产品需求:功能清单、用户故事、验收标准、里程碑 |
376
+ | [docs/specs/requirements-traceability.md](docs/specs/requirements-traceability.md) | 文档章节 → 模块 / CLI → 验收 全量追溯矩阵 |
377
+ | [docs/specs/priority.md](docs/specs/priority.md) | P0 / P1 / P2 优先级与排期 |
378
+ | [docs/specs/cli-reference.md](docs/specs/cli-reference.md) | 全部 CLI / Python API / MCP 命令与退出码 |
379
+ | [docs/decisions/](docs/decisions/) | 命名、数据层、端口等架构决策(只增不改) |
380
+ | `councli.docx` / `councli文档.docx` | 需求原始文档(v1.1 / v1.2) |
381
+
382
+ ---
383
+
384
+ ## 开发
385
+
386
+ ```bash
387
+ pip install -e ".[dev]"
388
+ pytest -q
389
+ ruff check .
390
+ mypy src
391
+ python -m build
392
+ ```
393
+
394
+ CI 覆盖:`pytest` + `ruff` + `mypy` + `pip-audit` + 全提供商同环境 import smoke test + 打包检查。
395
+ 依赖锁定使用 `uv.lock`;发布包只声明最小依赖范围。
396
+
397
+ ## License
398
+
399
+ Apache License 2.0。本项目为独立实现,研究框架的语境与术语受
400
+ [TradingAgents 论文](https://arxiv.org/abs/2412.20138)启发;
401
+ `TradingAgentsGraph` 兼容别名仅为接口便利,不包含第三方项目源码。
402
+ 归属与第三方许可证声明见 `NOTICE`。