统计已实现盈亏扣手续费,并按平仓时指数冻结为 U。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-08 22:50:21 +08:00
parent e8f8a76753
commit 5e8b578f75
12 changed files with 726 additions and 54 deletions
+44 -1
View File
@@ -424,6 +424,41 @@ def open_coin_option_buy_full(
premium_paid = round(float(ask) * eth_amount, 8)
premium_ccy = premium_ccy_for_mode("coin", underlying)
# 开仓手续费(折权利金单位);优先成交回包,否则查单
open_fee = 0.0
try:
from lib.options.options_pnl_settle_lib import (
extract_order_fee,
fee_to_premium_ccy,
resolve_close_index_px,
sum_option_order_fees_in_premium,
)
idx_open = resolve_close_index_px(
ex,
inst_id=inst_id,
underlying=underlying,
hint=(q.get("index_px") if isinstance(q, dict) else None),
)
fee_hint, fee_ccy_hint = extract_order_fee(order if isinstance(order, dict) else None)
if fee_hint <= 0 and isinstance(fill, dict):
fee_hint, fee_ccy_hint = extract_order_fee(fill.get("order") if isinstance(fill.get("order"), dict) else fill)
if fee_hint > 0:
open_fee = fee_to_premium_ccy(
fee_hint, fee_ccy_hint or premium_ccy, premium_ccy=premium_ccy, index_px=idx_open
)
if open_fee <= 0:
open_fee = sum_option_order_fees_in_premium(
ex,
inst_id=inst_id,
ord_ids=[ord_id],
premium_ccy=premium_ccy,
index_px=idx_open,
fetch_order_fn=cfg.get("fetch_option_order"),
)
except Exception:
open_fee = 0.0
# 部分成交/减半张数后卖掉多余买币(按 bridge coin_bought 封顶)
need_coin = float(premium_paid)
try:
@@ -464,6 +499,7 @@ def open_coin_option_buy_full(
bridge_id=bridge_id,
budget_usdt=buy_usdt,
premium_ccy=premium_ccy,
open_fee=open_fee,
profit_exit_enabled=profit_exit_enabled,
profit_exit_mult=profit_exit_mult,
)
@@ -533,14 +569,19 @@ def _insert_coin_trade(conn: Any, **kwargs: Any) -> int:
pe = 1 if kwargs.get("profit_exit_enabled") else 0
pe_mult = float(kwargs.get("profit_exit_mult") or 1.0)
pe_state = "active" if pe else "idle"
open_fee = float(kwargs.get("open_fee") or 0.0)
if open_fee < 0:
open_fee = abs(open_fee)
fee_ccy = str(kwargs.get("premium_ccy") or "ETH")
cur = conn.execute(
"""
INSERT INTO options_trades(
inst_id, underlying, opt_type, strike, exp_time, sheets, eth_amount,
open_quote, premium_paid, status, signal_note, exchange_ord_id,
margin_mode, premium_ccy, bridge_id, budget_usdt,
open_fee, fee_ccy,
profit_exit_enabled, profit_exit_mult, profit_exit_state, created_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'open', ?, ?, 'coin', ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'open', ?, ?, 'coin', ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
kwargs["inst_id"],
@@ -557,6 +598,8 @@ def _insert_coin_trade(conn: Any, **kwargs: Any) -> int:
kwargs.get("premium_ccy") or "ETH",
kwargs.get("bridge_id"),
kwargs.get("budget_usdt"),
open_fee,
fee_ccy,
pe,
pe_mult,
pe_state,