Optimize signal read paths and enforce score invariants

This commit is contained in:
2026-07-11 16:04:13 +02:00
parent fdc49d0e28
commit 9450831ef3
13 changed files with 426 additions and 170 deletions
+14 -10
View File
@@ -566,6 +566,7 @@ async def scan_all_tickers(
ranks = await momentum_service.compute_activation_ranks(db)
except Exception:
await db.rollback()
logger.exception("Activation ranking refresh failed")
ranks = {}
@@ -573,19 +574,21 @@ async def scan_all_tickers(
for index, ticker in enumerate(tickers):
if progress_callback is not None:
progress_callback(index, total, ticker.symbol)
# Refresh scores first so the scheduled scan works off current data.
# Nothing else marks scores stale, so without this they'd never update
# for tickers the user doesn't manually fetch.
try:
# Refresh scores first so the scheduled scan works off current data.
# Nothing else marks scores stale, so without this they'd never
# update for tickers the user doesn't manually fetch.
try:
from app.services import scoring_service
from app.services import scoring_service
await scoring_service.compute_all_dimensions(db, ticker.symbol)
await scoring_service.compute_composite_score(db, ticker.symbol)
await db.commit()
except Exception:
logger.exception("Error refreshing scores for %s", ticker.symbol)
await scoring_service.compute_all_dimensions(db, ticker.symbol)
await scoring_service.compute_composite_score(db, ticker.symbol)
await db.commit()
except Exception:
await db.rollback()
logger.exception("Error refreshing scores for %s", ticker.symbol)
continue
try:
setups = await scan_ticker(
db, ticker.symbol, rr_threshold, atr_multiplier,
momentum_percentile=(ranks.get(ticker.symbol) or {}).get("momentum_percentile"),
@@ -594,6 +597,7 @@ async def scan_all_tickers(
)
all_setups.extend(setups)
except Exception:
await db.rollback()
logger.exception("Error scanning ticker %s", ticker.symbol)
if progress_callback is not None and total: