Align options review PnL with OKX positions-history realizedPnl.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -263,8 +263,12 @@ def _sync_options_trades(
|
||||
if not force and now - _OPTIONS_SYNC_LAST_AT < _OPTIONS_SYNC_INTERVAL_SEC:
|
||||
return
|
||||
_OPTIONS_SYNC_LAST_AT = now
|
||||
from lib.exchange.okx_options_lib import fetch_option_position_history
|
||||
from lib.options.options_monitor_lib import reconcile_live_open_trades, sync_open_options_trades
|
||||
from lib.exchange.okx_options_lib import fetch_all_option_positions_history, fetch_option_position_history
|
||||
from lib.options.options_monitor_lib import (
|
||||
backfill_closed_options_realized_pnl_from_history,
|
||||
reconcile_live_open_trades,
|
||||
sync_open_options_trades,
|
||||
)
|
||||
|
||||
if raw_positions is None:
|
||||
raw = cfg["fetch_option_positions"](ex)
|
||||
@@ -282,6 +286,11 @@ def _sync_options_trades(
|
||||
init_options_tables(conn)
|
||||
reconcile_live_open_trades(conn, live_inst_ids=live_ids)
|
||||
sync_open_options_trades(conn, live_inst_ids=live_ids, fetch_history_fn=_hist)
|
||||
try:
|
||||
hist_all = fetch_all_option_positions_history(ex, limit=200)
|
||||
backfill_closed_options_realized_pnl_from_history(conn, hist_all)
|
||||
except Exception:
|
||||
pass
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user