修复期权开平仓时间按 UTC 入库导致复盘K线标记偏8小时:统一业务时区并一次性迁移。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-09-15 11:20:39 +08:00
parent 0132ca4ca1
commit 72ad8ea7dc
8 changed files with 245 additions and 40 deletions
+8 -4
View File
@@ -1218,6 +1218,7 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
try:
init_options_tables(conn)
from lib.options.options_profit_exit_lib import ensure_profit_exit_columns
from lib.options.options_time_lib import options_app_now_str
ensure_profit_exit_columns(conn)
meta = q.get("meta") or {}
@@ -1230,8 +1231,8 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
INSERT INTO options_trades
(inst_id, underlying, opt_type, strike, exp_time, sheets, eth_amount,
open_quote, premium_paid, status, signal_note, exchange_ord_id,
profit_exit_enabled, profit_exit_mult, profit_exit_state)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'open', ?, ?, ?, ?, ?)
profit_exit_enabled, profit_exit_mult, profit_exit_state, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'open', ?, ?, ?, ?, ?, ?)
""",
(
inst_id,
@@ -1248,6 +1249,7 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
1 if profit_exit_enabled else 0,
profit_exit_mult if profit_exit_enabled else 1.0,
"active" if profit_exit_enabled else "idle",
options_app_now_str(),
),
)
trade_id = int(cur.lastrowid)
@@ -1348,6 +1350,8 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
conn = cfg["get_db"]()
try:
init_options_tables(conn)
from lib.options.options_time_lib import options_app_now_str
conn.execute(
"""
UPDATE options_trades
@@ -1356,10 +1360,10 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
WHEN signal_note IS NULL OR TRIM(signal_note) = '' THEN '委托撤销'
ELSE signal_note
END,
closed_at = CURRENT_TIMESTAMP
closed_at = ?
WHERE inst_id = ? AND exchange_ord_id = ? AND status = 'open'
""",
(inst_id, ord_id),
(options_app_now_str(), inst_id, ord_id),
)
conn.commit()
finally: