fix真盈亏收口为币本位×卖回价减初始权利金U,禁指数冒充平仓价。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -155,7 +155,7 @@ def repair(conn: sqlite3.Connection, *, apply: bool) -> list[dict[str, Any]]:
|
||||
"""
|
||||
SELECT id, inst_id, underlying, premium_paid, premium_received, realized_pnl,
|
||||
open_index_px, close_index_px, realized_pnl_usdt, bridge_id,
|
||||
created_at, closed_at, budget_usdt
|
||||
created_at, closed_at, budget_usdt, initial_premium_usdt
|
||||
FROM options_trades
|
||||
WHERE status='closed'
|
||||
ORDER BY id
|
||||
@@ -181,11 +181,16 @@ def repair(conn: sqlite3.Connection, *, apply: bool) -> list[dict[str, Any]]:
|
||||
old_open = _safe_float(r["open_index_px"])
|
||||
old_close = _safe_float(r["close_index_px"])
|
||||
old_u = _safe_float(r["realized_pnl_usdt"])
|
||||
use_open = open_px or old_open
|
||||
initial_u = _safe_float(r["initial_premium_usdt"])
|
||||
if initial_u is None and paid is not None and use_open is not None and use_open > 0:
|
||||
initial_u = round(float(paid) * float(use_open), 4)
|
||||
new_u = true_pnl_usdt_premium_move(
|
||||
coin_pnl=coin,
|
||||
premium_paid=paid,
|
||||
open_index_px=open_px or old_open,
|
||||
sell_back_px=close_px or old_close,
|
||||
initial_premium_usdt=initial_u,
|
||||
open_index_px=use_open,
|
||||
)
|
||||
item = {
|
||||
"id": tid,
|
||||
@@ -231,11 +236,7 @@ def repair(conn: sqlite3.Connection, *, apply: bool) -> list[dict[str, Any]]:
|
||||
SET open_index_px = COALESCE(?, open_index_px),
|
||||
close_index_px = COALESCE(?, close_index_px),
|
||||
realized_pnl_usdt = COALESCE(?, realized_pnl_usdt),
|
||||
initial_premium_usdt = CASE
|
||||
WHEN ? IS NOT NULL AND premium_paid IS NOT NULL
|
||||
THEN round(premium_paid * ?, 4)
|
||||
ELSE initial_premium_usdt
|
||||
END,
|
||||
initial_premium_usdt = COALESCE(?, initial_premium_usdt),
|
||||
pnl_settled = 1
|
||||
WHERE id = ?
|
||||
""",
|
||||
@@ -243,8 +244,7 @@ def repair(conn: sqlite3.Connection, *, apply: bool) -> list[dict[str, Any]]:
|
||||
open_px,
|
||||
close_px,
|
||||
new_u,
|
||||
open_px,
|
||||
open_px,
|
||||
initial_u,
|
||||
tid,
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user