๐Ÿ”ง Troubleshooting & Fixes

Hyperliquid Python SDK: Fix WebSocket Reconnect Subscription Drops and Duplicates (2026)

โš ๏ธ Disclosure: Some links on this page are affiliate links. If you sign up through them, I may earn a commission โ€” at no extra cost to you. I only review tools I actually use.
A community-reported issue in the Hyperliquid Python SDK describes two related WebSocketManager reconnect bugs: subscriptions created after the first connect are not re-sent after a reconnect, while subscriptions created before the first connect are re-sent again on every reconnect. The suggested fix is to replay active_subscriptions on reconnect and clear queued_subscriptions after the first connect.

This article summarizes the reported failure mode, affected code locations, and the proposed correction from Hyperliquid Python SDK issue #338, reported on Nov 12, 2026. It is a reference summary of a public issue report, not a verified platform-confirmed patch.

Reported symptoms

According to the issue, after a WebSocket reconnect:

Affected code locations

The issue points to hyperliquid/websocket_manager.py in the Python SDK:

The reported behavior is:
  1. on_open() only replays queued_subscriptions.
  2. queued_subscriptions is only populated before the first connect.
  3. Subscriptions made after connecting live in active_subscriptions and are never re-sent after a reconnect.
  4. queued_subscriptions is never cleared, so pre-connect subscriptions are re-sent again on each reconnect.

Failure sequence

The issue includes an offline reproduction using a stubbed WebSocket module, with no network or wallet required. The reported sequence is:

  1. Subscribe to allMids before connecting.
  2. Connect, then subscribe to userEvents.
  3. Simulate a reconnect by calling the on_open path again.
Observed result from the report: This reproduction is attributed to the issue reporter and is not presented as a test performed by the author.

Suggested fix

The issue suggests two changes:

Conceptually, the reconnect path should distinguish the first open from later opens:

## Pseudocode based on the reported fix; not a verified SDK patch.
def on_open(self, ws):
    if self._first_connect_done:
        for subscription in self.active_subscriptions:
            self._send_subscription(subscription)
    else:
        for subscription in self.queued_subscriptions:
            self._send_subscription(subscription)
        self.queued_subscriptions.clear()

    self._first_connect_done = True

The exact implementation should follow the SDKโ€™s actual data structures and subscription-sending method. The key idea is that every active subscription should be resubscribed after a reconnect, while queued pre-connect subscriptions should not remain queued indefinitely.

Subscription messages to resubscribe

Hyperliquid WebSocket subscriptions are sent as JSON messages with the format:

{
  "method": "subscribe",
  "subscription": { "...": "..." }
}

Examples from the Hyperliquid WebSocket subscriptions documentation include:

๐Ÿ’ก Hyperliquid

Like what you're reading? Try it yourself โ€” this link supports ChartedTrader at no cost to you.

Create a Hyperliquid account โ†’
๐ŸŽ You receive: 4% fee discount on first $25M volume ยท per account, lifetime

{
  "method": "subscribe",
  "subscription": {
    "type": "allMids",
    "dex": "<dex>"
  }
}

{
  "method": "subscribe",
  "subscription": {
    "type": "userEvents",
    "user": "<address>"
  }
}

{
  "method": "subscribe",
  "subscription": {
    "type": "orderUpdates",
    "user": "<address>"
  }
}

{
  "method": "subscribe",
  "subscription": {
    "type": "userFills",
    "user": "<address>"
  }
}

If your bot tracks local subscription state, make sure duplicate subscription acknowledgements or repeated stream messages do not cause double-counting.

This article contains a Hyperliquid referral link. If you sign up through Create a Hyperliquid account, I may earn a referral reward.

Continue with Hyperliquid

Browse the Hyperliquid guide hub for the complete user journey.

Silent disconnects in issue #340

Hyperliquid Python SDK issue #340 reports a related failure mode: after a WebSocket drop, WebsocketManager does not reconnect and does not signal the caller. The report says ws_ready remains True, the manager thread ends, existing subscriptions stop receiving messages, and a later subscribe() can raise WebSocketConnectionClosedException. The proposed root causes are that run() calls run_forever() with no reconnect delay, so the websocket-client default ends the read loop permanently; __init__ has no on_close/on_error handler to reset ws_ready; and on_open replays only queued_subscriptions, leaving already-active subscriptions unsent on a new connection.

The issue suggests passing a reconnect delay to run_forever(reconnect=...), adding on_close/on_error handlers that set ws_ready = False, and re-sending all active_subscriptions in on_open. This matters because bots depending on userFills, orderUpdates, or userEvents can miss fills or keep acting on stale order state after a network blip or server restart.

Issue #340 testnet reproduction and version details

Hyperliquid Python SDK issue #340 includes a testnet reproduction using Info with skip_ws=False, subscribing to allMids, then calling ws_manager.ws.close() to simulate a network drop. The report says that after 4 seconds ws_ready is still True, the manager thread is alive=False, keep_running=False, no further messages arrive, and a later subscribe() raises WebSocketConnectionClosedException.

The report points to websocket_manager.py:101-106 for run() calling self.ws.run_forever() with no arguments, which it says makes websocket-client use reconnect=None / RECONNECT = 0, ending the read loop permanently. It also points to websocket_manager.py:76-88 for missing on_close/on_error handlers and ws_ready never being reset, and to websocket_manager.py:141-145 for on_open replaying only queued_subscriptions.

The issue lists SDK version 0.24.0, commit 2fdb18f9517675ea03695a0962bd19eece9c83f0, and websocket-client 1.9.2. It also notes the report is related to issue #191 but adds the live testnet reproduction and the ws_ready / queued-subscription-only details.

Source verification

๐Ÿงฎ Free Hyperliquid calculators

Fee Calculator โ†’
Hyperliquid vs centralized exchange fee comparison
PnL & Liquidation โ†’
Perp PnL + liquidation price
Position Size โ†’
Risk-aware position sizing for HL perps
Hyperliquid

Ready to get started? Use the link below โ€” it helps support ChartedTrader at no cost to you.

Create a Hyperliquid account โ†’
๐ŸŽ You receive: 4% fee discount on first $25M volume ยท per account, lifetime
๐Ÿ“ˆ

About the author

I'm a systematic trader running live strategies on IB (USDJPY momentum) and Hyperliquid (crypto perps). Every tool reviewed here is something I've used with real capital. Questions? Reach out.

๐Ÿ“š Related Articles

๐Ÿ”Œ
API & Developers

Hyperliquid WebSocket Trades and Candles: Snapshot, Dedupe Key, and Finality

Use the official WsTrade recommendation (block_time, coin, tid) for global uniqueness, and treat candle pushes as mutable interval state.

November 15, 2026 โฑ 4 min read
๐Ÿ”Œ
API & Developers

Hyperliquid Python SDK Tutorial: Build a Bot (2026)

Build a production-ready trading bot on Hyperliquid using the official Python SDK. Covers API wallet security, order execution, WebSocket feeds, and common pitfalls to avoid.

May 6, 2026 โฑ 12 min read
๐Ÿ”Œ
API & Developers

Hyperliquid API Websocket Guide for Developers (2026)

Connect to Hyperliquid WebSocket endpoints, subscribe to basic feeds, send post requests, and keep the connection alive with ping/pong and reconnect handling.

July 29, 2026 โฑ 8 min read