from __future__ import annotations from typing import Any, Dict, Optional def resolve_analysis_higher_timeframe(interval: str) -> Optional[str]: if interval in {"1h", "4h"}: return "1d" if interval in {"5m", "15m"}: return "1h" return None def build_analysis_endpoint_response( *, symbol: str, interval: str, timestamp: int, analysis: Dict[str, Any], verdict: str, ai_rule_version: str, ai_rule_count: int, refresh_requested: bool, indicators_snapshot: Optional[Dict[str, Any]], ) -> Dict[str, Any]: response: Dict[str, Any] = { "symbol": symbol, "interval": interval, "timestamp": timestamp, "analysis": analysis, "verdict": verdict, "verdict_source": "local_rules", "ai_rules": { "version": ai_rule_version, "loaded_count": ai_rule_count, }, "cache": {"refresh_requested": refresh_requested}, "indicators_snapshot": indicators_snapshot, } response["generated_at"] = timestamp return response