-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrategy_registry.py
More file actions
116 lines (96 loc) · 3.57 KB
/
strategy_registry.py
File metadata and controls
116 lines (96 loc) · 3.57 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from __future__ import annotations
from crypto_strategies import get_platform_runtime_adapter, get_strategy_catalog
from quant_platform_kit.common.strategies import (
CRYPTO_DOMAIN,
PlatformCapabilityMatrix,
PlatformStrategyPolicy,
StrategyDefinition,
build_platform_profile_matrix,
build_platform_profile_status_matrix,
derive_enabled_profiles_for_platform,
derive_eligible_profiles_for_platform,
get_catalog_strategy_metadata,
get_enabled_profiles_for_platform,
resolve_platform_strategy_definition,
)
BINANCE_PLATFORM = "binance"
DEFAULT_STRATEGY_PROFILE = "crypto_leader_rotation"
ROLLBACK_STRATEGY_PROFILE = DEFAULT_STRATEGY_PROFILE
STRATEGY_CATALOG = get_strategy_catalog()
STRATEGY_DEFINITIONS = dict(STRATEGY_CATALOG.definitions)
BINANCE_ROLLOUT_ALLOWLIST = frozenset(STRATEGY_DEFINITIONS)
PLATFORM_SUPPORTED_DOMAINS: dict[str, frozenset[str]] = {
BINANCE_PLATFORM: frozenset({CRYPTO_DOMAIN}),
}
PLATFORM_CAPABILITY_MATRIX = PlatformCapabilityMatrix(
platform_id=BINANCE_PLATFORM,
supported_domains=PLATFORM_SUPPORTED_DOMAINS[BINANCE_PLATFORM],
supported_target_modes=frozenset({"weight"}),
supported_inputs=frozenset(
{
"market_prices",
"derived_indicators",
"benchmark_snapshot",
"portfolio_snapshot",
"universe_snapshot",
}
),
supported_capabilities=frozenset(),
)
ELIGIBLE_STRATEGY_PROFILES = derive_eligible_profiles_for_platform(
STRATEGY_CATALOG,
capability_matrix=PLATFORM_CAPABILITY_MATRIX,
runtime_adapter_loader=lambda profile: get_platform_runtime_adapter(
profile,
platform_id=BINANCE_PLATFORM,
),
)
BINANCE_ENABLED_PROFILES = derive_enabled_profiles_for_platform(
STRATEGY_CATALOG,
capability_matrix=PLATFORM_CAPABILITY_MATRIX,
runtime_adapter_loader=lambda profile: get_platform_runtime_adapter(
profile,
platform_id=BINANCE_PLATFORM,
),
rollout_allowlist=BINANCE_ROLLOUT_ALLOWLIST,
)
PLATFORM_POLICY = PlatformStrategyPolicy(
platform_id=BINANCE_PLATFORM,
supported_domains=PLATFORM_SUPPORTED_DOMAINS[BINANCE_PLATFORM],
enabled_profiles=BINANCE_ENABLED_PROFILES,
default_profile=DEFAULT_STRATEGY_PROFILE,
rollback_profile=ROLLBACK_STRATEGY_PROFILE,
)
SUPPORTED_STRATEGY_PROFILES = BINANCE_ENABLED_PROFILES
def get_eligible_profiles_for_platform(platform_id: str) -> frozenset[str]:
if platform_id != BINANCE_PLATFORM:
return frozenset()
return ELIGIBLE_STRATEGY_PROFILES
def get_supported_profiles_for_platform(platform_id: str) -> frozenset[str]:
return get_enabled_profiles_for_platform(platform_id, policy=PLATFORM_POLICY)
def get_platform_profile_matrix() -> list[dict[str, object]]:
return build_platform_profile_matrix(STRATEGY_CATALOG, policy=PLATFORM_POLICY)
def get_platform_profile_status_matrix() -> list[dict[str, object]]:
return build_platform_profile_status_matrix(
STRATEGY_CATALOG,
policy=PLATFORM_POLICY,
eligible_profiles=ELIGIBLE_STRATEGY_PROFILES,
)
def resolve_strategy_definition(
raw_value: str | None,
*,
platform_id: str,
) -> StrategyDefinition:
return resolve_platform_strategy_definition(
raw_value,
platform_id=platform_id,
strategy_catalog=STRATEGY_CATALOG,
policy=PLATFORM_POLICY,
)
def resolve_strategy_metadata(
raw_value: str | None,
*,
platform_id: str,
):
definition = resolve_strategy_definition(raw_value, platform_id=platform_id)
return get_catalog_strategy_metadata(STRATEGY_CATALOG, definition.profile)