Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion notifications/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 ""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down