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
| Feed | Subscription | What 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 |
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.
# 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())| Channel | Messages in 15 s | First message |
|---|---|---|
| trades | 19 | 30 trades, first a sell at 63,907 |
| l2Book | 2 | 20 levels a side, 63,888 / 63,889 |
| bbo | 112 | 63,888 / 63,889 |
| candle | 14 | 1m candle, 62 trades so far |
| userFills | 22 | Snapshot of 30 fills |
| pong | 1 | 244 ms after the ping |
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
| Limit | Applies to | Value |
|---|---|---|
| REST weight | IP | 1,200 per minute |
| Exchange actions | IP | Weight 1 + floor(batch length / 40) |
| Info: l2Book, allMids, clearinghouseState, orderStatus and 2 more | IP | Weight 2 |
| Other info | IP | Weight 20 (userRole 60); extra per 20 items for userFills and similar, per 60 for candleSnapshot |
| Websocket | IP | 10 connections (30 new a minute), 1,000 subscriptions (user feeds for 10 users at most), 2,000 messages sent a minute |
| Actions | Address | 1 per 1 USDC traded, plus 10,000; cancels min(limit + 100,000, 2 × limit) |
| Open orders | Address | 1,000, plus 1 per 5M USDC volume, max 5,000 |
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.
Related articles
Hyperliquid funding, margin and liquidation explained
How Hyperliquid funding, margin modes and liquidation work, with Nov 2026 numbers and a worked $10,000 example. Fee tiers have their own page.
What is the funding rate in crypto? How it works on Hyperliquid, with dated BTC rates
The funding rate is what longs and shorts pay each other to keep a perpetual future near spot. How Hyperliquid sets it every hour, a worked example, and dated BTC, ETH, SOL, HYPE and stock perp rates.
Hyperliquid fees explained (Nov 2026): maker, taker, builder fees
On a paid Senpi plan you pay only Hyperliquid’s fee. Hyperliquid’s fees on Nov 18, 2026: 0.045% taker, 0.015% maker, tiers, discounts, builder fees by app and HIP-3 rates.
Anthropic stock before the IPO: how to trade ANT now (Nov 2026)
You can trade Anthropic before its IPO: the ANT pre-IPO perp trades 24/7 on Hyperliquid and Senpi, long or short. How it’s priced, what happens at listing, the risks.