33from collections .abc import Mapping
44from typing import Any
55
6- from quant_platform_kit .strategy_contracts import StrategyDecision
6+ from quant_platform_kit .strategy_contracts import (
7+ StrategyDecision ,
8+ build_allocation_intent ,
9+ build_allocation_payload ,
10+ )
711
812
913_EMERGENCY_FLAGS = frozenset ({"emergency" , "hard_defense" })
@@ -25,10 +29,15 @@ def _derive_target_weights(decision: StrategyDecision) -> dict[str, float]:
2529def _derive_managed_symbols (
2630 decision : StrategyDecision ,
2731 runtime_metadata : Mapping [str , Any ],
32+ * ,
33+ allocation_payload : Mapping [str , Any ] | None = None ,
2834) -> tuple [str , ...]:
2935 explicit = runtime_metadata .get ("managed_symbols" )
3036 if explicit :
3137 return tuple (str (symbol ) for symbol in explicit )
38+ allocation_symbols = allocation_payload .get ("strategy_symbols" ) if allocation_payload else None
39+ if allocation_symbols :
40+ return tuple (str (symbol ) for symbol in allocation_symbols )
3241 return tuple (position .symbol for position in decision .positions )
3342
3443
@@ -93,18 +102,33 @@ def map_strategy_decision(
93102 risk_flags = tuple (str (flag ) for flag in decision .risk_flags )
94103 no_execute = bool (_NO_EXECUTE_FLAGS & set (risk_flags ))
95104 target_weights = None if no_execute else _derive_target_weights (decision )
105+ allocation_payload = None
106+ if not no_execute and decision .positions :
107+ allocation_payload = build_allocation_payload (
108+ build_allocation_intent (
109+ decision ,
110+ strategy_profile = strategy_profile ,
111+ strategy_symbols_order = "risk_safe_income" ,
112+ )
113+ )
96114 signal_desc = _derive_signal_description (decision , runtime_metadata )
97115 status_desc = _derive_status_description (decision , runtime_metadata )
98116 is_emergency = bool (_EMERGENCY_FLAGS & set (risk_flags ))
99117
100118 metadata : dict [str , Any ] = {** runtime_metadata , ** diagnostics }
101119 metadata .setdefault ("strategy_profile" , strategy_profile )
102120 metadata .setdefault ("status_icon" , "🐤" )
103- metadata .setdefault ("managed_symbols" , _derive_managed_symbols (decision , runtime_metadata ))
121+ metadata .setdefault (
122+ "managed_symbols" ,
123+ _derive_managed_symbols (decision , runtime_metadata , allocation_payload = allocation_payload ),
124+ )
104125 safe_haven_symbol = _derive_safe_haven_symbol (decision , runtime_metadata )
105126 if safe_haven_symbol :
106127 metadata .setdefault ("safe_haven_symbol" , safe_haven_symbol )
107128 metadata .setdefault ("risk_flags" , risk_flags )
108129 metadata .setdefault ("actionable" , not no_execute )
130+ if allocation_payload :
131+ metadata .setdefault ("target_mode" , allocation_payload ["target_mode" ])
132+ metadata .setdefault ("allocation" , allocation_payload )
109133
110134 return target_weights , signal_desc , is_emergency , status_desc , metadata
0 commit comments