Skip to content

Commit 7cf72d8

Browse files
committed
Use QuantPlatformKit shared strategy contract
1 parent ad793b3 commit 7cf72d8

3 files changed

Lines changed: 21 additions & 37 deletions

File tree

‎requirements.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
flask
22
gunicorn
3-
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@v0.4.0
3+
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@v0.5.0
44
pandas
55
requests
66
pytz

‎strategy_registry.py‎

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
from __future__ import annotations
22

3-
from dataclasses import dataclass
4-
5-
US_EQUITY_DOMAIN = "us_equity"
6-
CRYPTO_DOMAIN = "crypto"
3+
from quant_platform_kit.common.strategies import (
4+
US_EQUITY_DOMAIN,
5+
StrategyDefinition,
6+
get_supported_profiles_for_platform as qpk_get_supported_profiles_for_platform,
7+
resolve_strategy_definition as qpk_resolve_strategy_definition,
8+
)
79

810
LONGBRIDGE_PLATFORM = "longbridge"
911

1012

11-
@dataclass(frozen=True)
12-
class StrategyDefinition:
13-
profile: str
14-
domain: str
15-
supported_platforms: frozenset[str]
16-
17-
1813
DEFAULT_STRATEGY_PROFILE = "semiconductor_rotation_income"
1914

2015
STRATEGY_DEFINITIONS: dict[str, StrategyDefinition] = {
@@ -33,11 +28,10 @@ class StrategyDefinition:
3328

3429

3530
def get_supported_profiles_for_platform(platform_id: str) -> frozenset[str]:
36-
return frozenset(
37-
profile
38-
for profile, definition in STRATEGY_DEFINITIONS.items()
39-
if platform_id in definition.supported_platforms
40-
and definition.domain in PLATFORM_SUPPORTED_DOMAINS.get(platform_id, frozenset())
31+
return qpk_get_supported_profiles_for_platform(
32+
STRATEGY_DEFINITIONS,
33+
PLATFORM_SUPPORTED_DOMAINS,
34+
platform_id=platform_id,
4135
)
4236

4337

@@ -46,23 +40,10 @@ def resolve_strategy_definition(
4640
*,
4741
platform_id: str,
4842
) -> StrategyDefinition:
49-
profile = (raw_value or DEFAULT_STRATEGY_PROFILE).strip().lower()
50-
definition = STRATEGY_DEFINITIONS.get(profile)
51-
supported = ", ".join(sorted(get_supported_profiles_for_platform(platform_id)))
52-
53-
if definition is None:
54-
raise ValueError(
55-
f"Unsupported STRATEGY_PROFILE={raw_value!r}; supported values: {supported}"
56-
)
57-
58-
if platform_id not in definition.supported_platforms:
59-
raise ValueError(
60-
f"Unsupported STRATEGY_PROFILE={raw_value!r}; supported values: {supported}"
61-
)
62-
63-
if definition.domain not in PLATFORM_SUPPORTED_DOMAINS.get(platform_id, frozenset()):
64-
raise ValueError(
65-
f"Unsupported strategy domain {definition.domain!r} for platform {platform_id!r}"
66-
)
67-
68-
return definition
43+
return qpk_resolve_strategy_definition(
44+
raw_value,
45+
platform_id=platform_id,
46+
strategy_definitions=STRATEGY_DEFINITIONS,
47+
platform_supported_domains=PLATFORM_SUPPORTED_DOMAINS,
48+
default_profile=DEFAULT_STRATEGY_PROFILE,
49+
)

‎tests/test_runtime_config_support.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
ROOT = Path(__file__).resolve().parents[1]
99
if str(ROOT) not in sys.path:
1010
sys.path.insert(0, str(ROOT))
11+
QPK_SRC = ROOT.parent / "QuantPlatformKit" / "src"
12+
if str(QPK_SRC) not in sys.path:
13+
sys.path.insert(0, str(QPK_SRC))
1114

1215
from runtime_config_support import (
1316
DEFAULT_ACCOUNT_REGION,

0 commit comments

Comments
 (0)