feat: live_executor开仓前检查risk_guard状态+紧急指令

- 读/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未启动(文件不存在) → 允许交易(不阻塞)
This commit is contained in:
root 2026-03-02 10:05:45 +00:00
parent cb869926e2
commit fe754cf628

View File

@ -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: