Fix false options close sync, restore bar layout, and show open premium in history.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-09 17:51:07 +08:00
parent 08a61fd4ae
commit 5a97e14f3e
6 changed files with 124 additions and 24 deletions
+53
View File
@@ -176,6 +176,8 @@ def sync_open_options_trades(
closed_at = datetime.fromtimestamp(int(exp_ms) / 1000, tz=timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
else:
continue
conn.execute(
"""
@@ -207,6 +209,57 @@ def sync_open_options_trades(
return updated
def reconcile_live_open_trades(
conn: sqlite3.Connection,
*,
live_inst_ids: set[str],
) -> int:
"""交易所有持仓但本地误标 closed 时恢复为 open."""
fixed = 0
for inst_id in live_inst_ids:
if not inst_id:
continue
open_row = conn.execute(
"SELECT id FROM options_trades WHERE inst_id = ? AND status = 'open' LIMIT 1",
(inst_id,),
).fetchone()
if open_row:
continue
row = conn.execute(
"""
SELECT id, close_ord_id, realized_pnl
FROM options_trades
WHERE inst_id = ? AND status = 'closed'
ORDER BY id DESC LIMIT 1
""",
(inst_id,),
).fetchone()
if not row:
continue
if row["close_ord_id"]:
continue
if row["realized_pnl"] is not None:
continue
conn.execute(
"""
UPDATE options_trades
SET status = 'open',
close_quote = NULL,
premium_received = NULL,
realized_pnl = NULL,
closed_at = NULL,
signal_note = CASE
WHEN signal_note = '到期结算' THEN NULL
ELSE signal_note
END
WHERE id = ?
""",
(int(row["id"]),),
)
fixed += 1
return fixed
def options_monitor_loop(
*,
enabled: bool,