Add OKX options expiry and close breakeven to hub monitor and dashboard.

Expose bePx-based expiry balance and mark-to-close breakeven on positions so monitor and dashboard can show both labels per contract.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-07 16:10:03 +08:00
parent 7bbb5663c9
commit 3570a6900e
8 changed files with 269 additions and 9 deletions
+32 -2
View File
@@ -666,23 +666,53 @@ def transfer_main_sub_account(
def format_position_row(pos: dict[str, Any], ct_mult: float = 0.01) -> dict[str, Any]:
from lib.options.options_pricing_lib import (
close_breakeven_idx,
expiry_breakeven_px,
idx_distance_to_be,
)
sheets = _safe_float(pos.get("pos")) or 0.0
avg = _safe_float(pos.get("avgPx"))
mark = _safe_float(pos.get("markPx"))
upl = _safe_float(pos.get("upl"))
upl_ratio = _safe_float(pos.get("uplRatio"))
idx_px = _safe_float(pos.get("idxPx"))
opt_type = pos.get("optType")
strike = _safe_float(pos.get("stk"))
delta_pa = _safe_float(pos.get("deltaPA"))
expiry_be = expiry_breakeven_px(
opt_type=str(opt_type or ""),
strike=strike,
avg_px=avg,
be_px_api=_safe_float(pos.get("bePx")),
)
close_be = close_breakeven_idx(
opt_type=str(opt_type or ""),
idx_px=idx_px,
mark_px=mark,
avg_px=avg,
delta_pa=delta_pa,
pos=sheets,
ct_mult=ct_mult,
)
return {
"inst_id": pos.get("instId"),
"pos": sheets,
"eth_amount": round(abs(sheets) * ct_mult, 8),
"avg_px": avg,
"mark_px": mark,
"idx_px": idx_px,
"upl": upl,
"upl_ratio_pct": round(upl_ratio * 100, 2) if upl_ratio is not None else None,
"exp_time": pos.get("expTime"),
"opt_type": pos.get("optType"),
"strike": _safe_float(pos.get("stk")),
"opt_type": opt_type,
"strike": strike,
"avail_pos": _safe_float(pos.get("availPos")),
"expiry_be_px": expiry_be,
"close_be_px": close_be,
"dist_expiry_be": idx_distance_to_be(idx_px, expiry_be),
"dist_close_be": idx_distance_to_be(idx_px, close_be),
"raw": pos,
}