Add trade move points; label option UPL price as bid not mark.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-31 15:44:52 +08:00
parent 8ceb521049
commit dffcd77837
5 changed files with 72 additions and 5 deletions
+43
View File
@@ -61,6 +61,46 @@ def _expiry_settle_info(g: dict, fills: list) -> dict | None:
}
def _close_index_px(g: dict, fills: list) -> float | None:
"""平仓时标的指数:优先 settle_index_px,否则用永续平仓价近似。"""
raw = g.get("settle_index_px")
if raw is not None:
try:
v = float(raw)
if v > 0:
return v
except (TypeError, ValueError):
pass
for row in fills:
f = dict(row) if not isinstance(row, dict) else row
if str(f.get("leg") or "") == "perp" and str(f.get("action") or "") == "close":
try:
v = float(f.get("fill_px") or 0)
if v > 0:
return v
except (TypeError, ValueError):
pass
break
return None
def _move_points(g: dict, fills: list) -> float | None:
"""开仓指数 → 平仓指数的点数(带符号:上涨为正)。持仓中无平仓价则空。"""
entry = g.get("entry_index_px")
if entry is None:
return None
try:
e = float(entry)
except (TypeError, ValueError):
return None
if e <= 0:
return None
close_px = _close_index_px(g, fills)
if close_px is None:
return None
return round(float(close_px) - e, 2)
def _enrich_group(g: dict, fills: list) -> dict:
summary = summarize_fills_pnl(fills)
# LIVE:优先 groups.realized_pnl(已按交易所回写,含资金费)
@@ -81,6 +121,9 @@ def _enrich_group(g: dict, fills: list) -> dict:
g["expiry_settle"] = info
if g.get("settle_index_px") is None and info.get("settle_index_px") is not None:
g["settle_index_px"] = info["settle_index_px"]
mp = _move_points(g, fills)
g["move_points"] = mp
g["close_index_px"] = _close_index_px(g, fills)
return g