Fix option history to full closes only, 2-decimal USDC, restore hide-delete.

Filter OKX positions-history to type 2/3/6, format premium and bid recovery to 2 decimals, and allow locally hiding rows via delete button.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-11 09:24:24 +08:00
parent fdea5bb610
commit bf2d668d3c
7 changed files with 130 additions and 20 deletions
+8
View File
@@ -46,6 +46,14 @@ def init_options_tables(conn: sqlite3.Connection) -> None:
)
"""
)
conn.execute(
"""
CREATE TABLE IF NOT EXISTS options_history_hidden (
history_key TEXT PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
"""
)
conn.execute(
"""
CREATE TABLE IF NOT EXISTS options_transfer_log (
+32 -4
View File
@@ -915,6 +915,17 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
finally:
conn.close()
hidden_keys: set[str] = set()
conn = cfg["get_db"]()
try:
init_options_tables(conn)
hidden_keys = {
str(r["history_key"])
for r in conn.execute("SELECT history_key FROM options_history_hidden").fetchall()
}
finally:
conn.close()
hist_raw = fetch_all_option_positions_history(ex, limit=200)
for raw in hist_raw:
inst_id = str(raw.get("instId") or "").strip()
@@ -925,7 +936,11 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
closed = [x for x in items if x.get("status") != "open"]
closed.sort(key=lambda x: int(x.get("close_ms") or 0), reverse=True)
open_rows.sort(key=lambda x: int(x.get("close_ms") or 0), reverse=True)
history = open_rows + closed
history = [
x
for x in (open_rows + closed)
if str(x.get("history_key") or "") not in hidden_keys
]
live_ids = {str(x.get("inst_id") or "") for x in open_rows}
return jsonify({"ok": True, "history": history, "live_inst_ids": sorted(live_ids)})
@@ -939,13 +954,26 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
return jsonify({"ok": True, **compute_options_stats(cfg["get_db"])})
@app.route("/api/options/history/<path:trade_id>", methods=["DELETE"])
@app.route("/api/options/history/<path:history_key>", methods=["DELETE"])
@lr
def api_options_history_delete(trade_id: str):
def api_options_history_delete(history_key: str):
ex, err = _require_options_ex(cfg)
if ex is None:
return jsonify({"ok": False, "msg": err})
return jsonify({"ok": False, "msg": "历史仓位来自交易所,不支持本地删除"})
key = (history_key or "").strip()
if not key:
return jsonify({"ok": False, "msg": "缺少 history_key"})
conn = cfg["get_db"]()
try:
init_options_tables(conn)
conn.execute(
"INSERT OR IGNORE INTO options_history_hidden (history_key) VALUES (?)",
(key,),
)
conn.commit()
finally:
conn.close()
return jsonify({"ok": True})
def _start_monitor_thread(app: Flask, cfg: dict[str, Any]) -> None:
+3 -2
View File
@@ -198,10 +198,11 @@
<th>状态</th>
<th>盈亏</th>
<th>时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="opt-history-tbody">
<tr><td colspan="6" class="muted">加载中…</td></tr>
<tr><td colspan="7" class="muted">加载中…</td></tr>
</tbody>
</table>
</div>
@@ -211,4 +212,4 @@
</div>
</div>
<script src="/static/options_expiry_countdown.js?v=1"></script>
<script src="/static/options_panel.js?v=24"></script>
<script src="/static/options_panel.js?v=25"></script>