Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hyperliquid/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ def __init__(
# the original dex.
perp_dexs: Optional[List[str]] = None,
timeout: Optional[float] = None,
reconnect_ws: Optional[int] = None, # Exposed reconnect parameter to auto-reconnect
): # pylint: disable=too-many-locals
super().__init__(base_url, timeout)
self.ws_manager: Optional[WebsocketManager] = None
if not skip_ws:
self.ws_manager = WebsocketManager(self.base_url)
self.ws_manager = WebsocketManager(self.base_url, reconnect_ws=reconnect_ws)
self.ws_manager.start()

if spot_meta is None:
Expand Down
5 changes: 3 additions & 2 deletions hyperliquid/websocket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def ws_msg_to_identifier(ws_msg: WsMsg) -> Optional[str]:


class WebsocketManager(threading.Thread):
def __init__(self, base_url):
def __init__(self, base_url, reconnect_ws: Optional[int] = None):
super().__init__()
self.subscription_id_counter = 0
self.ws_ready = False
Expand All @@ -85,10 +85,11 @@ def __init__(self, base_url):
self.ws = websocket.WebSocketApp(ws_url, on_message=self.on_message, on_open=self.on_open)
self.ping_sender = threading.Thread(target=self.send_ping)
self.stop_event = threading.Event()
self.reconnect_ws: Optional[int] = reconnect_ws # Exposed reconnect parameter to auto-reconnect

def run(self):
self.ping_sender.start()
self.ws.run_forever()
self.ws.run_forever(reconnect=self.reconnect_ws)

def send_ping(self):
while not self.stop_event.wait(50):
Expand Down