Dashboard OKX card: 3-column perpetual/options split when options enabled.
Show perpetual and options funding metrics separately, total funds row, then positions; other exchanges keep the 2-column layout. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -38,6 +38,29 @@ def _account_capital_base(ac: dict) -> Optional[float]:
|
||||
return None
|
||||
|
||||
|
||||
def _options_layout_enabled(ac: dict) -> bool:
|
||||
if str(ac.get("key") or "").lower() != "okx":
|
||||
return False
|
||||
snap = ac.get("options_snapshot")
|
||||
if isinstance(snap, dict) and snap.get("enabled") is not False:
|
||||
return True
|
||||
return ac.get("options_funding_usdt") is not None or ac.get("options_trading_usdt") is not None
|
||||
|
||||
|
||||
def _perpetual_float_pnl_u(ac: dict) -> Optional[float]:
|
||||
try:
|
||||
total = float(ac.get("float_pnl_u") or 0)
|
||||
except (TypeError, ValueError):
|
||||
total = 0.0
|
||||
opt = ac.get("options_float_pnl_u")
|
||||
if opt is None:
|
||||
return round(total, 4)
|
||||
try:
|
||||
return round(total - float(opt), 4)
|
||||
except (TypeError, ValueError):
|
||||
return round(total, 4)
|
||||
|
||||
|
||||
def _enrich_account_row(ac: dict) -> dict:
|
||||
st = ac.get("trade_stats") or {}
|
||||
capital = _account_capital_base(ac)
|
||||
@@ -61,6 +84,8 @@ def _enrich_account_row(ac: dict) -> dict:
|
||||
"options_trading_usdt": ac.get("options_trading_usdt"),
|
||||
"options_float_pnl_u": ac.get("options_float_pnl_u"),
|
||||
"options_open_position_count": ac.get("options_open_position_count"),
|
||||
"options_layout": _options_layout_enabled(ac),
|
||||
"perpetual_float_pnl_u": _perpetual_float_pnl_u(ac),
|
||||
"capital_total_usdt": round(capital, 4) if capital is not None else None,
|
||||
"available_trading_usdt": ac.get("available_trading_usdt"),
|
||||
"pnl_u": st.get("total_pnl_u"),
|
||||
|
||||
Reference in New Issue
Block a user