权利金折 U 优先用开仓 budget_usdt,避免随币价浮动。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-03 03:23:46 +08:00
parent a71042c3e1
commit 91ff1cdecc
2 changed files with 35 additions and 1 deletions
+21
View File
@@ -148,6 +148,27 @@ def sum_open_premium_paid(conn: sqlite3.Connection, inst_id: str) -> float | Non
return round(float(row["total"] or 0), 8)
def sum_open_budget_usdt(conn: sqlite3.Connection, inst_id: str) -> float | None:
"""同合约 open 腿开仓预算/兑换占用 USDT 合计(权利金折 U 展示用,不随币价变)."""
inst = (inst_id or "").strip()
if not inst:
return None
row = conn.execute(
"""
SELECT SUM(budget_usdt) AS total, COUNT(*) AS n
FROM options_trades
WHERE inst_id = ? AND status = 'open' AND budget_usdt IS NOT NULL
""",
(inst,),
).fetchone()
if not row or int(row["n"] or 0) < 1:
return None
try:
return round(float(row["total"] or 0), 4)
except (TypeError, ValueError):
return None
def sum_open_sheets(conn: sqlite3.Connection, inst_id: str) -> int | None:
"""同合约所有 open 腿张数合计."""
inst = (inst_id or "").strip()