Keep unflat legs on 当前持仓 after plan end.
Closed plans with open legs stay visible and closable so residual positions are not orphaned from the UI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -192,6 +192,34 @@ def list_plans(
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def list_plans_for_live_positions(
|
||||
conn: sqlite3.Connection,
|
||||
*,
|
||||
plan_type: str = "perp_options",
|
||||
limit: int = 40,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""当前持仓用:进行中计划 + 已结束但仍有 open 腿(人工结束未平仓残留)."""
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT DISTINCT p.*
|
||||
FROM hedge_plans p
|
||||
LEFT JOIN hedge_plan_legs l ON l.plan_id = p.id
|
||||
WHERE p.plan_type = ?
|
||||
AND (
|
||||
p.status IN ('opening', 'active', 'partial')
|
||||
OR (
|
||||
p.status = 'closed'
|
||||
AND lower(coalesce(l.status, '')) = 'open'
|
||||
)
|
||||
)
|
||||
ORDER BY p.id DESC
|
||||
LIMIT ?
|
||||
""",
|
||||
(str(plan_type), int(limit)),
|
||||
).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def get_plan(conn: sqlite3.Connection, plan_id: int) -> Optional[dict[str, Any]]:
|
||||
row = conn.execute("SELECT * FROM hedge_plans WHERE id=?", (plan_id,)).fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
Reference in New Issue
Block a user