Skip to content

Commit 1a34489

Browse files
committed
Added activeAssetData websocket subscription
1 parent a4280d0 commit 1a34489

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

examples/basic_ws.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def main():
2020
info.subscribe({"type": "bbo", "coin": "ETH"}, print)
2121
info.subscribe({"type": "activeAssetCtx", "coin": "BTC"}, print) # Perp
2222
info.subscribe({"type": "activeAssetCtx", "coin": "@1"}, print) # Spot
23+
info.subscribe({"type": "activeAssetData", "user": address, "coin": "BTC"}, print) # Perp
2324

2425

2526
if __name__ == "__main__":

hyperliquid/utils/types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
)
5151
WebData2Subscription = TypedDict("WebData2Subscription", {"type": Literal["webData2"], "user": str})
5252
ActiveAssetCtxSubscription = TypedDict("ActiveAssetCtxSubscription", {"type": Literal["activeAssetCtx"], "coin": str})
53+
ActiveAssetDataSubscription = TypedDict(
54+
"ActiveAssetDataSubscription", {"type": Literal["activeAssetData"], "user": str, "coin": str}
55+
)
5356
# If adding new subscription types that contain coin's don't forget to handle automatically rewrite name to coin in info.subscribe
5457
Subscription = Union[
5558
AllMidsSubscription,
@@ -64,6 +67,7 @@
6467
UserNonFundingLedgerUpdatesSubscription,
6568
WebData2Subscription,
6669
ActiveAssetCtxSubscription,
70+
ActiveAssetDataSubscription,
6771
]
6872

6973
AllMidsData = TypedDict("AllMidsData", {"mids": Dict[str, str]})
@@ -75,6 +79,14 @@
7579
BboMsg = TypedDict("BboMsg", {"channel": Literal["bbo"], "data": BboData})
7680
PongMsg = TypedDict("PongMsg", {"channel": Literal["pong"]})
7781
Trade = TypedDict("Trade", {"coin": str, "side": Side, "px": str, "sz": int, "hash": str, "time": int})
82+
Leverage = TypedDict(
83+
"Leverage",
84+
{
85+
"type": Union[Literal["cross"], Literal["isolated"]],
86+
"value": int,
87+
"rawUsd": Optional[str],
88+
},
89+
)
7890
TradesMsg = TypedDict("TradesMsg", {"channel": Literal["trades"], "data": List[Trade]})
7991
PerpAssetCtx = TypedDict(
8092
"PerpAssetCtx",
@@ -97,6 +109,18 @@
97109
ActiveSpotAssetCtxMsg = TypedDict(
98110
"ActiveSpotAssetCtxMsg", {"channel": Literal["activeSpotAssetCtx"], "data": ActiveSpotAssetCtx}
99111
)
112+
ActiveAssetData = TypedDict(
113+
"ActiveAssetData",
114+
{
115+
"user": str,
116+
"coin": str,
117+
"leverage": Leverage,
118+
"maxTradeSzs": List[str],
119+
"availableToTrade": List[str],
120+
"markPx": str,
121+
},
122+
)
123+
ActiveAssetDataMsg = TypedDict("ActiveAssetDataMsg", {"channel": Literal["activeAssetData"], "data": ActiveAssetData})
100124
Fill = TypedDict(
101125
"Fill",
102126
{

hyperliquid/websocket_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def subscription_to_identifier(subscription: Subscription) -> str:
3535
return f'bbo:{subscription["coin"].lower()}'
3636
elif subscription["type"] == "activeAssetCtx":
3737
return f'activeAssetCtx:{subscription["coin"].lower()}'
38+
elif subscription["type"] == "activeAssetData":
39+
return f'activeAssetData:{subscription["coin"].lower()}'
3840

3941

4042
def ws_msg_to_identifier(ws_msg: WsMsg) -> Optional[str]:
@@ -68,6 +70,8 @@ def ws_msg_to_identifier(ws_msg: WsMsg) -> Optional[str]:
6870
return f'bbo:{ws_msg["data"]["coin"].lower()}'
6971
elif ws_msg["channel"] == "activeAssetCtx" or ws_msg["channel"] == "activeSpotAssetCtx":
7072
return f'activeAssetCtx:{ws_msg["data"]["coin"].lower()}'
73+
elif ws_msg["channel"] == "activeAssetData":
74+
return f'activeAssetData:{ws_msg["data"]["coin"].lower()}'
7175

7276

7377
class WebsocketManager(threading.Thread):

0 commit comments

Comments
 (0)