Skip to content

Add AssetCTX websocket endpoint #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions hyperliquid/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,16 @@ def query_user_to_multi_sig_signers(self, multi_sig_user: str) -> Any:
return self.post("/info", {"type": "userToMultiSigSigners", "user": multi_sig_user})

def subscribe(self, subscription: Subscription, callback: Callable[[Any], None]) -> int:
if subscription["type"] == "l2Book" or subscription["type"] == "trades" or subscription["type"] == "candle":
subscription["coin"] = self.name_to_coin[subscription["coin"]]
if subscription["type"] == "l2Book" or subscription["type"] == "trades" or subscription["type"] == "candle" or subscription['type'] == 'activeAssetCtx':
subscription["coin"] = self.name_to_coin[subscription["coin"]]
if self.ws_manager is None:
raise RuntimeError("Cannot call subscribe since skip_ws was used")
else:
return self.ws_manager.subscribe(subscription, callback)

def unsubscribe(self, subscription: Subscription, subscription_id: int) -> bool:
if subscription["type"] == "l2Book" or subscription["type"] == "trades" or subscription["type"] == "candle":
subscription["coin"] = self.name_to_coin[subscription["coin"]]
if subscription["type"] == "l2Book" or subscription["type"] == "trades" or subscription["type"] == "candle" or subscription['type'] == 'activeAssetCtx':
subscription["coin"] = self.name_to_coin[subscription["coin"]]
if self.ws_manager is None:
raise RuntimeError("Cannot call unsubscribe since skip_ws was used")
else:
Expand Down
4 changes: 4 additions & 0 deletions hyperliquid/websocket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def subscription_to_identifier(subscription: Subscription) -> str:
return f'l2Book:{subscription["coin"].lower()}'
elif subscription["type"] == "trades":
return f'trades:{subscription["coin"].lower()}'
elif subscription["type"] == "activeAssetCtx":
return f'activeAssetCtx:{subscription["coin"].lower()}'
elif subscription["type"] == "userEvents":
return "userEvents"
elif subscription["type"] == "userFills":
Expand All @@ -41,6 +43,8 @@ def ws_msg_to_identifier(ws_msg: WsMsg) -> Optional[str]:
return "allMids"
elif ws_msg["channel"] == "l2Book":
return f'l2Book:{ws_msg["data"]["coin"].lower()}'
elif ws_msg["channel"] == "activeAssetCtx":
return f'activeAssetCtx:{ws_msg["data"]["coin"].lower()}'
elif ws_msg["channel"] == "trades":
trades = ws_msg["data"]
if len(trades) == 0:
Expand Down