Skip to content

Commit f2e9e19

Browse files
committed
Add Bybit ignore_uncached_instrument_executions config option
1 parent 985c53d commit f2e9e19

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

RELEASES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Released on TBD (UTC).
99
- Added Interactive Brokers cache config support for historical provider (#2942), thanks @ms32035
1010
- Added Interactive Brokers support for fetching orders from all clients (#2948), thanks @dinana
1111
- Added Bybit SPOT position reports with opt-in `use_spot_position_reports` config option for `BybitExecClientConfig`
12+
- Added Bybit `ignore_uncached_instrument_executions` config option for `BybitExecClientConfig` (default `False` to retain current behavior)
1213
- Added OKX trade mode per order via `params` using `td_mode` key
1314

1415
### Breaking Changes

nautilus_trader/adapters/bybit/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class BybitExecClientConfig(LiveExecClientConfig, frozen=True):
116116
- Zero balances (after rounding to instrument precision) are reported as FLAT.
117117
WARNING: This may lead to unintended liquidation of wallet assets if strategies
118118
are not designed to handle spot positions appropriately.
119+
ignore_uncached_instrument_executions : bool, default False
120+
If True, execution message for instruments not contained in the cache are ignored instead of raising an error.
119121
max_retries : PositiveInt, optional
120122
The maximum number of times a submit, cancel or modify order request will be retried.
121123
retry_delay_initial_ms : PositiveInt, optional
@@ -153,6 +155,7 @@ class BybitExecClientConfig(LiveExecClientConfig, frozen=True):
153155
use_ws_execution_fast: bool = False
154156
use_ws_trade_api: bool = False
155157
use_http_batch_api: bool = False
158+
ignore_uncached_instrument_executions: bool = False
156159
max_retries: PositiveInt | None = None
157160
retry_delay_initial_ms: PositiveInt | None = None
158161
retry_delay_max_ms: PositiveInt | None = None

nautilus_trader/adapters/bybit/execution.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def __init__(
197197
self._margin_mode = config.margin_mode
198198
self._position_mode = config.position_mode
199199
self._use_spot_position_reports = config.use_spot_position_reports
200+
self._ignore_uncached_instrument_executions = config.ignore_uncached_instrument_executions
200201

201202
self._log.info(f"Account type: {account_type_to_str(account_type)}", LogColor.BLUE)
202203
self._log.info(f"Product types: {[p.value for p in product_types]}", LogColor.BLUE)
@@ -205,6 +206,7 @@ def __init__(
205206
self._log.info(f"{config.use_ws_trade_api=}", LogColor.BLUE)
206207
self._log.info(f"{config.use_http_batch_api=}", LogColor.BLUE)
207208
self._log.info(f"{config.use_spot_position_reports=}", LogColor.BLUE)
209+
self._log.info(f"{config.ignore_uncached_instrument_executions=}", LogColor.BLUE)
208210
self._log.info(f"{config.max_retries=}", LogColor.BLUE)
209211
self._log.info(f"{config.retry_delay_initial_ms=}", LogColor.BLUE)
210212
self._log.info(f"{config.retry_delay_max_ms=}", LogColor.BLUE)
@@ -1429,6 +1431,7 @@ def _handle_ws_message_private(self, raw: bytes) -> None:
14291431
def _handle_account_execution_update(self, raw: bytes) -> None:
14301432
try:
14311433
msg = self._decoder_ws_account_execution_update.decode(raw)
1434+
14321435
for trade in msg.data:
14331436
self._process_execution(trade)
14341437
except Exception as e:
@@ -1437,12 +1440,13 @@ def _handle_account_execution_update(self, raw: bytes) -> None:
14371440
def _handle_account_execution_fast_update(self, raw: bytes) -> None:
14381441
try:
14391442
msg = self._decoder_ws_account_execution_fast_update.decode(raw)
1443+
14401444
for trade in msg.data:
14411445
self._process_execution(trade)
14421446
except Exception as e:
14431447
self._log.exception(f"Failed to handle account execution update: {e}", e)
14441448

1445-
def _process_execution(
1449+
def _process_execution( # noqa: C901 (too complex)
14461450
self,
14471451
execution: BybitWsAccountExecution | BybitWsAccountExecutionFast,
14481452
) -> None:
@@ -1489,6 +1493,9 @@ def _process_execution(
14891493

14901494
instrument = self._cache.instrument(instrument_id)
14911495
if instrument is None:
1496+
if self._ignore_uncached_instrument_executions:
1497+
return
1498+
14921499
raise ValueError(
14931500
f"Cannot handle trade event: instrument {instrument_id} not found",
14941501
)

0 commit comments

Comments
 (0)