Skip to content

Commit

Permalink
Add error logs to websocket for dYdX (#1993)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsblom authored Oct 10, 2024
1 parent c5d2841 commit e873be2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nautilus_trader/adapters/dydx/websocket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,22 @@ async def _reconnect_guard(self) -> None:
if self.is_disconnected() or time_since_previous_msg > pd.Timedelta(
seconds=self._msg_timeout_secs,
):
if self.is_disconnected():
self._log.error("Websocket disconnected. Reconnecting.")

# Print error if no message has been received for twice the timeout time
# to reduce log noise.
if time_since_previous_msg > pd.Timedelta(seconds=2 * self._msg_timeout_secs):
self._log.error(
f"{time_since_previous_msg} since previous received message. Reconnecting.",
)

try:
await self.disconnect()
await self.connect()
self.reconnect()

self._log.info("Websocket connected")
except Exception as e:
self._log.error(f"Failed to connect the websocket: {e}")
self._client = None
Expand Down

0 comments on commit e873be2

Please sign in to comment.