#!/bin/bash
# Wire CEXBOT global risk hooks

FILE=/opt/dyeverse/crypto_agency/cex_bot/main.py

# 1. Add pre-order check before execute_intent (around line 372)
sed -i '372i\            # Global risk DB check\n            if not _cex_pre_order_check():\n                logger.critical(f"[EXEC] Order blocked by global risk DB")\n                self.risk_gate.clear_pending(intent.exchange, intent.symbol, intent.side, intent.size_usd)\n                return\n' $FILE

# 2. Add PnL recording after position_tracker update (around line 410)
sed -i '410a\                    # Record PnL to global risk DB\n                    pnl_delta = self.position_tracker.get_session_pnl()\n                    _cex_record_pnl(pnl_delta)' $FILE

# 3. Add hot-reload check in status loop (around line 442)
sed -i '442a\            # Hot-reload check\n            _cex_reload_check()' $FILE

echo "CEXBOT hooks wired"
