Docs
Docs
Home
Getting Started
Agent Tooling
CLI
Supported Chains
Acala
Aptos
Arbitrum
Arc
Asset Hub
Astar
Avalanche
Base
Berachain
Bifrost
Binance Smart Chain
Bittensor
Blast
Boba Network
Bridge Hub
Celo
Centrifuge
Chiliz
Cronos
Enjin
Ethereum
Etherlink
Flow EVM Gateway
Gnosis
Hydration
Hyperliquid
Immutable
Ink
IoTeX
Kusama
Linea
LISK
Manta Atlantic
Manta Pacific
Mantle
MegaETH
Monad
Movement
Neuroweb
opBNB
Optimism
Plasma
Polkadot
Polygon
Pulsechain
Robinhood
Ronin
Scroll
Sonic
Starknet
Taiko
Tempo
Sui
TRON
Unichain
Viction
World Chain
XDC Network
XX Network
Zetachain
zkSync Era
Zora
Supported ChainsHyperliquidHyperliquid HyperCoreOrderbook Websocket API

WebSocket API Quick Reference

Quick reference for the Hyperliquid Order Book WebSocket API. Connection details, message formats, and links to detailed documentation.

Hyperliquid RPC endpoint: endpoint URLs, plans and pricing.

Quick reference for connecting to and using the Hyperliquid Order Book WebSocket API. For detailed documentation on each subscription type, see the individual pages.

Detailed Documentation

SubscriptionDescriptionDocumentation
TradesReal-time trade executionsView Trades Docs →
L2 Order BookAggregated price levelsView L2 Docs →
L4 Order BookIndividual order visibilityView L4 Docs →

For an overview of all subscription types and use cases, see the Order Book Server Overview.

Connection

Text
wss://api-hyperliquid-mainnet-orderbook.n.dwellir.com/{API_KEY}/ws

Replace {API_KEY} with the API key from your Dwellir dashboard. The Order Book add-on must be enabled on your API plan.

Quick Start

Python
import asyncio
import json
import websockets

async def main():
    ws_url = "wss://api-hyperliquid-mainnet-orderbook.n.dwellir.com/{API_KEY}/ws"

    async with websockets.connect(ws_url) as websocket:
        # Subscribe to BTC trades
        await websocket.send(json.dumps({
            "method": "subscribe",
            "subscription": {"type": "trades", "coin": "BTC"}
        }))

        async for message in websocket:
            print(json.loads(message))

asyncio.run(main())

Subscription Types

Trades

JSON
{
  "method": "subscribe",
  "subscription": {
    "type": "trades",
    "coin": "BTC"
  }
}
ParameterDefaultDescription
user(none)Optional. Filter to trades involving a specific wallet address

Full Trades Documentation →

L2 Order Book

JSON
{
  "method": "subscribe",
  "subscription": {
    "type": "l2Book",
    "coin": "BTC",
    "nSigFigs": 5,
    "nLevels": 20
  }
}
ParameterDefaultRangeDescription
nSigFigs52-5Price aggregation significant figures
nLevels201-100Number of price levels per side

Full L2 Documentation →

L4 Order Book

JSON
{
  "method": "subscribe",
  "subscription": {
    "type": "l4Book",
    "coin": "BTC"
  }
}

Full L4 Documentation →

Unsubscribe

JSON
{
  "method": "unsubscribe",
  "subscription": {
    "type": "trades",
    "coin": "BTC"
  }
}

Server Messages

Subscription Confirmation

JSON
{
  "channel": "subscriptionResponse",
  "data": {
    "method": "subscribe",
    "subscription": { "type": "trades", "coin": "BTC" }
  }
}

Error Response

JSON
{
  "channel": "error",
  "data": "Invalid subscription: coin not found"
}

Common Errors

ErrorCause
"coin not found"Invalid trading pair symbol
"n_levels too high"Requested more than 100 levels
"Already subscribed"Duplicate subscription
"Order book not ready"Server initializing

Response Channels

ChannelSubscription Type
tradesTrades stream
l2BookL2 order book
l4BookL4 order book
subscriptionResponseSubscription confirmations
errorError messages

Reconnection

The server may restart to resync state. Implement automatic reconnection:

Python
async def connect_with_retry():
    delay = 1
    while True:
        try:
            async with websockets.connect(ws_url) as ws:
                delay = 1  # Reset on success
                await handle_connection(ws)
        except Exception:
            await asyncio.sleep(delay)
            delay = min(delay * 2, 60)  # Exponential backoff

Resources

  • Code Examples - Complete Python examples
  • Volume Calculator - Estimate monthly usage
  • Contact - Get access credentials

For detailed documentation, visit the individual subscription pages: Trades | L2 Book | L4 Book

Trades Stream

Stream real-time trade executions from Hyperliquid with ultra-low latency. Access price, size, direction, and participant data for every trade.

eth_blockNumber

Get the current block height on Hyperliquid. Essential for syncing dApps, monitoring transaction confirmations, and blockchain state tracking.

On this page

Detailed DocumentationConnectionQuick StartSubscription TypesTradesL2 Order BookL4 Order BookUnsubscribeServer MessagesSubscription ConfirmationError ResponseCommon ErrorsResponse ChannelsReconnectionResources