Include options unrealized PnL in OKX instance header realtime PnL total.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 11:05:52 +08:00
parent 75a64c5d24
commit f68197b775
6 changed files with 102 additions and 2 deletions
+15
View File
@@ -110,3 +110,18 @@ def resolve_instance_unrealized_pnl(
if active_rows and get_metrics_fn:
return sum_unrealized_pnl_from_metrics(active_rows, get_metrics_fn)
return None
def merge_unrealized_pnl_components(*parts: float | None) -> float | None:
"""合并永续与期权等多路未实现盈亏(任一路有值即参与合计)。"""
total = 0.0
found = False
for part in parts:
if part is None:
continue
try:
total += float(part)
found = True
except (TypeError, ValueError):
continue
return round(total, 2) if found else None