Mirror option expiry settlements from exchange bills; debit OO LIVE open premiums.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -394,6 +394,42 @@ class OkxTradeClient:
|
||||
total += to_usdt(float(raw), ccy)
|
||||
return total
|
||||
|
||||
def get_option_settlement_bills(
|
||||
self, inst_id: str, *, begin_ms: int, end_ms: int | None = None
|
||||
) -> list[dict] | None:
|
||||
"""期权交割/行权相关账单(近 7 日 bills;失败再试 archive)。"""
|
||||
end = int(end_ms or int(time.time() * 1000))
|
||||
begin = int(begin_ms)
|
||||
# type=3 Delivery;再本地按 subType 170/171/172 过滤
|
||||
path = (
|
||||
f"/api/v5/account/bills?instType=OPTION&instId={inst_id}"
|
||||
f"&type=3&begin={begin}&end={end}"
|
||||
)
|
||||
try:
|
||||
rows = self._request("GET", path)
|
||||
except Exception as e:
|
||||
logger.warning("okx option bills type=3 failed: %s; try all types", e)
|
||||
try:
|
||||
rows = self._request(
|
||||
"GET",
|
||||
f"/api/v5/account/bills?instType=OPTION&instId={inst_id}"
|
||||
f"&begin={begin}&end={end}",
|
||||
)
|
||||
except Exception as e2:
|
||||
logger.warning("okx option bills failed: %s; try archive", e2)
|
||||
try:
|
||||
rows = self._request(
|
||||
"GET",
|
||||
f"/api/v5/account/bills-archive?instType=OPTION&instId={inst_id}"
|
||||
f"&begin={begin}&end={end}",
|
||||
)
|
||||
except Exception as e3:
|
||||
logger.warning("okx option bills-archive failed: %s", e3)
|
||||
return None
|
||||
if not isinstance(rows, list):
|
||||
return []
|
||||
return [r for r in rows if isinstance(r, dict)]
|
||||
|
||||
def get_closed_perp_pnl_usdt(
|
||||
self, inst_id: str, *, begin_ms: int, end_ms: int | None = None
|
||||
) -> float | None:
|
||||
|
||||
Reference in New Issue
Block a user