fix模拟盘盈亏:收回×卖回价 − 开仓U权利金 − 手续费,历史按U展示。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+17
-5
@@ -1220,10 +1220,17 @@ class SimBroker:
|
||||
conn = self.get_db()
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
try:
|
||||
from lib.options.options_stats_lib import sync_sim_cash_realized_pnl_usdt
|
||||
|
||||
sync_sim_cash_realized_pnl_usdt(conn, exchange)
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
sql = """
|
||||
SELECT id, inst_id, underlying, sheets, open_quote, close_quote,
|
||||
premium_paid, premium_received, realized_pnl, premium_ccy,
|
||||
created_at, closed_at
|
||||
premium_paid, premium_received, realized_pnl, realized_pnl_usdt,
|
||||
premium_ccy, created_at, closed_at
|
||||
FROM options_trades
|
||||
WHERE status = 'closed'
|
||||
"""
|
||||
@@ -1250,6 +1257,7 @@ class SimBroker:
|
||||
paid = float(r["premium_paid"] or 0) if r["premium_paid"] is not None else None
|
||||
recv = float(r["premium_received"] or 0) if r["premium_received"] is not None else None
|
||||
pnl = float(r["realized_pnl"]) if r["realized_pnl"] is not None else None
|
||||
pnl_usdt = float(r["realized_pnl_usdt"]) if r["realized_pnl_usdt"] is not None else None
|
||||
if pnl is None and paid is not None and recv is not None:
|
||||
pnl = round(recv - paid, 8)
|
||||
if pnl is None:
|
||||
@@ -1283,16 +1291,20 @@ class SimBroker:
|
||||
"closeAvgPx": str(close_px) if close_px is not None else "",
|
||||
"closeTotalPos": str(sheets),
|
||||
"openMaxPos": str(sheets),
|
||||
"realizedPnl": str(round(pnl, 8)),
|
||||
"pnl": str(round(pnl, 8)),
|
||||
# 展示用 U 盈亏;币数量仍放 raw 供对账
|
||||
"realizedPnl": str(round(pnl_usdt, 4)) if pnl_usdt is not None else str(round(pnl, 8)),
|
||||
"pnl": str(round(pnl_usdt, 4)) if pnl_usdt is not None else str(round(pnl, 8)),
|
||||
"pnlRatio": str(round(pnl_ratio, 8)) if pnl_ratio is not None else "",
|
||||
"cTime": str(open_ms or ""),
|
||||
"uTime": str(close_ms or ""),
|
||||
"type": "2",
|
||||
"optType": opt_type or "",
|
||||
"stk": str(strike) if strike is not None else "",
|
||||
"_sim_premium_ccy": ccy,
|
||||
"_sim_premium_paid": paid,
|
||||
"_sim_premium_ccy": ccy,
|
||||
"_sim_realized_pnl_coin": pnl,
|
||||
"_sim_realized_pnl_usdt": pnl_usdt,
|
||||
"_sim_pnl_display_ccy": "USDT" if pnl_usdt is not None else ccy,
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user