fix: 交易安全审计修复 — 补偿平仓、中控同步、滚仓/趋势防护

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-04 22:44:16 +08:00
parent df28e6dfb8
commit eb975b0133
11 changed files with 675 additions and 162 deletions
+15 -2
View File
@@ -40,7 +40,8 @@ def check_roll_monitors(cfg: dict[str, Any]) -> None:
_reconcile_roll_groups(conn, cfg)
_check_pending_roll_legs(conn, cfg)
conn.commit()
except Exception:
except Exception as e:
print(f"[roll_monitor] {e}", flush=True)
try:
conn.rollback()
except Exception:
@@ -408,7 +409,19 @@ def _execute_pending_roll_leg(
return
oid = str(order.get("id") or "") if isinstance(order, dict) else ""
cfg["replace_tpsl"](ex_sym, direction, sl, tp0, mon)
try:
cfg["replace_tpsl"](ex_sym, direction, sl, tp0, mon)
except Exception as tpsl_err:
fe = cfg.get("friendly_error")
msg = fe(tpsl_err) if callable(fe) else str(tpsl_err)
conn.execute(
"""UPDATE roll_legs SET status='error', exchange_order_id=?, fill_price=?, amount=?
WHERE id=? AND status='pending'""",
(oid, fill, float(amount), leg_id),
)
_notify_roll_fail(cfg, group, leg, mark, f"加仓成交但止盈止损更新失败: {msg}")
return
conn.execute(
"""UPDATE roll_legs SET status='filled', fill_price=?, amount=?, exchange_order_id=?,
new_stop_loss=? WHERE id=? AND status='pending'""",