修复期权币本位高危缺陷:开仓估量、卖回封顶、握库超时与条件单嵌套锁。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -212,31 +212,50 @@ def build_display_option_positions(
|
||||
cfg: dict[str, Any],
|
||||
ex: Any,
|
||||
raw_positions: list[dict[str, Any]],
|
||||
*,
|
||||
include_close_preview: bool = True,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""与实例 /api/options/positions 相同 enrichment + close_preview."""
|
||||
"""与实例 /api/options/positions 相同 enrichment;可选 close_preview.
|
||||
|
||||
DB 读写与交易所拉盘口分离,避免握库期间网络导致 database is locked / 中控超时。
|
||||
"""
|
||||
from lib.options.options_db import init_options_tables, sum_open_budget_usdt, sum_open_premium_paid
|
||||
|
||||
meta_cache: dict[str, dict[str, Any] | None] = {}
|
||||
rows: list[dict[str, Any]] = []
|
||||
prem_by_inst: dict[str, float | None] = {}
|
||||
budget_by_inst: dict[str, float | None] = {}
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
for p in raw_positions:
|
||||
inst = str(p.get("instId") or "").strip()
|
||||
premium_override = sum_open_premium_paid(conn, inst) if inst else None
|
||||
budget_usdt = sum_open_budget_usdt(conn, inst) if inst else None
|
||||
row = enrich_position_row_display(
|
||||
cfg,
|
||||
ex,
|
||||
p,
|
||||
meta_cache=meta_cache,
|
||||
premium_override=premium_override,
|
||||
)
|
||||
if budget_usdt is not None:
|
||||
row["budget_usdt"] = round(float(budget_usdt), 4)
|
||||
row["premium_entry_usdt"] = round(float(budget_usdt), 4)
|
||||
attach_close_preview(cfg, ex, row, premium_paid=_safe_float(row.get("premium_paid")))
|
||||
rows.append(row)
|
||||
if not inst:
|
||||
continue
|
||||
prem_by_inst[inst] = sum_open_premium_paid(conn, inst)
|
||||
budget_by_inst[inst] = sum_open_budget_usdt(conn, inst)
|
||||
try:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
rows: list[dict[str, Any]] = []
|
||||
for p in raw_positions:
|
||||
inst = str(p.get("instId") or "").strip()
|
||||
premium_override = prem_by_inst.get(inst)
|
||||
budget_usdt = budget_by_inst.get(inst)
|
||||
row = enrich_position_row_display(
|
||||
cfg,
|
||||
ex,
|
||||
p,
|
||||
meta_cache=meta_cache,
|
||||
premium_override=premium_override,
|
||||
)
|
||||
if budget_usdt is not None:
|
||||
row["budget_usdt"] = round(float(budget_usdt), 4)
|
||||
row["premium_entry_usdt"] = round(float(budget_usdt), 4)
|
||||
if include_close_preview:
|
||||
attach_close_preview(cfg, ex, row, premium_paid=_safe_float(row.get("premium_paid")))
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user