1
This commit is contained in:
parent
9f799b04f6
commit
ce7a203f3d
@ -72,6 +72,17 @@ def _display_symbol(symbol: str) -> str:
|
||||
return value
|
||||
|
||||
|
||||
def _safe_bool(value) -> bool:
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if value is None:
|
||||
return False
|
||||
if isinstance(value, (int, float)):
|
||||
return value != 0
|
||||
text = str(value).strip().lower()
|
||||
return text in {"1", "true", "yes", "y", "on"}
|
||||
|
||||
|
||||
def _compact_position(item: dict, account: dict | None = None) -> dict:
|
||||
info = item.get("info") if isinstance(item.get("info"), dict) else {}
|
||||
contracts = _safe_float(item.get("contracts") or info.get("positionAmt"))
|
||||
@ -128,7 +139,7 @@ def _compact_order(item: dict) -> dict:
|
||||
"filled": _safe_float(item.get("filled") or info.get("executedQty")),
|
||||
"average": _safe_float(item.get("average") or info.get("avgPrice")),
|
||||
"realized_pnl": _safe_float(item.get("realizedPnl") or info.get("realizedPnl") or info.get("realizedProfit")),
|
||||
"reduce_only": bool(item.get("reduceOnly") or info.get("reduceOnly")),
|
||||
"reduce_only": _safe_bool(item.get("reduceOnly") if item.get("reduceOnly") is not None else info.get("reduceOnly")),
|
||||
"position_side": item.get("positionSide") or info.get("positionSide") or "",
|
||||
"timestamp": item.get("datetime") or item.get("timestamp") or info.get("updateTime") or info.get("time"),
|
||||
}
|
||||
@ -337,7 +348,7 @@ def _historical_positions_from_orders(orders: list[dict]) -> list[dict]:
|
||||
amount = _order_amount(order)
|
||||
price = _order_price(order)
|
||||
pnl = _safe_float(order.get("realized_pnl"))
|
||||
reduce_only = bool(order.get("reduce_only"))
|
||||
reduce_only = _safe_bool(order.get("reduce_only"))
|
||||
is_close = reduce_only or abs(pnl) > 0
|
||||
direction = _order_direction(order, closing=is_close)
|
||||
if not direction:
|
||||
|
||||
@ -318,7 +318,7 @@ def test_live_account_overview_normalizes_futures_symbols_and_pairs_closed_posit
|
||||
"average": 0.1,
|
||||
"filled": 100,
|
||||
"datetime": "2026-06-07T08:00:00",
|
||||
"info": {"reduceOnly": False},
|
||||
"info": {"reduceOnly": "false"},
|
||||
},
|
||||
{
|
||||
"id": "exit-1",
|
||||
@ -329,7 +329,7 @@ def test_live_account_overview_normalizes_futures_symbols_and_pairs_closed_posit
|
||||
"average": 0.12,
|
||||
"filled": 100,
|
||||
"datetime": "2026-06-07T09:00:00",
|
||||
"info": {"reduceOnly": True, "realizedPnl": "2"},
|
||||
"info": {"reduceOnly": "true", "realizedPnl": "2"},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user