fix: OKX 持仓张数优先读 info.pos,滚仓后同步 order_amount
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -24,23 +24,26 @@ def _coerce_float(*values: Any) -> float | None:
|
||||
|
||||
|
||||
def position_contracts(p: dict[str, Any]) -> float:
|
||||
raw = p.get("contracts")
|
||||
if raw is not None:
|
||||
try:
|
||||
return float(raw)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
info = p.get("info") or {}
|
||||
if not isinstance(info, dict):
|
||||
info = {}
|
||||
for k in ("positionAmt", "positionamt", "pos", "size"):
|
||||
# OKX 等:info.pos 为交易所张数,优先于 ccxt contracts(加仓后后者可能滞后)
|
||||
for k in ("pos", "positionAmt", "positionamt", "size"):
|
||||
if k in info:
|
||||
try:
|
||||
v = float(info[k])
|
||||
if v != 0:
|
||||
return v
|
||||
return abs(v)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
raw = p.get("contracts")
|
||||
if raw is not None:
|
||||
try:
|
||||
v = float(raw)
|
||||
if v != 0:
|
||||
return abs(v)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return 0.0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user