币本位数据统计改为U展示,已平盈亏按指数折U与浮盈口径一致。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-21 06:46:11 +08:00
parent d60c6ad710
commit fc24114142
3 changed files with 117 additions and 13 deletions
+10 -2
View File
@@ -1828,14 +1828,19 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
if ex is None:
return jsonify({"ok": False, "msg": err})
from lib.options.options_history_lib import load_options_history
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 compute_options_stats_from_history
from lib.options.options_stats_lib import (
compute_options_stats_from_history,
history_pnl_to_usdt,
)
raw_live = cfg["fetch_option_positions"](ex)
if raw_live is None:
return jsonify({"ok": False, "msg": "获取期权持仓失败"})
history = load_options_history(ex, cfg)
stats = compute_options_stats_from_history(history)
# 币本位已平盈亏按指数折 U,与持仓浮盈/合计口径一致
stats = compute_options_stats_from_history(history_pnl_to_usdt(history, ex))
open_float = sum_options_net_pnl_usdc(cfg, ex, raw_live)
net_realized = _safe_float(stats.get("net_realized_pnl")) or 0.0
total_pnl = None
@@ -1843,12 +1848,15 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
total_pnl = round(net_realized + float(open_float), 4)
elif stats.get("total_closed"):
total_pnl = round(net_realized, 4)
# 币本位统计统一标 U;USDC 模式仍标 USDC
pnl_unit = "U" if is_coin_margin_mode() else "USDC"
return jsonify(
{
"ok": True,
**stats,
"open_float_pnl": open_float,
"total_pnl": total_pnl,
"pnl_unit": pnl_unit,
}
)