Fix hub total floating PnL by excluding OKX options from swap agent.
Option legs were scored with linear swap math and then added again from the options snapshot, inflating 总浮盈亏 and 持有仓位. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -578,7 +578,14 @@ def _status_inner(x_control_token: str | None) -> Any:
|
||||
positions_out: list[dict[str, Any]] = []
|
||||
total_upnl = 0.0
|
||||
try:
|
||||
raw = ex.fetch_positions() or []
|
||||
# OKX 统一账户 fetch_positions 可能混入期权;优先只要永续,再二次过滤
|
||||
if EXCHANGE_KIND == "okx":
|
||||
try:
|
||||
raw = ex.fetch_positions(params={"instType": "SWAP"}) or []
|
||||
except Exception:
|
||||
raw = ex.fetch_positions() or []
|
||||
else:
|
||||
raw = ex.fetch_positions() or []
|
||||
except Exception as e:
|
||||
return JSONResponse(
|
||||
{
|
||||
@@ -592,9 +599,13 @@ def _status_inner(x_control_token: str | None) -> Any:
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
from lib.hub.hub_position_metrics import is_option_like_position
|
||||
|
||||
for p in raw:
|
||||
if not isinstance(p, dict):
|
||||
continue
|
||||
if is_option_like_position(p):
|
||||
continue
|
||||
c = _position_contracts(p)
|
||||
if abs(c) < 1e-12:
|
||||
continue
|
||||
@@ -807,13 +818,23 @@ def emergency_close_all(x_control_token: str | None = Header(default=None, alias
|
||||
closed: list[dict[str, Any]] = []
|
||||
|
||||
try:
|
||||
raw = ex.fetch_positions() or []
|
||||
if EXCHANGE_KIND == "okx":
|
||||
try:
|
||||
raw = ex.fetch_positions(params={"instType": "SWAP"}) or []
|
||||
except Exception:
|
||||
raw = ex.fetch_positions() or []
|
||||
else:
|
||||
raw = ex.fetch_positions() or []
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=502, detail=f"fetch_positions: {e}") from e
|
||||
|
||||
from lib.hub.hub_position_metrics import is_option_like_position
|
||||
|
||||
for p in raw:
|
||||
if not isinstance(p, dict):
|
||||
continue
|
||||
if is_option_like_position(p):
|
||||
continue
|
||||
c = _position_contracts(p)
|
||||
if abs(c) < 1e-12:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user