def get_cex_status(): cex_positions_path = /opt/dyeverse/crypto_agency/cex_bot/data/positions.json if not os.path.exists(cex_positions_path): return {active: False, error: positions.json not found} try: with open(cex_positions_path, r) as f: data = json.load(f) positions = [] for p in data.get(positions, []): positions.append({ exchange: p[exchange], symbol: p[symbol], side: p[side], qty: round(p[qty], 8), qty_usd: round(p[qty_usd], 2), avg_entry: round(p[avg_entry], 4), realized_pnl: round(p[realized_pnl], 4), fills: p[fills], }) total_realized = data.get(total_realized_pnl, 0) kill_switch = False session_pnl = total_realized total_intents = 0 total_executed = 0 mode = paper try: import subprocess result = subprocess.run( [pm2, logs, sovereign-cex, --lines, 100, --nostream, --no-color], capture_output=True, text=True, timeout=3 ) if KILL_SWITCH_BLOCK in result.stdout: kill_switch = True for line in result.stdout.split(chr(10)): if kill_switch= in line: kill_switch = kill_switch=True in line if session_pnl= in line: parts = line.split(session_pnl=) if len(parts) > 1: pnl_str = parts[1].split()[0].replace($, ) try: session_pnl = float(pnl_str) except: pass if intents= in line: parts = line.split(intents=) if len(parts) > 1: try: total_intents = int(parts[1].split()[0]) except: pass if executed= in line: parts = line.split(executed=) if len(parts) > 1: try: total_executed = int(parts[1].split()[0]) except: pass except: pass return { active: True, mode: mode, positions: positions, total_realized_pnl: round(total_realized, 4), session_pnl: round(session_pnl, 4), kill_switch: kill_switch, position_count: len(positions), total_intents: total_intents, total_executed: total_executed, } except Exception as e: return {active: False, error: str(e)}