# ── Stop-Loss Check (prevent position blowouts) ──────────────────────── stop_loss_triggers = self.positions.check_stop_loss_positions(self.risk_manager) for sl_ticker in stop_loss_triggers: logger.critical(f"[STOP_LOSS] Force-closing {sl_ticker} (exceeded $50 max loss)") sl_pos = self.positions.get_position(sl_ticker) if sl_pos.side == "LONG": # Force market sell price = tick.get("price", 0) tx = await self.executor.execute_market_swap(sl_ticker, sl_pos.qty_usd, "SELL") if tx: pnl_event = self.positions.record_fill(sl_ticker, "SELL", sl_pos.qty_usd, price) if pnl_event: self.risk_manager._daily_pnl += pnl_event["realized_pnl"] self.risk_manager._save_state() self._log_tape("STOP_LOSS_EXIT", { "ticker": sl_ticker, "side": "SELL", "size_usd": sl_pos.qty_usd, "price": price, "realized_pnl": pnl_event.get("realized_pnl", 0) if pnl_event else 0, "unrealized_pnl": sl_pos.unrealized_pnl(), })