45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
|
|
"""Compatibility wrapper for the legacy policy engine namespace."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from dataclasses import dataclass
|
||
|
|
from typing import Optional
|
||
|
|
|
||
|
|
from prod.clean_arch.dita.account import AccountProjection, AccountSnapshot
|
||
|
|
from prod.clean_arch.dita.contracts import DecisionConfig as PolicyConfig
|
||
|
|
from prod.clean_arch.dita.decision import DecisionEngine
|
||
|
|
from prod.clean_arch.dita.intent import IntentEngine
|
||
|
|
from prod.clean_arch.dita.trade import TradeExecutor
|
||
|
|
|
||
|
|
from .contracts import PolicyContext, PolicyPosition
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass(frozen=True)
|
||
|
|
class PolicyContextWrapper:
|
||
|
|
"""Backward-compatible context alias for older callers."""
|
||
|
|
|
||
|
|
capital: float
|
||
|
|
open_positions: int = 0
|
||
|
|
trade_seq: int = 0
|
||
|
|
|
||
|
|
|
||
|
|
class PolicyEngine:
|
||
|
|
"""Legacy facade that now delegates to the DITA boundary."""
|
||
|
|
|
||
|
|
def __init__(self, config: Optional[PolicyConfig] = None):
|
||
|
|
self.config = config or PolicyConfig()
|
||
|
|
self.decision_engine = DecisionEngine(self.config)
|
||
|
|
self.intent_engine = IntentEngine(self.config)
|
||
|
|
self.trade_executor = TradeExecutor()
|
||
|
|
self.account = AccountProjection(
|
||
|
|
runtime_namespace="pink",
|
||
|
|
strategy_namespace="pink",
|
||
|
|
event_namespace="pink",
|
||
|
|
)
|
||
|
|
self.account.snapshot = AccountSnapshot(capital=25_000.0, equity=25_000.0)
|
||
|
|
|
||
|
|
def decide(self, snapshot, context: PolicyContext, position: Optional[PolicyPosition] = None):
|
||
|
|
decision = self.decision_engine.decide(snapshot, context, position)
|
||
|
|
return decision
|
||
|
|
|