11from __future__ import annotations
22
3- from dataclasses import dataclass
4-
53from quant_platform_kit .common .strategies import (
4+ StrategyCatalog ,
65 StrategyComponentDefinition ,
76 StrategyDefinition ,
7+ StrategyMetadata ,
88 US_EQUITY_DOMAIN ,
9+ build_strategy_catalog ,
10+ build_strategy_index_rows ,
11+ get_catalog_compatible_platforms ,
12+ get_catalog_strategy_definition ,
13+ get_catalog_strategy_metadata ,
14+ normalize_profile_name as qpk_normalize_profile_name ,
15+ resolve_catalog_profile ,
916)
1017
1118GLOBAL_ETF_ROTATION_PROFILE = "global_etf_rotation"
2330 CASH_BUFFER_BRANCH_DEFAULT_PROFILE : frozenset ({"ibkr" }),
2431}
2532
26-
27- @dataclass (frozen = True )
28- class StrategyMetadata :
29- canonical_profile : str
30- display_name : str
31- description : str
32- aliases : tuple [str , ...] = ()
33- cadence : str | None = None
34- asset_scope : str | None = None
35- benchmark : str | None = None
36- role : str | None = None
37- status : str | None = None
38-
39-
4033# `supported_platforms` 仍保留为兼容镜像,避免一次性改动所有平台 runtime。
4134# 平台真正的启用状态由各自 runtime 仓库维护;UES 这里只表达策略层兼容性。
4235def _build_strategy_definition (
@@ -151,68 +144,45 @@ def _build_strategy_definition(
151144 for alias in metadata .aliases
152145}
153146
147+ STRATEGY_CATALOG : StrategyCatalog = build_strategy_catalog (
148+ strategy_definitions = STRATEGY_DEFINITIONS ,
149+ metadata = STRATEGY_METADATA ,
150+ compatible_platforms = STRATEGY_PLATFORM_COMPATIBILITY ,
151+ profile_aliases = PROFILE_ALIASES ,
152+ )
153+
154154
155155def normalize_profile_name (profile : str | None ) -> str :
156- return str (profile or "" ). strip (). lower ( )
156+ return qpk_normalize_profile_name (profile )
157157
158158
159159def resolve_canonical_profile (profile : str | None ) -> str :
160- normalized = normalize_profile_name (profile )
161- return PROFILE_ALIASES .get (normalized , normalized )
160+ return resolve_catalog_profile (profile , strategy_catalog = STRATEGY_CATALOG )
162161
163162
164163def get_strategy_definitions () -> dict [str , StrategyDefinition ]:
165164 return dict (STRATEGY_DEFINITIONS )
166165
167166
167+ def get_strategy_catalog () -> StrategyCatalog :
168+ return STRATEGY_CATALOG
169+
170+
168171def get_strategy_platform_compatibility_map () -> dict [str , frozenset [str ]]:
169172 return dict (STRATEGY_PLATFORM_COMPATIBILITY )
170173
171174
172175def get_compatible_platforms (profile : str ) -> frozenset [str ]:
173- canonical = resolve_canonical_profile (profile )
174- if canonical not in STRATEGY_PLATFORM_COMPATIBILITY :
175- supported = ", " .join (sorted (STRATEGY_PLATFORM_COMPATIBILITY )) or "<none>"
176- aliases = ", " .join (sorted (PROFILE_ALIASES )) or "<none>"
177- raise ValueError (
178- f"Unknown us_equity strategy profile={ profile !r} ; supported canonical values: { supported } ; aliases: { aliases } "
179- )
180- return STRATEGY_PLATFORM_COMPATIBILITY [canonical ]
176+ return get_catalog_compatible_platforms (STRATEGY_CATALOG , profile )
181177
182178
183179def get_strategy_definition (profile : str ) -> StrategyDefinition :
184- canonical = resolve_canonical_profile (profile )
185- if canonical not in STRATEGY_DEFINITIONS :
186- supported = ", " .join (sorted (STRATEGY_DEFINITIONS )) or "<none>"
187- aliases = ", " .join (sorted (PROFILE_ALIASES )) or "<none>"
188- raise ValueError (
189- f"Unknown us_equity strategy profile={ profile !r} ; supported canonical values: { supported } ; aliases: { aliases } "
190- )
191- return STRATEGY_DEFINITIONS [canonical ]
180+ return get_catalog_strategy_definition (STRATEGY_CATALOG , profile )
192181
193182
194183
195184def get_strategy_index_rows () -> list [dict [str , object ]]:
196- rows : list [dict [str , object ]] = []
197- for canonical_profile in sorted (STRATEGY_METADATA ):
198- metadata = STRATEGY_METADATA [canonical_profile ]
199- definition = STRATEGY_DEFINITIONS [canonical_profile ]
200- rows .append (
201- {
202- "canonical_profile" : metadata .canonical_profile ,
203- "display_name" : metadata .display_name ,
204- "aliases" : metadata .aliases ,
205- "description" : metadata .description ,
206- "cadence" : metadata .cadence ,
207- "asset_scope" : metadata .asset_scope ,
208- "benchmark" : metadata .benchmark ,
209- "role" : metadata .role ,
210- "status" : metadata .status ,
211- "component_names" : tuple (component .name for component in definition .components ),
212- "compatible_platforms" : STRATEGY_PLATFORM_COMPATIBILITY [canonical_profile ],
213- }
214- )
215- return rows
185+ return build_strategy_index_rows (STRATEGY_CATALOG )
216186
217187
218188
@@ -221,14 +191,7 @@ def get_strategy_metadata_map() -> dict[str, StrategyMetadata]:
221191
222192
223193def get_strategy_metadata (profile : str ) -> StrategyMetadata :
224- canonical = resolve_canonical_profile (profile )
225- if canonical not in STRATEGY_METADATA :
226- supported = ", " .join (sorted (STRATEGY_METADATA )) or "<none>"
227- aliases = ", " .join (sorted (PROFILE_ALIASES )) or "<none>"
228- raise ValueError (
229- f"Unknown us_equity strategy profile={ profile !r} ; supported canonical values: { supported } ; aliases: { aliases } "
230- )
231- return STRATEGY_METADATA [canonical ]
194+ return get_catalog_strategy_metadata (STRATEGY_CATALOG , profile )
232195
233196
234197def get_profile_aliases () -> dict [str , str ]:
0 commit comments