fix复盘交易记录改回真盈亏A,期权历史仅记期权腿不含现货。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -555,9 +555,16 @@ def sync_options_from_local_trades(
|
||||
ccy = str(r["premium_ccy"] or "").strip().upper()
|
||||
if not ccy:
|
||||
ccy = premium_ccy_for_mode(margin_mode_from_inst_id(inst), underly)
|
||||
frozen_usdt = _safe_float(r["realized_pnl_usdt"])
|
||||
try:
|
||||
settled = int(r["pnl_settled"] or 0) == 1
|
||||
except Exception:
|
||||
settled = False
|
||||
# 有账户快照未结算:交易记录显示待结算(真盈亏=卖回后 after−before)
|
||||
acct_pending = _safe_float(r["trading_usdt_before"]) is not None and not settled
|
||||
close_idx = _safe_float(r["close_index_px"])
|
||||
open_idx = _safe_float(r["open_index_px"])
|
||||
# 折算指数:平仓卖回价 > 开仓 > 实时(仅无冻结时兜底)
|
||||
# 折算指数:仅用于初始权利金/期权手续费展示,不用于真盈亏
|
||||
idx = None
|
||||
if close_idx is not None and close_idx > 0:
|
||||
idx = close_idx
|
||||
@@ -565,23 +572,21 @@ def sync_options_from_local_trades(
|
||||
idx = open_idx
|
||||
else:
|
||||
idx = idx_cache.get(underly)
|
||||
pnl = _safe_float(r["realized_pnl"])
|
||||
if pnl is None:
|
||||
paid0 = _safe_float(r["premium_paid"])
|
||||
recv0 = _safe_float(r["premium_received"])
|
||||
if paid0 is not None and recv0 is not None:
|
||||
pnl = recv0 - paid0
|
||||
prem = _safe_float(r["premium_paid"])
|
||||
# 期权交易记录盈亏与数据统计同口径 B:币盈亏 × 平仓卖回价(不用账户差分 A)
|
||||
pnl_u = _to_usdt(pnl, ccy=ccy, idx=idx)
|
||||
# 交易记录真盈亏=口径 A(卖光币后账户差分);未结算不写假 U
|
||||
if acct_pending:
|
||||
pnl_u = None
|
||||
elif frozen_usdt is not None and (settled or _safe_float(r["trading_usdt_before"]) is None):
|
||||
pnl_u = round(float(frozen_usdt), 4)
|
||||
else:
|
||||
# 旧单无账户快照:不回退币×价冒充真盈亏
|
||||
pnl_u = None
|
||||
# 初始权利金(U)=开仓指数×权利金币量;不含多买
|
||||
stored_initial = _safe_float(r["initial_premium_usdt"])
|
||||
open_idx_for_prem = open_idx if (open_idx is not None and open_idx > 0) else idx
|
||||
prem_u = stored_initial
|
||||
if prem_u is None:
|
||||
prem_u = _to_usdt(prem, ccy=ccy, idx=open_idx_for_prem)
|
||||
if ccy in ("ETH", "BTC") and pnl_u is None:
|
||||
pnl_u = None
|
||||
if ccy in ("ETH", "BTC") and prem_u is None:
|
||||
prem_u = prem
|
||||
# 仅期权开/平手续费折 U(不含现货)
|
||||
@@ -635,7 +640,7 @@ def sync_options_from_local_trades(
|
||||
"option_fee_usdt": fee_u,
|
||||
"created_at": opened_at,
|
||||
"closed_at": closed_at,
|
||||
"status_label": "已平",
|
||||
"status_label": "待结算" if acct_pending else "已平",
|
||||
},
|
||||
)
|
||||
if action == "inserted":
|
||||
|
||||
@@ -345,7 +345,7 @@
|
||||
<th>张数</th>
|
||||
<th>权利金</th>
|
||||
<th>状态</th>
|
||||
<th>盈亏</th>
|
||||
<th title="仅期权腿币收益,不含现货买/卖回">盈亏</th>
|
||||
<th>时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
|
||||
@@ -229,7 +229,7 @@
|
||||
<span class="or-step" aria-hidden="true">1</span>
|
||||
<div>
|
||||
<div class="or-section-title" id="or-list-title">期权交易记录</div>
|
||||
<p class="or-section-desc">点「复盘」填写表单;已复盘仍保留在此,也可在下方查看详情。</p>
|
||||
<p class="or-section-desc">盈亏为卖光币后的账户真盈亏;点「复盘」填写表单。期权历史仅记期权腿币收益,不含现货。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="options-strike-table-wrap or-trades-table-wrap" id="or-trades-wrap">
|
||||
@@ -239,9 +239,9 @@
|
||||
<th>类型</th>
|
||||
<th>标的/合约</th>
|
||||
<th>初始权利金</th>
|
||||
<th>盈亏</th>
|
||||
<th title="卖回完成后交易账户 USDT 差分">真盈亏</th>
|
||||
<th>盈利率</th>
|
||||
<th>手续费</th>
|
||||
<th title="仅期权开/平手续费">手续费</th>
|
||||
<th>开仓时间</th>
|
||||
<th>平仓时间</th>
|
||||
<th>持有</th>
|
||||
|
||||
Reference in New Issue
Block a user