Skip to content

Commit d8667e0

Browse files
authored
Implement _subscribe_instrument for dYdX and Bybit (#2636)
1 parent b09b842 commit d8667e0

File tree

3 files changed

+114
-4
lines changed

3 files changed

+114
-4
lines changed

nautilus_trader/adapters/bybit/data.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@
5555
from nautilus_trader.data.messages import RequestQuoteTicks
5656
from nautilus_trader.data.messages import RequestTradeTicks
5757
from nautilus_trader.data.messages import SubscribeBars
58+
from nautilus_trader.data.messages import SubscribeInstrument
59+
from nautilus_trader.data.messages import SubscribeInstruments
5860
from nautilus_trader.data.messages import SubscribeOrderBook
5961
from nautilus_trader.data.messages import SubscribeQuoteTicks
6062
from nautilus_trader.data.messages import SubscribeTradeTicks
6163
from nautilus_trader.data.messages import UnsubscribeBars
64+
from nautilus_trader.data.messages import UnsubscribeInstrument
65+
from nautilus_trader.data.messages import UnsubscribeInstruments
6266
from nautilus_trader.data.messages import UnsubscribeOrderBook
6367
from nautilus_trader.data.messages import UnsubscribeQuoteTicks
6468
from nautilus_trader.data.messages import UnsubscribeTradeTicks
@@ -273,6 +277,57 @@ async def _update_instruments(self, interval_mins: int) -> None:
273277
except asyncio.CancelledError:
274278
self._log.debug("Canceled task 'update_instruments'")
275279

280+
async def _subscribe_instruments(self, command: SubscribeInstruments) -> None:
281+
"""
282+
Subscribe to instruments updates.
283+
284+
Parameters
285+
----------
286+
command : SubscribeInstruments
287+
The command to subscribe to instruments.
288+
289+
"""
290+
self._log.info("Skipping subscribe_instruments, Bybit subscribes automatically")
291+
292+
async def _subscribe_instrument(self, command: SubscribeInstrument) -> None:
293+
"""
294+
Subscribe to instrument updates.
295+
296+
Parameters
297+
----------
298+
command : SubscribeInstrument
299+
The command to subscribe to instrument.
300+
301+
"""
302+
self._log.info("Skipping subscribe_instrument, Bybit subscribes automatically")
303+
304+
async def _unsubscribe_instruments(
305+
self,
306+
command: UnsubscribeInstruments,
307+
) -> None:
308+
"""
309+
Unsubscribe from instruments updates.
310+
311+
Parameters
312+
----------
313+
command : UnsubscribeInstruments
314+
The command to unsubscribe from instruments updates.
315+
316+
"""
317+
self._log.info("Skipping unsubscribe_instruments, not applicable for Bybit")
318+
319+
async def _unsubscribe_instrument(self, command: UnsubscribeInstrument) -> None:
320+
"""
321+
Unsubscribe from instrument updates.
322+
323+
Parameters
324+
----------
325+
command : UnsubscribeInstrument
326+
The command to unsubscribe from instrument updates.
327+
328+
"""
329+
self._log.info("Skipping unsubscribe_instrument, not applicable for Bybit")
330+
276331
async def _subscribe_order_book_deltas(self, command: SubscribeOrderBook) -> None:
277332
if command.book_type == BookType.L3_MBO:
278333
self._log.error(

nautilus_trader/adapters/dydx/data.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@
4848
from nautilus_trader.common.enums import LogColor
4949
from nautilus_trader.data.messages import RequestBars
5050
from nautilus_trader.data.messages import SubscribeBars
51+
from nautilus_trader.data.messages import SubscribeInstrument
52+
from nautilus_trader.data.messages import SubscribeInstruments
5153
from nautilus_trader.data.messages import SubscribeOrderBook
5254
from nautilus_trader.data.messages import SubscribeQuoteTicks
5355
from nautilus_trader.data.messages import SubscribeTradeTicks
5456
from nautilus_trader.data.messages import UnsubscribeBars
57+
from nautilus_trader.data.messages import UnsubscribeInstrument
58+
from nautilus_trader.data.messages import UnsubscribeInstruments
5559
from nautilus_trader.data.messages import UnsubscribeOrderBook
5660
from nautilus_trader.data.messages import UnsubscribeQuoteTicks
5761
from nautilus_trader.data.messages import UnsubscribeTradeTicks
@@ -152,8 +156,8 @@ def __init__(
152156
base_url=ws_base_url,
153157
loop=loop,
154158
max_send_retries=config.max_retries or 3,
155-
delay_initial_ms=config.retry_delay_initial_ms or 1_000,
156-
delay_max_ms=config.retry_delay_max_ms or 10_000,
159+
delay_initial_ms=config.retry_delay_initial_ms or 100,
160+
delay_max_ms=config.retry_delay_max_ms or 5_000,
157161
backoff_factor=2,
158162
)
159163

@@ -773,6 +777,57 @@ def _handle_markets_subscribed(self, raw: bytes) -> None:
773777
except Exception as e:
774778
self._log.exception(f"Failed to parse market channel data: {raw.decode()}", e)
775779

780+
async def _subscribe_instruments(self, command: SubscribeInstruments) -> None:
781+
"""
782+
Subscribe to instruments updates.
783+
784+
Parameters
785+
----------
786+
command : SubscribeInstruments
787+
The command to subscribe to instruments.
788+
789+
"""
790+
self._log.info("Skipping subscribe_instruments, dYdX subscribes automatically")
791+
792+
async def _subscribe_instrument(self, command: SubscribeInstrument) -> None:
793+
"""
794+
Subscribe to instrument updates.
795+
796+
Parameters
797+
----------
798+
command : SubscribeInstrument
799+
The command to subscribe to instrument.
800+
801+
"""
802+
self._log.info("Skipping subscribe_instrument, dYdX subscribes automatically")
803+
804+
async def _unsubscribe_instruments(
805+
self,
806+
command: UnsubscribeInstruments,
807+
) -> None:
808+
"""
809+
Unsubscribe from instruments updates.
810+
811+
Parameters
812+
----------
813+
command : UnsubscribeInstruments
814+
The command to unsubscribe from instruments updates.
815+
816+
"""
817+
self._log.info("Skipping unsubscribe_instruments, not applicable for dYdX")
818+
819+
async def _unsubscribe_instrument(self, command: UnsubscribeInstrument) -> None:
820+
"""
821+
Unsubscribe from instrument updates.
822+
823+
Parameters
824+
----------
825+
command : UnsubscribeInstrument
826+
The command to unsubscribe from instrument updates.
827+
828+
"""
829+
self._log.info("Skipping unsubscribe_instrument, not applicable for dYdX")
830+
776831
async def _subscribe_trade_ticks(self, command: SubscribeTradeTicks) -> None:
777832
dydx_symbol = DYDXSymbol(command.instrument_id.symbol.value)
778833
await self._ws_client.subscribe_trades(dydx_symbol.raw_symbol)

nautilus_trader/adapters/dydx/websocket/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ async def connect(self) -> None:
162162
self._retry_manager_pool = RetryManagerPool[None](
163163
pool_size=100,
164164
max_retries=self._max_send_retries or 0,
165-
delay_initial_ms=self._delay_initial_ms or 1_000,
166-
delay_max_ms=self._delay_max_ms or 10_000,
165+
delay_initial_ms=self._delay_initial_ms or 100,
166+
delay_max_ms=self._delay_max_ms or 5_000,
167167
backoff_factor=self._backoff_factor or 2,
168168
logger=self._log,
169169
exc_types=(WebSocketClientError,),

0 commit comments

Comments
 (0)