Align hedge UI/fees: drop 未启动, premium coin/U, equity incl perp margin, OKX option fees.

Option net uses Min(0.03%×coin, 7%×premium) with bid/ask fills (no slip); live PnL colors fixed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 17:12:10 +08:00
parent be00991568
commit 746655acba
12 changed files with 190 additions and 45 deletions
+17 -4
View File
@@ -7,7 +7,7 @@ import uuid
from datetime import datetime
from typing import Any, Callable
from lib.sim.pricing_lib import option_fill, perp_fill, sim_fee_rate
from lib.sim.pricing_lib import option_fill, perp_fill, sim_fee_rate, sim_option_fee_rate
from lib.sim.wallets_lib import InsufficientFunds, SimWallets
@@ -109,7 +109,20 @@ class SimBroker:
self.wallets = SimWallets(get_db)
def balances_header(self) -> dict[str, float]:
return self.wallets.view()
"""资金快照.trading_usdt=全仓权益(可用+永续占用保证金);trading_usdt_free=可开仓余额."""
w = dict(self.wallets.view())
free = float(w.get("trading_usdt") or 0)
margin = 0.0
try:
for p in self.list_perp_positions():
margin += float(p.get("margin_usdt") or 0)
except Exception:
margin = 0.0
w["trading_usdt_free"] = free
w["perp_margin_usdt"] = margin
# 永续全仓:展示权益含占用保证金;期权逐仓权利金在币余额,不并入 USDT
w["trading_usdt"] = round(free + margin, 8)
return w
def list_perp_positions(self) -> list[dict[str, Any]]:
conn = self.get_db()
@@ -431,7 +444,7 @@ class SimBroker:
n = int(sheets)
if n < 1:
return {"ok": False, "msg": "张数至少为 1"}
fr = sim_fee_rate(fee_rate)
fr = sim_option_fee_rate(fee_rate)
bid, ask, ct_mult = _option_bid_ask(exchange_options, inst_id)
if price is not None and float(price) > 0:
# 限价: 用 min(limit, ask) 作为基准卖一近似, 仍走 option_fill 滑点
@@ -540,7 +553,7 @@ class SimBroker:
close_n = min(pos_s, float(n))
if close_n <= 0:
return {"ok": False, "msg": "平仓张数无效"}
fr = sim_fee_rate(fee_rate)
fr = sim_option_fee_rate(fee_rate)
qty = close_n * ct_mult
pr = option_fill(action="close", bid=bid, ask=ask, qty=qty, fee_rate=fr)
credit = pr.notional - pr.fee