-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrategy_loader.py
More file actions
91 lines (74 loc) · 3.62 KB
/
Copy pathstrategy_loader.py
File metadata and controls
91 lines (74 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from __future__ import annotations
import os
from quant_platform_kit.common.platform_runner.loader import (
load_strategy_definition as _qpk_load_definition,
load_strategy_entrypoint_for_profile as _qpk_load_entrypoint,
)
from quant_platform_kit.common.strategies import StrategyDefinition
from quant_platform_kit.common.strategy_contracts import (
StrategyEntrypoint,
StrategyRuntimeAdapter,
)
from us_equity_strategies import get_strategy_entrypoint
from strategy_registry import LONGBRIDGE_PLATFORM as PLATFORM, PLATFORM_POLICY, STRATEGY_CATALOG, get_platform_runtime_adapter
_V7_PROFILE_NAME = "soxl_soxx_core_only_p2_v7_longterm_compounding_cash_reserve"
def _bound_v7_application(raw_profile: str | None) -> bool:
"""Return true only for the exact paused V7 application binding.
The normal platform policy remains the default. This one guarded loader
path exists so a disabled candidate revision can prove what it loaded;
it never grants an execution route or changes the global allowlist.
"""
if str(raw_profile or "").strip() != _V7_PROFILE_NAME:
return False
from application.v7_paper_application import load_v7_paper_application_binding
return load_v7_paper_application_binding(os.environ) is not None
def load_strategy_definition(raw_profile: str | None) -> StrategyDefinition:
if _bound_v7_application(raw_profile):
return STRATEGY_CATALOG.definitions[raw_profile.strip()]
return _qpk_load_definition(
raw_profile,
platform_id=PLATFORM,
strategy_catalog=STRATEGY_CATALOG,
policy=PLATFORM_POLICY,
)
def load_strategy_entrypoint_for_profile(raw_profile: str | None) -> StrategyEntrypoint:
if _bound_v7_application(raw_profile):
return get_strategy_entrypoint(raw_profile.strip())
runtime_adapter = load_strategy_runtime_adapter_for_profile(raw_profile)
return _qpk_load_entrypoint(
raw_profile,
platform_id=PLATFORM,
strategy_catalog=STRATEGY_CATALOG,
policy=PLATFORM_POLICY,
runtime_adapter=runtime_adapter,
)
def load_strategy_execution_entrypoint_for_profile(
raw_profile: str | None,
*,
execution_materials: dict[str, object] | None,
) -> StrategyEntrypoint:
"""Load the separately guarded V7 execution entrypoint.
The ordinary loader remains research-only for V7. Execution selection is
explicit and requires a validated PAPER mandate and release material.
"""
if str(raw_profile or "").strip() != _V7_PROFILE_NAME:
raise ValueError("V7 execution entrypoint requires the exact V7 profile")
if not _bound_v7_application(raw_profile):
raise ValueError("V7 execution entrypoint requires the protected binding")
materials = execution_materials or {}
mandate = materials.get("mandate_provenance")
if not isinstance(mandate, dict) or mandate.get("authority_scope") != "PAPER":
raise ValueError("V7 execution entrypoint requires a PAPER mandate")
if materials.get("strategy_release") is None:
raise ValueError("V7 execution entrypoint requires a strategy release")
try:
from us_equity_strategies.entrypoints import soxl_soxx_core_only_p2_v7_execution_entrypoint
except ImportError as exc:
raise ValueError("V7 execution entrypoint is unavailable in the installed UES revision") from exc
return soxl_soxx_core_only_p2_v7_execution_entrypoint
def load_strategy_runtime_adapter_for_profile(raw_profile: str | None) -> StrategyRuntimeAdapter:
definition = load_strategy_definition(raw_profile)
return get_platform_runtime_adapter(
definition.profile,
platform_id=PLATFORM,
)