Skip to content

Commit ab920d9

Browse files
committed
Fix bbo
1 parent 8eadff5 commit ab920d9

4 files changed

Lines changed: 13 additions & 2 deletions

File tree

examples/basic_ws.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def main():
1717
info.subscribe({"type": "userFundings", "user": address}, print)
1818
info.subscribe({"type": "userNonFundingLedgerUpdates", "user": address}, print)
1919
info.subscribe({"type": "webData2", "user": address}, print)
20+
info.subscribe({"type": "bbo", "coin": "ETH"}, print)
2021

2122

2223
if __name__ == "__main__":

hyperliquid/info.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,12 @@ def query_user_to_multi_sig_signers(self, multi_sig_user: str) -> Any:
575575
return self.post("/info", {"type": "userToMultiSigSigners", "user": multi_sig_user})
576576

577577
def subscribe(self, subscription: Subscription, callback: Callable[[Any], None]) -> int:
578-
if subscription["type"] == "l2Book" or subscription["type"] == "trades" or subscription["type"] == "candle":
578+
if (
579+
subscription["type"] == "l2Book"
580+
or subscription["type"] == "trades"
581+
or subscription["type"] == "candle"
582+
or subscription["type"] == "bbo"
583+
):
579584
subscription["coin"] = self.name_to_coin[subscription["coin"]]
580585
if self.ws_manager is None:
581586
raise RuntimeError("Cannot call subscribe since skip_ws was used")

hyperliquid/utils/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
AllMidsMsg = TypedDict("AllMidsMsg", {"channel": Literal["allMids"], "data": AllMidsData})
6969
L2Level = TypedDict("L2Level", {"px": str, "sz": str, "n": int})
7070
BboData = TypedDict("BboData", {"coin": str, "time": int, "bbo": Tuple[Optional[L2Level], Optional[L2Level]]})
71+
BboMsg = TypedDict("BboMsg", {"channel": Literal["bbo"], "data": BboData})
7172
L2BookData = TypedDict("L2BookData", {"coin": str, "levels": Tuple[List[L2Level]], "time": int})
7273
L2BookMsg = TypedDict("L2BookMsg", {"channel": Literal["l2Book"], "data": L2BookData})
7374
PongMsg = TypedDict("PongMsg", {"channel": Literal["pong"]})
@@ -111,7 +112,7 @@
111112
},
112113
total=False,
113114
)
114-
WsMsg = Union[AllMidsMsg, L2BookMsg, TradesMsg, UserEventsMsg, PongMsg, UserFillsMsg, OtherWsMsg]
115+
WsMsg = Union[AllMidsMsg, BboMsg, L2BookMsg, TradesMsg, UserEventsMsg, PongMsg, UserFillsMsg, OtherWsMsg]
115116

116117
# b is the public address of the builder, f is the amount of the fee in tenths of basis points. e.g. 10 means 1 basis point
117118
BuilderInfo = TypedDict("BuilderInfo", {"b": str, "f": int})

hyperliquid/websocket_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def subscription_to_identifier(subscription: Subscription) -> str:
3131
return f'userNonFundingLedgerUpdates:{subscription["user"].lower()}'
3232
elif subscription["type"] == "webData2":
3333
return f'webData2:{subscription["user"].lower()}'
34+
elif subscription["type"] == "bbo":
35+
return f'bbo:{subscription["coin"].lower()}'
3436

3537

3638
def ws_msg_to_identifier(ws_msg: WsMsg) -> Optional[str]:
@@ -60,6 +62,8 @@ def ws_msg_to_identifier(ws_msg: WsMsg) -> Optional[str]:
6062
return f'userNonFundingLedgerUpdates:{ws_msg["data"]["user"].lower()}'
6163
elif ws_msg["channel"] == "webData2":
6264
return f'webData2:{ws_msg["data"]["user"].lower()}'
65+
elif ws_msg["channel"] == "bbo":
66+
return f'bbo:{ws_msg["data"]["coin"].lower()}'
6367

6468

6569
class WebsocketManager(threading.Thread):

0 commit comments

Comments
 (0)