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:
@@ -45,7 +45,54 @@ def test_sync_open_options_trades_marks_expired_closed():
|
||||
assert "到期结算" in (row["signal_note"] or "")
|
||||
|
||||
|
||||
def test_sync_open_options_trades_uses_exchange_history():
|
||||
def test_sync_open_options_trades_skips_without_close_evidence():
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.row_factory = sqlite3.Row
|
||||
init_options_tables(conn)
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO options_trades
|
||||
(inst_id, underlying, opt_type, strike, exp_time, sheets, eth_amount,
|
||||
open_quote, premium_paid, status, created_at)
|
||||
VALUES (?, 'BTC', 'P', 62000, '', 1, 0.01, 380.0, 3.8, 'open', '2026-07-09 08:00:00')
|
||||
""",
|
||||
("BTC-USD_UM-260710-62000-P",),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
n = sync_open_options_trades(
|
||||
conn,
|
||||
live_inst_ids=set(),
|
||||
fetch_history_fn=lambda _inst: [],
|
||||
)
|
||||
assert n == 0
|
||||
row = conn.execute("SELECT status FROM options_trades").fetchone()
|
||||
assert row["status"] == "open"
|
||||
|
||||
|
||||
def test_reconcile_live_open_trades_reopens_sync_artifact():
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.row_factory = sqlite3.Row
|
||||
init_options_tables(conn)
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO options_trades
|
||||
(inst_id, underlying, opt_type, strike, exp_time, sheets, eth_amount,
|
||||
open_quote, premium_paid, status, closed_at)
|
||||
VALUES (?, 'BTC', 'P', 62000, '', 1, 0.01, 380.0, 3.8, 'closed', '2026-07-09 09:10:34')
|
||||
""",
|
||||
("BTC-USD_UM-260710-62000-P",),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
from lib.options.options_monitor_lib import reconcile_live_open_trades
|
||||
|
||||
n = reconcile_live_open_trades(conn, live_inst_ids={"BTC-USD_UM-260710-62000-P"})
|
||||
assert n == 1
|
||||
row = conn.execute("SELECT status, closed_at FROM options_trades").fetchone()
|
||||
assert row["status"] == "open"
|
||||
assert row["closed_at"] is None
|
||||
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.row_factory = sqlite3.Row
|
||||
init_options_tables(conn)
|
||||
|
||||
Reference in New Issue
Block a user