From f7f0aa0678eb732f320ca2bbc2585698874d3282 Mon Sep 17 00:00:00 2001 From: John Weston Date: Mon, 23 Mar 2026 19:05:23 -0400 Subject: [PATCH] Address Gemini round 6: fix indicator fallback, consistent _safe_get usage HIGH: Unknown indicator now returns clear error with supported list instead of silently falling back to technicals() which has a different response structure MEDIUM: Use _safe_get consistently in get_sentiment_score (was data.get) --- tradingagents/dataflows/polaris.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tradingagents/dataflows/polaris.py b/tradingagents/dataflows/polaris.py index a939ff82..a7c39966 100644 --- a/tradingagents/dataflows/polaris.py +++ b/tradingagents/dataflows/polaris.py @@ -218,7 +218,12 @@ def get_indicators( if polaris_type in known_types: data = client.indicators(symbol, type=polaris_type, range=range_param) else: - data = client.technicals(symbol, range=range_param) + # Unknown indicator — return an error rather than silently falling back + # to client.technicals() which returns a different structure + return ( + f"Unknown indicator '{indicator}' for {symbol}. " + f"Supported: {', '.join(sorted(known_types))}" + ) except Exception as e: return f"Error fetching indicators for {symbol}: {e}" @@ -589,11 +594,11 @@ def get_sentiment_score( except Exception as e: return f"Error fetching sentiment score for {symbol}: {e}" - components = data.get("components", {}) - sent = components.get("sentiment", {}) or {} - mom = components.get("momentum", {}) or {} - vol = components.get("volume", {}) or {} - evt = components.get("events", {}) or {} + components = _safe_get(data, "components", {}) + sent = _safe_get(components, "sentiment", {}) + mom = _safe_get(components, "momentum", {}) + vol = _safe_get(components, "volume", {}) + evt = _safe_get(components, "events", {}) lines = [ f"# Composite Trading Signal: {symbol.upper()}",