From b37671e5342e280e262d68565e023159257b5fb1 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Fri, 29 May 2026 11:37:06 +0800 Subject: [PATCH] Infer quote overlay state in notifications --- notifications/renderers.py | 18 +++++++++++++++++- tests/test_notifications.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/notifications/renderers.py b/notifications/renderers.py index c5d0b3b..5809fff 100644 --- a/notifications/renderers.py +++ b/notifications/renderers.py @@ -70,6 +70,22 @@ def _localize_notification_text(text, *, translator): return _base_localize_notification_text(text, translator=translator) +def _infer_quote_overlay_used(source: str, overlay): + if overlay is not None: + return overlay + normalized_source = str(source or "").strip().lower() + if "with_live_quote_overlay" in normalized_source: + return True + if normalized_source in { + "longbridge_candlesticks", + "historical_close", + "snapshot_close", + "market_quote", + }: + return False + return None + + def _localize_timing_contract(contract: str, *, translator) -> str: value = str(contract or "").strip() if not value: @@ -177,7 +193,7 @@ def _format_signal_snapshot_line(snapshot, *, translator) -> str: return "" market_date = str(snapshot.get("market_date") or snapshot.get("signal_as_of") or "").strip() source = str(snapshot.get("latest_price_source") or "").strip() - overlay = snapshot.get("quote_overlay_used") + overlay = _infer_quote_overlay_used(source, snapshot.get("quote_overlay_used")) warning = snapshot.get("data_freshness_warning") if not market_date and not source and overlay is None and warning in (None, "", False): return "" diff --git a/tests/test_notifications.py b/tests/test_notifications.py index 2be0484..ae80c4f 100644 --- a/tests/test_notifications.py +++ b/tests/test_notifications.py @@ -133,7 +133,7 @@ def test_heartbeat_signal_snapshot_localizes_price_source(self): ) self.assertIn("数据源 LongBridge 日线K线", rendered.compact_text) - self.assertIn("报价覆盖 未知", rendered.compact_text) + self.assertIn("报价覆盖 否", rendered.compact_text) self.assertIn("📊 市场状态: 🚀 风险开启(SOXX+SOXL)", rendered.compact_text) self.assertNotIn("longbridge_candlesticks", rendered.compact_text)