diff --git a/services/trading/engine.py b/services/trading/engine.py index 6f91f9a..a4f7cc1 100644 --- a/services/trading/engine.py +++ b/services/trading/engine.py @@ -946,6 +946,27 @@ class TradingEngine: if pos_match is None: continue + # Suppress take-profit when a strong buy signal is active + if trigger.trigger_type == "take_profit" and self.pool is not None: + try: + active_buy = await self.pool.fetchrow( + "SELECT confidence FROM recommendations " + "WHERE ticker = $1 AND action = 'buy' " + "AND mode IN ('paper_eligible', 'live_eligible') " + "AND generated_at > NOW() - INTERVAL '2 hours' " + "ORDER BY confidence DESC LIMIT 1", + trigger.ticker, + ) + if active_buy and float(active_buy["confidence"]) >= 0.80: + logger.info( + "Suppressing take-profit for %s — active buy signal (confidence=%.3f)", + trigger.ticker, + float(active_buy["confidence"]), + ) + continue + except Exception: + pass # On error, proceed with the take-profit + await self._submit_sell_order( trigger.ticker, pos_match.quantity,