diff --git a/backend/live_executor.py b/backend/live_executor.py index 557f8c0..43f3f1d 100644 --- a/backend/live_executor.py +++ b/backend/live_executor.py @@ -263,6 +263,34 @@ async def execute_entry(session: aiohttp.ClientSession, signal: dict, db_conn): t_signal = signal_ts # 信号时间戳(ms) + # 0. 检查风控状态(读risk_guard写的状态文件) + try: + with open("/tmp/risk_guard_state.json") as f: + risk_state = json.load(f) + if risk_state.get("block_new_entries"): + logger.warning(f"[{symbol}] ❌ 风控禁止新开仓: {risk_state.get('circuit_break_reason', '未知原因')}") + return None + if risk_state.get("reduce_only"): + logger.warning(f"[{symbol}] ❌ 只减仓模式,拒绝开仓") + return None + except FileNotFoundError: + pass # risk_guard还没启动,允许交易 + except Exception as e: + logger.warning(f"[{symbol}] ⚠ 读取风控状态失败: {e},继续交易") + + # 检查前端紧急操作指令 + try: + with open("/tmp/risk_guard_emergency.json") as f: + emergency = json.load(f) + action = emergency.get("action") + if action in ("close_all", "block_new"): + logger.warning(f"[{symbol}] ❌ 紧急指令生效: {action},拒绝开仓") + return None + except FileNotFoundError: + pass + except Exception: + pass + # 1. 检查余额 balance = await get_account_balance(session) if balance < RISK_PER_TRADE_USD * 2: