From fe754cf6285cca82f84ea7f5ff5d21a42fdb8886 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 2 Mar 2026 10:05:45 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20live=5Fexecutor=E5=BC=80=E4=BB=93?= =?UTF-8?q?=E5=89=8D=E6=A3=80=E6=9F=A5risk=5Fguard=E7=8A=B6=E6=80=81+?= =?UTF-8?q?=E7=B4=A7=E6=80=A5=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 读/tmp/risk_guard_state.json: block_new_entries=true → 拒绝开仓 - 读/tmp/risk_guard_state.json: reduce_only=true → 拒绝开仓 - 读/tmp/risk_guard_emergency.json: close_all/block_new → 拒绝开仓 - risk_guard未启动(文件不存在) → 允许交易(不阻塞) --- backend/live_executor.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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: