Persist options review deletes across local resync.

Hide deleted rows by history key and contract/close fingerprint so local options_trades imports no longer resurrect them.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 10:03:00 +08:00
parent 48afc8ebe3
commit d7272c9722
9 changed files with 339 additions and 14 deletions
+56
View File
@@ -1096,6 +1096,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
key = (history_key or "").strip()
if not key:
return jsonify({"ok": False, "msg": "缺少 history_key"})
data = request.get_json(silent=True) or {}
inst_id = str(data.get("inst_id") or request.args.get("inst_id") or "").strip() or None
closed_at = str(data.get("closed_at") or request.args.get("closed_at") or "").strip() or None
conn = cfg["get_db"]()
try:
init_options_tables(conn)
@@ -1103,6 +1106,59 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
"INSERT OR IGNORE INTO options_history_hidden (history_key) VALUES (?)",
(key,),
)
# 同步隐藏期权复盘,避免本地已平记录刷新后又出现
try:
from lib.options.options_review_lib import hide_review_keys
hide_review_keys(
conn,
history_key=key,
inst_id=inst_id,
closed_at=closed_at,
)
if inst_id:
# 去掉已导入的复盘快照(按合约+平仓时间)
if closed_at:
rows = conn.execute(
"""
SELECT id, history_key FROM options_review_trades
WHERE inst_id = ?
AND substr(COALESCE(closed_at,''),1,16) = substr(?,1,16)
""",
(inst_id, closed_at),
).fetchall()
else:
rows = conn.execute(
"""
SELECT id, history_key FROM options_review_trades
WHERE inst_id = ?
""",
(inst_id,),
).fetchall()
for r in rows:
conn.execute(
"DELETE FROM options_review_entries WHERE trade_id=?",
(int(r["id"]),),
)
conn.execute(
"DELETE FROM options_review_trades WHERE id=?",
(int(r["id"]),),
)
conn.execute(
"INSERT OR IGNORE INTO options_review_hidden(history_key, inst_id, closed_at) VALUES (?,?,?)",
(str(r["history_key"]), inst_id, (closed_at or "")[:19] or None),
)
fps = []
if closed_at:
fps.append(f"inst_close:{inst_id}:{closed_at[:16]}")
fps.append(f"inst:{inst_id}")
for fp in fps:
conn.execute(
"INSERT OR IGNORE INTO options_review_hidden(history_key, inst_id, closed_at) VALUES (?,?,?)",
(fp, inst_id, (closed_at or "")[:19] or None),
)
except Exception:
pass
conn.commit()
finally:
conn.close()