|
1 | 1 | # QuantPlatformKit |
2 | 2 |
|
3 | | -Shared broker adapters, domain models, execution ports, and notification utilities for QuantStrategyLab strategies. |
| 3 | +Shared platform contracts, broker adapters, strategy-plugin helpers, and notification primitives for QuantStrategyLab repositories. |
4 | 4 |
|
5 | | -[English](#english) | [中文](#中文) | [中文详版](./README.zh-CN.md) |
| 5 | +[中文](./README.zh-CN.md) |
6 | 6 |
|
7 | | ---- |
| 7 | +## What This Repository Is |
8 | 8 |
|
9 | | -<a id="english"></a> |
10 | | -## English |
| 9 | +`QuantPlatformKit` is the public shared platform layer. It keeps cross-repository interfaces stable so strategy repositories and broker platform repositories can evolve without copying runtime glue. |
11 | 10 |
|
12 | | -## Scope |
| 11 | +It contains: |
13 | 12 |
|
14 | | -This repository is the shared platform layer for QuantStrategyLab strategy services. |
| 13 | +- common domain models and runtime target helpers |
| 14 | +- narrow ports for market data, portfolio snapshots, order execution, notifications, and state |
| 15 | +- reusable broker adapter utilities |
| 16 | +- strategy loading, strategy-plugin, and alert-message contracts |
| 17 | +- synthetic-data tests for public behavior |
15 | 18 |
|
16 | | -It is intended to contain: |
| 19 | +It does not contain private runtime wiring or generated strategy outputs. |
17 | 20 |
|
18 | | -- common domain models |
19 | | -- narrow ports for market data, portfolio snapshots, execution, notifications, and state |
20 | | -- broker-specific adapters |
21 | | -- small reusable notification utilities |
| 21 | +## Repository Workflow |
22 | 22 |
|
23 | | -It is not intended to contain: |
| 23 | +QuantStrategyLab repositories are split by responsibility: |
24 | 24 |
|
25 | | -- strategy rules |
26 | | -- target allocation logic |
27 | | -- Cloud Run entrypoints |
28 | | -- scheduler or workflow orchestration specific to one strategy |
| 25 | +- Strategy repositories own strategy metadata, input requirements, and `manifest + evaluate(ctx)` entrypoints. |
| 26 | +- Platform repositories own broker sessions, runtime config loading, runtime entrypoints, decision mapping, and order submission. |
| 27 | +- Snapshot or data pipeline repositories own generated artifacts and their publication process. |
| 28 | +- `QuantPlatformKit` owns the shared contracts and helper APIs used by those repositories. |
29 | 29 |
|
30 | | -## Strategy contract boundary |
31 | | - |
32 | | -The current mainline split is: |
33 | | - |
34 | | -- platform repositories assemble `StrategyContext` |
35 | | -- platform repositories load a strategy entrypoint through `load_strategy_entrypoint(...)` |
36 | | -- strategy repositories return a unified `StrategyDecision` |
37 | | -- platform-local decision mappers turn that decision into broker orders, notifications, and runtime state updates |
38 | | - |
39 | | -Strategy repositories should expose `manifest + evaluate(ctx)` and keep any migration-window runtime metadata behind `StrategyRuntimeAdapter`. Broker-specific order sequencing and UI layout should stay out of strategy outputs. |
40 | | -Platform repositories should share common execution outcome and notification envelope helpers from this package so broker-specific differences stay limited to adapters, order payloads, and transport wiring. |
41 | | - |
42 | | -Migration details and follow-up guidance live in [`docs/strategy_contract_migration.md`](./docs/strategy_contract_migration.md). |
43 | | - |
44 | | -For the stricter end-state rules for new US equity strategies, see: |
45 | | - |
46 | | -- [`docs/us_equity_strategy_onboarding.md`](./docs/us_equity_strategy_onboarding.md) |
47 | | -- [`docs/us_equity_strategy_onboarding.zh-CN.md`](./docs/us_equity_strategy_onboarding.zh-CN.md) |
48 | | -- [`docs/us_equity_cross_platform_strategy_spec.md`](./docs/us_equity_cross_platform_strategy_spec.md) |
49 | | -- [`docs/us_equity_cross_platform_strategy_spec.zh-CN.md`](./docs/us_equity_cross_platform_strategy_spec.zh-CN.md) |
50 | | -- [`docs/us_equity_execution_translation_spec.md`](./docs/us_equity_execution_translation_spec.md) |
51 | | -- [`docs/us_equity_execution_translation_spec.zh-CN.md`](./docs/us_equity_execution_translation_spec.zh-CN.md) |
52 | | -- [`docs/us_equity_release_cutover_plan.md`](./docs/us_equity_release_cutover_plan.md) |
53 | | -- [`docs/us_equity_release_cutover_plan.zh-CN.md`](./docs/us_equity_release_cutover_plan.zh-CN.md) |
54 | | -- [`docs/us_equity_live_switch_runbook.md`](./docs/us_equity_live_switch_runbook.md) |
55 | | -- [`docs/us_equity_live_switch_runbook.zh-CN.md`](./docs/us_equity_live_switch_runbook.zh-CN.md) |
56 | | -- [`docs/platform_notification_outcomes.md`](./docs/platform_notification_outcomes.md) |
57 | | -- [`docs/platform_notification_outcomes.zh-CN.md`](./docs/platform_notification_outcomes.zh-CN.md) |
58 | | -- [`docs/strategy_plugin_runtime_contract.md`](./docs/strategy_plugin_runtime_contract.md) |
59 | | - |
60 | | -## Package layout |
61 | | - |
62 | | -```text |
63 | | -src/quant_platform_kit/ |
64 | | - common/ |
65 | | - models.py |
66 | | - ports.py |
67 | | - strategies.py |
68 | | - strategy_plugins.py |
69 | | - ibkr/ |
70 | | - connection.py |
71 | | - market_data.py |
72 | | - portfolio.py |
73 | | - execution.py |
74 | | - binance/ |
75 | | - client.py |
76 | | - account.py |
77 | | - market_data.py |
78 | | - execution.py |
79 | | - schwab/ |
80 | | - auth.py |
81 | | - market_data.py |
82 | | - portfolio.py |
83 | | - execution.py |
84 | | - longbridge/ |
85 | | - auth.py |
86 | | - market_data.py |
87 | | - portfolio.py |
88 | | - execution.py |
89 | | - notifications/ |
90 | | - telegram.py |
91 | | -tests/ |
92 | | -``` |
93 | | - |
94 | | -## Development |
95 | | - |
96 | | -Run tests with: |
97 | | - |
98 | | -```bash |
99 | | -PYTHONPATH=src python3 -m unittest discover -s tests |
100 | | -``` |
101 | | - |
102 | | -## Release and deployment model |
103 | | - |
104 | | -`QuantPlatformKit` is a shared dependency, not a runtime service. Strategy repos should pin a fixed Git tag such as: |
| 30 | +The normal flow is: |
105 | 31 |
|
106 | 32 | ```text |
107 | | -quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@v0.7.1 |
| 33 | +Platform repository |
| 34 | + builds StrategyContext from broker/runtime inputs |
| 35 | + loads a strategy entrypoint from a strategy repository |
| 36 | + receives a StrategyDecision |
| 37 | + maps that decision into broker-specific execution and notifications |
| 38 | +
|
| 39 | +QuantPlatformKit |
| 40 | + provides shared contracts, loaders, adapters, and plugin alert helpers |
108 | 41 | ``` |
109 | 42 |
|
110 | | -Cloud Run and self-hosted runner deployments should continue to deploy the strategy repositories only. See [docs/deployment_model.md](./docs/deployment_model.md) for: |
111 | | - |
112 | | -- service naming suggestions |
113 | | -- fixed-tag dependency rules |
114 | | -- Google Cloud trigger rebind steps after repo rename |
115 | | -- HK / SG multi-service guidance for `LongBridgePlatform` |
116 | | -- US equity cross-platform strategy contract rules |
117 | | - |
118 | | ---- |
119 | | - |
120 | | -<a id="中文"></a> |
121 | | -## 中文 |
122 | | - |
123 | | -`QuantPlatformKit` 是 `QuantStrategyLab` 的共享平台层仓库。 |
124 | | - |
125 | | -它负责放这些内容: |
126 | | - |
127 | | -- 统一领域模型 |
128 | | -- 市场数据、持仓、执行、通知相关的公共接口 |
129 | | -- IBKR / Schwab / LongBridge / Binance 的平台适配层 |
130 | | -- 少量可复用的通知和运行时工具 |
131 | | - |
132 | | -它不负责放这些内容: |
| 43 | +Strategy code should not branch on a broker platform, and platform code should not duplicate strategy rules. |
133 | 44 |
|
134 | | -- 具体策略规则 |
135 | | -- 目标仓位和调仓计算 |
136 | | -- Cloud Run 或 VPS 入口 |
137 | | -- 某一个平台仓库自己的调度和部署编排 |
| 45 | +## Strategy Plugins |
138 | 46 |
|
139 | | -### 范围 |
| 47 | +Strategy plugins are sidecar artifacts that platform repositories may read when a strategy profile opts in. This repository defines the public plugin contract, compatibility checks, alert-message building, and duplicate-suppression helpers. |
140 | 48 |
|
141 | | -这个仓库是各平台仓库共享的公共依赖。 |
| 49 | +Generated plugin artifacts and platform-specific notification routing stay with the producing pipeline or consuming platform repository. Tests in this repository use synthetic price history and synthetic payloads only. |
142 | 50 |
|
143 | | -### 策略契约边界 |
144 | | - |
145 | | -当前主线边界已经固定为: |
146 | | - |
147 | | -- 平台仓库负责组装 `StrategyContext` |
148 | | -- 平台仓库通过 `load_strategy_entrypoint(...)` 加载策略入口 |
149 | | -- 策略仓库只返回统一的 `StrategyDecision` |
150 | | -- 平台自己的 decision mapper 再把决策映射成券商订单、通知和运行时状态更新 |
151 | | - |
152 | | -策略仓库应该暴露 `manifest + evaluate(ctx)`;如果迁移窗口里还需要少量运行时元数据,就放在 `StrategyRuntimeAdapter` 里,不要把券商专属下单顺序或展示布局塞回策略输出。 |
153 | | - |
154 | | -迁移说明和后续约束见 [`docs/strategy_contract_migration.md`](./docs/strategy_contract_migration.md)。 |
155 | | - |
156 | | -以后新增美股策略要遵守的更严格跨平台规范见: |
157 | | - |
158 | | -- [`docs/us_equity_strategy_onboarding.md`](./docs/us_equity_strategy_onboarding.md) |
159 | | -- [`docs/us_equity_strategy_onboarding.zh-CN.md`](./docs/us_equity_strategy_onboarding.zh-CN.md) |
160 | | -- [`docs/us_equity_cross_platform_strategy_spec.md`](./docs/us_equity_cross_platform_strategy_spec.md) |
161 | | -- [`docs/us_equity_cross_platform_strategy_spec.zh-CN.md`](./docs/us_equity_cross_platform_strategy_spec.zh-CN.md) |
162 | | -- [`docs/us_equity_live_switch_runbook.md`](./docs/us_equity_live_switch_runbook.md) |
163 | | -- [`docs/us_equity_live_switch_runbook.zh-CN.md`](./docs/us_equity_live_switch_runbook.zh-CN.md) |
164 | | -- [`docs/strategy_plugin_runtime_contract.md`](./docs/strategy_plugin_runtime_contract.md) |
165 | | - |
166 | | -### 目录结构 |
| 51 | +## Package Layout |
167 | 52 |
|
168 | 53 | ```text |
169 | 54 | src/quant_platform_kit/ |
170 | 55 | common/ |
171 | | - models.py |
172 | | - ports.py |
173 | | - strategies.py |
174 | | - strategy_plugins.py |
175 | 56 | ibkr/ |
176 | | - connection.py |
177 | | - market_data.py |
178 | | - portfolio.py |
179 | | - execution.py |
180 | 57 | binance/ |
181 | | - client.py |
182 | | - account.py |
183 | | - market_data.py |
184 | | - execution.py |
185 | 58 | schwab/ |
186 | | - auth.py |
187 | | - market_data.py |
188 | | - portfolio.py |
189 | | - execution.py |
190 | 59 | longbridge/ |
191 | | - auth.py |
192 | | - market_data.py |
193 | | - portfolio.py |
194 | | - execution.py |
195 | 60 | notifications/ |
196 | | - telegram.py |
197 | 61 | tests/ |
198 | 62 | ``` |
199 | 63 |
|
200 | | -### 开发 |
| 64 | +## Development |
201 | 65 |
|
202 | | -运行测试: |
| 66 | +Run the public test suite: |
203 | 67 |
|
204 | 68 | ```bash |
205 | | -PYTHONPATH=src python3 -m unittest discover -s tests |
| 69 | +PYTHONPATH=src pytest |
206 | 70 | ``` |
207 | 71 |
|
208 | | -### 发布和部署 |
209 | | - |
210 | | -`QuantPlatformKit` 只作为共享依赖,不单独部署。策略仓库应该固定依赖某个 Git tag,例如: |
| 72 | +Run linting: |
211 | 73 |
|
212 | | -```text |
213 | | -quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@v0.7.1 |
| 74 | +```bash |
| 75 | +PYTHONPATH=src ruff check . |
214 | 76 | ``` |
215 | 77 |
|
216 | | -部署说明见: |
| 78 | +## License |
217 | 79 |
|
218 | | -- [英文部署说明](./docs/deployment_model.md) |
219 | | -- [中文部署说明](./docs/deployment_model.zh-CN.md) |
220 | | -- [美股跨平台策略规范(英文)](./docs/us_equity_cross_platform_strategy_spec.md) |
221 | | -- [美股跨平台策略规范(中文)](./docs/us_equity_cross_platform_strategy_spec.zh-CN.md) |
| 80 | +MIT License. See [LICENSE](./LICENSE). |
0 commit comments