diff --git a/services/trading/engine.py b/services/trading/engine.py index 43c3ac4..1a39669 100644 --- a/services/trading/engine.py +++ b/services/trading/engine.py @@ -584,11 +584,21 @@ class TradingEngine: "WHERE action IN ('buy','sell') " "AND mode IN ('paper_eligible','live_eligible') " "AND generated_at > $1 " - "ORDER BY confidence DESC", + "ORDER BY confidence DESC " + "LIMIT 50", self._last_poll_timestamp, ) - self._last_poll_timestamp = datetime.now(tz=timezone.utc) + if rows: + # Advance timestamp to the oldest rec in this batch + # so next poll picks up where we left off + last_gen = max(r["generated_at"] for r in rows) + self._last_poll_timestamp = last_gen recs = [dict(r) for r in rows] + if recs: + logger.info( + "Polled %d recommendations (highest confidence=%.3f)", + len(recs), recs[0].get("confidence", 0), + ) except Exception: logger.debug("Could not poll recommendations — table may not exist yet") continue