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
7 changes: 4 additions & 3 deletions 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 Expand Up @@ -286,7 +287,7 @@ def meta(self, dex: str = "") -> Meta:
"""
return cast(Meta, self.post("/info", {"type": "meta", "dex": dex}))

def meta_and_asset_ctxs(self) -> Any:
def meta_and_asset_ctxs(self, dex: str = "") -> Any:
"""Retrieve exchange MetaAndAssetCtxs

POST /info
Expand Down Expand Up @@ -319,7 +320,7 @@ def meta_and_asset_ctxs(self) -> Any:
...
]
"""
return self.post("/info", {"type": "metaAndAssetCtxs"})
return self.post("/info", {"type": "metaAndAssetCtxs", "dex": dex})

def perp_dexs(self) -> Any:
return self.post("/info", {"type": "perpDexs"})
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