feat期权盈亏按交易账户快照结算:一次一仓、持仓禁划转、卖回后冻结。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-09 00:29:47 +08:00
parent e0e2a94322
commit 260bfd1f29
12 changed files with 659 additions and 157 deletions
+4 -2
View File
@@ -379,7 +379,7 @@ def close_option_by_bid1(
"""
SELECT id, premium_paid, open_fee, premium_ccy, underlying,
exchange_ord_id, budget_usdt, open_index_px, fee_ccy,
eth_amount, open_quote
eth_amount, open_quote, trading_usdt_before
FROM options_trades
WHERE inst_id = ? AND status = 'open'
ORDER BY id ASC
@@ -510,7 +510,9 @@ def close_option_by_bid1(
fee_ccy=str(row["fee_ccy"] or row["premium_ccy"] or row_ccy or ""),
)
pnl = settled.get("realized_pnl")
pnl_usdt = settled.get("realized_pnl_usdt")
# 有交易账户 before 快照:U 盈亏等卖回后结算,平仓不写 realized_pnl_usdt
has_acct_snap = _safe_float(row["trading_usdt_before"]) is not None
pnl_usdt = None if has_acct_snap else settled.get("realized_pnl_usdt")
note_sql = ""
# 占位: close_quote/recv/pnl/ord/closed_at/open_fee/close_fee/fee_ccy/close_idx/open_idx/pnl_u/[note]/id