Harden discovery: surface screener failures + regression test
- discover_active_symbols logs the screener error instead of swallowing silently. - run_discovery records an explicit error when the universe is empty (surfaces in the discovery event + Grafana). - momentum doctor now FAILs when the latest discovery universe is 0 (the morning's dead screener would have shown red within a minute). - tests/unit/research/test_discovery.py: pins get_most_actives top<=100 and the ETF/price-band filtering. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
9113d8ea4c
commit
3e2b4f562e
4 files changed
+77
-4
No files matched your search
@@ -168,6 +168,12 @@ def run_discovery(
|
||||
for ticker in result.news:
|
||||
if ticker not in result.universe:
|
||||
result.universe.append(ticker)
|
||||
if not result.universe:
|
||||
# Make a dead screener LOUD (this was silent for a whole session once):
|
||||
# surfaces in the discovery event's errors and `momentum doctor`.
|
||||
result.errors.append(
|
||||
"screener returned 0 names (Alpaca cap/limit, or no qualifying movers)"
|
||||
)
|
||||
|
||||
# Backfill daily history for the universe so gap%/RVOL have a baseline.
|
||||
if backfill_daily and result.universe and client is not None:
|
||||
|
||||
@@ -13,6 +13,7 @@ hardcoded ``is_regular_hours = TRUE`` on every row. Here we:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import date, datetime, time, timedelta, timezone
|
||||
from zoneinfo import ZoneInfo
|
||||
@@ -23,6 +24,8 @@ REGULAR_CLOSE = time(16, 0)
|
||||
PREMARKET_OPEN = time(4, 0)
|
||||
AFTERHOURS_CLOSE = time(20, 0)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def classify_session(ts_utc: datetime) -> tuple[date, bool, bool, bool]:
|
||||
"""Return (session_date, is_premarket, is_regular_hours, is_afterhours)."""
|
||||
@@ -251,5 +254,6 @@ def discover_active_symbols(
|
||||
if len(in_band) >= top:
|
||||
break
|
||||
return in_band
|
||||
except Exception: # noqa: BLE001 - screener needs a paid feed sometimes
|
||||
except Exception as exc: # noqa: BLE001 - screener needs a paid feed sometimes
|
||||
logger.warning("most-actives screener failed: %s", exc)
|
||||
return []
|
||||
Reference in new issue
Block a user