fix实盘统计超时:先拉交易所/指数再短事务写冻结,避免握库锁拖死中控。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -284,13 +284,12 @@ def register_hub_bridge_routes(app: Flask, app_module: Any) -> None:
|
||||
cfg = hub_ctx.get("options_cfg")
|
||||
if not isinstance(cfg, dict):
|
||||
return jsonify({"ok": False, "msg": "期权未就绪", "version": 1}), 503
|
||||
from lib.options.options_db import init_options_tables
|
||||
from lib.options.options_margin_mode_lib import is_coin_margin_mode
|
||||
from lib.options.options_positions_lib import sum_options_net_pnl_usdc
|
||||
from lib.options.options_stats_lib import (
|
||||
apply_exchange_pnl_freeze,
|
||||
compute_options_stats_for_window,
|
||||
history_pnl_to_usdt,
|
||||
load_live_exchange_stats_history,
|
||||
load_local_options_stats_history,
|
||||
normalize_stats_window,
|
||||
)
|
||||
@@ -303,29 +302,26 @@ def register_hub_bridge_routes(app: Flask, app_module: Any) -> None:
|
||||
raw_live = cfg["fetch_option_positions"](ex)
|
||||
if raw_live is None:
|
||||
return jsonify({"ok": False, "msg": "获取期权持仓失败", "version": 1})
|
||||
# 模拟盘本地结算;实盘与期权历史同一交易所盈亏
|
||||
conn = cfg["get_db"]()
|
||||
use_sim = False
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
from lib.sim.mode_lib import is_sim_mode
|
||||
|
||||
use_sim = is_sim_mode(cfg["get_db"])
|
||||
except Exception:
|
||||
use_sim = False
|
||||
if use_sim:
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
from lib.sim.mode_lib import is_sim_mode
|
||||
|
||||
use_sim = is_sim_mode(cfg["get_db"])
|
||||
except Exception:
|
||||
use_sim = False
|
||||
if use_sim:
|
||||
history = load_local_options_stats_history(conn, ex)
|
||||
else:
|
||||
from lib.options.options_history_lib import load_options_history
|
||||
|
||||
history = apply_exchange_pnl_freeze(conn, load_options_history(ex, cfg), ex)
|
||||
try:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
conn.close()
|
||||
try:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
conn.close()
|
||||
else:
|
||||
# 实盘:先网后短事务,禁止握着 DB 锁拉行情(否则中控整机超时)
|
||||
history = load_live_exchange_stats_history(cfg, ex)
|
||||
stats = compute_options_stats_for_window(history_pnl_to_usdt(history, ex), window)
|
||||
open_float = sum_options_net_pnl_usdc(cfg, ex, raw_live)
|
||||
net_realized = stats.get("net_realized_pnl")
|
||||
|
||||
Reference in New Issue
Block a user