From a2b9b431c71279123c3442e10792815edbab4081 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sun, 26 Jul 2026 23:29:54 +0000 Subject: [PATCH] fix: isolate auxiliary price source failures --- dashboard/server.py | 12 ++++++++++-- tests/test_server_reliability.py | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dashboard/server.py b/dashboard/server.py index 8ab16a8..d01356d 100644 --- a/dashboard/server.py +++ b/dashboard/server.py @@ -206,7 +206,11 @@ def run_scrape(force_full=False): price_current = metrics["price"] log.info("Fetching BTC ATH...") - ath_data = price.fetch_ath() + try: + ath_data = price.fetch_ath() + except Exception as e: + cycle_errors.append(f"ATH: {e}") + ath_data = {} ath_val = ath_data.get("ath") or existing_cache.get("drawdown", {}).get("ath") if price_current.get("price") and ath_val: drawdown = price.calculate_drawdown(price_current["price"], ath_val) @@ -218,7 +222,11 @@ def run_scrape(force_full=False): metrics["drawdown"] = {"value": None} log.info("Fetching historical prices for 200D SMA / Mayer...") - hist = price.fetch_historical() + try: + hist = price.fetch_historical() + except Exception as e: + cycle_errors.append(f"Historical price: {e}") + hist = [] if hist: sma_200d = price.calculate_200d_sma(hist) mayer = price.calculate_mayer_multiple(price_current.get("price"), sma_200d) diff --git a/tests/test_server_reliability.py b/tests/test_server_reliability.py index 548c002..66e2872 100644 --- a/tests/test_server_reliability.py +++ b/tests/test_server_reliability.py @@ -89,8 +89,8 @@ def test_partial_fast_scrape_preserves_last_known_good_metric(server, monkeypatc monkeypatch.setattr(server, "HISTORY_PATH", str(history_path)) monkeypatch.setattr(server.fear_greed, "fetch", lambda: {"value": 25}) monkeypatch.setattr(server.price, "fetch_current", lambda: (_ for _ in ()).throw(RuntimeError("price timeout"))) - monkeypatch.setattr(server.price, "fetch_ath", lambda: {"ath": 70000}) - monkeypatch.setattr(server.price, "fetch_historical", lambda: []) + monkeypatch.setattr(server.price, "fetch_ath", lambda: (_ for _ in ()).throw(RuntimeError("ATH timeout"))) + monkeypatch.setattr(server.price, "fetch_historical", lambda: (_ for _ in ()).throw(RuntimeError("history timeout"))) monkeypatch.setattr(server.engine, "score_all", lambda metrics: {"composite_score": 50, "scored_count": 1, "metrics": []}) monkeypatch.setattr(server.engine, "score_all_ml", lambda metrics: {"composite_score": 50, "scored_count": 1, "metrics": []}) fake_updater = types.ModuleType("scrapers.history_updater")