Skip to content

Commit 1d9cb17

Browse files
committed
Fix and remove incomplete internal msgpack handling
1 parent 0fd2bf9 commit 1d9cb17

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

lighter/paper_client/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def __init__(
7373
self.account = new_paper_account(initial_collateral_usdc)
7474
self.market_configs: Dict[int, MarketConfig] = {}
7575
self.order_books: Dict[int, InMemoryOrderBook] = {}
76-
self.ws_url = (
77-
ws_url if ws_url is not None else self._default_ws_url(api_client, ws_path)
78-
)
76+
raw_ws_url = ws_url if ws_url is not None else self._default_ws_url(api_client, ws_path)
77+
separator = "&" if "?" in raw_ws_url else "?"
78+
self.ws_url = f"{raw_ws_url}{separator}encoding=json"
7979
self.initial_snapshot_timeout = initial_snapshot_timeout
8080
self._live_listeners: Dict[int, PaperOrderBookListener] = {}
8181
self._state_lock = asyncio.Lock()

lighter/paper_client/live.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ async def _run(self) -> None:
9090

9191
async def _handle_raw_message(self, raw_message: Any) -> None:
9292
if isinstance(raw_message, bytes):
93-
raw_message = raw_message.decode()
94-
message = json.loads(raw_message) if isinstance(raw_message, str) else raw_message
93+
raise TypeError(
94+
"received binary websocket frame; paper client only supports "
95+
"JSON encoding (ensure ws URL includes ?encoding=json)"
96+
)
97+
message = json.loads(raw_message)
9598
message_type = message.get("type")
9699

97100
if message_type == "connected":

0 commit comments

Comments
 (0)