Exclude trend and roll monitors from position-limit freeze count.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -139,3 +139,40 @@ def entry_reason_for_monitor_type(monitor_type: str | None) -> str:
|
||||
if mt == MONITOR_TYPE_ROLL:
|
||||
return ENTRY_REASON_ROLL
|
||||
return ""
|
||||
|
||||
|
||||
def order_monitor_excluded_from_position_limit(conn, row) -> bool:
|
||||
"""趋势回调 / 顺势加仓不计入 MAX_ACTIVE_POSITIONS 与仓位上限冻结。"""
|
||||
if order_monitor_source_type(row) in (MONITOR_TYPE_TREND_PULLBACK, MONITOR_TYPE_ROLL):
|
||||
return True
|
||||
oid = None
|
||||
try:
|
||||
keys = row.keys() if hasattr(row, "keys") else []
|
||||
if "id" in keys and row["id"] is not None:
|
||||
oid = int(row["id"])
|
||||
except Exception:
|
||||
oid = None
|
||||
if oid and oid > 0:
|
||||
try:
|
||||
hit = conn.execute(
|
||||
"SELECT 1 FROM roll_groups WHERE order_monitor_id=? AND status='active' LIMIT 1",
|
||||
(oid,),
|
||||
).fetchone()
|
||||
if hit is not None:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def count_position_limit_active_monitors(conn) -> int:
|
||||
"""计入仓位上限冻结的活跃监控数(不含趋势回调、顺势加仓)。"""
|
||||
try:
|
||||
rows = conn.execute("SELECT * FROM order_monitors WHERE status='active'").fetchall()
|
||||
except Exception:
|
||||
return 0
|
||||
n = 0
|
||||
for row in rows:
|
||||
if not order_monitor_excluded_from_position_limit(conn, row):
|
||||
n += 1
|
||||
return n
|
||||
|
||||
Reference in New Issue
Block a user