Hyperliquid API: websockets, subscriptions and rate limits (Python)

Updated Nov 19, 2026 · 5 min read

Connect to wss://api.hyperliquid.xyz/ws, subscribe to trades, books, candles and user fills, ping before the 60-second timeout, and stay under 1,200 REST weight a minute per IP. Tested Nov 19, 2026.

How do Hyperliquid’s websockets and rate limits work? Connect to wss://api.hyperliquid.xyz/ws (testnet: wss://api.hyperliquid-testnet.xyz/ws) and send one {"method": "subscribe", "subscription": {...}} message per feed; no key is needed. The server closes a connection it hasn’t sent a message to in 60 seconds, so send {"method": "ping"}. REST calls share 1,200 weight a minute per IP, and each IP may hold 10 websocket connections and 1,000 subscriptions.

Key takeaways

  • Most info requests weigh 20, about 60 a minute per IP; l2Book and allMids weigh 2.
  • User feeds need the account’s own address (main or sub-account); an API wallet’s address returns nothing.

Websocket subscription types

FeedSubscriptionWhat arrives
trades{"type": "trades", "coin": "BTC"}Price, size, aggressing side (B buy, A sell), both addresses
l2Book{"type": "l2Book", "coin": "BTC"}Book snapshots; nSigFigs and mantissa optional
bbo{"type": "bbo", "coin": "BTC"}Best bid and ask when they change
candle{"type": "candle", "coin": "BTC", "interval": "1m"}The current candle, 1m to 1M
allMids{"type": "allMids"}All mids; deprecated for fastAssetCtxs
userFills, userEvents, orderUpdates{"type": "userFills", "user": "0x…"}An account’s fills (snapshot first), events or order updates
Hyperliquid websocket docs, checked Nov 19, 2026. Unsubscribe by resending the subscription with method unsubscribe.

Connect and subscribe in Python

The script holds one connection for 15 seconds, subscribes to five feeds and sends one ping. The user feed follows an account behind the HLP vault.

python
# Connect to Hyperliquid's public websocket for ~15 seconds, subscribe to five feeds, send one ping and print
# what arrives. Read-only: no key, no orders.
import asyncio, json, time
from collections import Counter
from datetime import datetime, timezone

import websockets

URL = "wss://api.hyperliquid.xyz/ws"  # testnet: wss://api.hyperliquid-testnet.xyz/ws
HLP_ACCOUNT = "0x010461c14e146ac35fe42271bdc1134ee31c703a"  # a public account behind the HLP vault
SUBSCRIPTIONS = [
    {"type": "trades", "coin": "BTC"},
    {"type": "l2Book", "coin": "BTC"},
    {"type": "candle", "coin": "BTC", "interval": "1m"},
    {"type": "bbo", "coin": "BTC"},
    {"type": "userFills", "user": HLP_ACCOUNT},  # user feeds take the account address, not an API wallet's
]

def describe(channel, data):
    if channel == "subscriptionResponse":
        return f"subscribed to {data['subscription']['type']}"
    if channel == "trades":
        t = data[0]
        side = {"B": "buy", "A": "sell"}[t["side"]]  # the aggressing side
        return f"{len(data)} trade(s), first: {side} {t['sz']} {t['coin']} @ {t['px']}"
    if channel == "l2Book":
        bids, asks = data["levels"]
        return f"{len(bids)} bid / {len(asks)} ask levels, best {bids[0]['px']} / {asks[0]['px']}"
    if channel == "candle":
        return f"{data['i']} candle open {data['o']} close {data['c']}, {data['n']} trades so far"
    if channel == "bbo":
        bid, ask = data["bbo"]
        return f"best bid {bid['px']} x {bid['sz']}, best ask {ask['px']} x {ask['sz']}"
    if channel == "userFills":
        return f"isSnapshot={data.get('isSnapshot', False)}, {len(data['fills'])} fill(s)"
    return json.dumps(data)[:120]

async def main(seconds=15):
    counts = Counter()
    async with websockets.connect(URL, max_size=10_000_000) as ws:
        print(f"websockets {websockets.__version__} | connected {datetime.now(timezone.utc):%Y-%m-%d %H:%M:%S} UTC")
        for sub in SUBSCRIPTIONS:
            await ws.send(json.dumps({"method": "subscribe", "subscription": sub}))
        start, ping_sent = time.monotonic(), None
        while (left := seconds - (time.monotonic() - start)) > 0:
            if ping_sent is None and time.monotonic() - start > 5:
                ping_sent = time.monotonic()
                await ws.send(json.dumps({"method": "ping"}))  # the server drops connections idle for 60 s
            try:
                msg = json.loads(await asyncio.wait_for(ws.recv(), timeout=left))
            except asyncio.TimeoutError:
                break
            channel = msg.get("channel")
            counts[channel] += 1
            if channel == "pong":
                print(f"pong after {(time.monotonic() - ping_sent) * 1000:.0f} ms")
            elif channel == "subscriptionResponse" or counts[channel] == 1:
                print(f"[{channel}] {describe(channel, msg.get('data'))}")
    print(f"messages in {seconds} s:", dict(counts))

asyncio.run(main())
ChannelMessages in 15 sFirst message
trades1930 trades, first a sell at 63,907
l2Book220 levels a side, 63,888 / 63,889
bbo11263,888 / 63,889
candle141m candle, 62 trades so far
userFills22Snapshot of 30 fills
pong1244 ms after the ping
Run at 14:19 UTC on Nov 19, 2026, websockets 17.4, Python 3.12; counts vary with activity. Market data only; not a forecast or a trade signal.

Production code must reconnect: servers drop connections without notice, and missed data arrives in the snapshot on reconnect. The official hyperliquid-python-sdk pings every 50 seconds. The socket can also send info requests and signed actions as post messages; to sign orders, use an API wallet and see how to code a strategy on Hyperliquid.

Hyperliquid API rate limits

LimitApplies toValue
REST weightIP1,200 per minute
Exchange actionsIPWeight 1 + floor(batch length / 40)
Info: l2Book, allMids, clearinghouseState, orderStatus and 2 moreIPWeight 2
Other infoIPWeight 20 (userRole 60); extra per 20 items for userFills and similar, per 60 for candleSnapshot
WebsocketIP10 connections (30 new a minute), 1,000 subscriptions (user feeds for 10 users at most), 2,000 messages sent a minute
ActionsAddress1 per 1 USDC traded, plus 10,000; cancels min(limit + 100,000, 2 × limit)
Open ordersAddress1,000, plus 1 per 5M USDC volume, max 5,000
Hyperliquid rate limits docs, checked Nov 19, 2026. Sub-accounts count as separate users; a batch of n orders is one IP request and n address requests.

What happens when you hit a limit

An address over its action limit may send one request every 10 seconds. Check the budget with the userRateLimit info request, or reserve more with the reserveRequestWeight action at 0.0005 USDC per request. The docs don’t say what an IP over its weight gets; our CCXT test got HTTP 429 after repeated market loads on Nov 17.

Or let Senpi run the strategy

On Senpi, a strategy you confirm runs as code on Senpi’s runtime, and by default no AI model makes live trading decisions. Each strategy trades from its own strategy wallet; the agent holds no key and cannot withdraw.

What is the Hyperliquid websocket URL?

wss://api.hyperliquid.xyz/ws on mainnet and wss://api.hyperliquid-testnet.xyz/ws on testnet. Subscriptions need no key.

What is Hyperliquid’s API rate limit?

1,200 REST weight per minute per IP, with most info requests weighing 20. Orders and cancels also count per address.

How do I keep a Hyperliquid websocket connection alive?

Send {"method": "ping"}; the server replies {"channel": "pong"}. It closes connections it hasn’t sent a message to in 60 seconds.

Sources: Hyperliquid API docs; hyperliquid-python-sdk on GitHub; websockets on PyPI. Checked and run Nov 19, 2026.

Educational material, not financial advice.

Run a rule without a server

Describe the rule; Senpi runs it on its runtime with a stop from the first fill.

Try Senpi free
Share

Related articles