⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
All Blog Posts
Article Image

Step-by-Step Guide to Using Dwellir's Hyperliquid Order Book Server

3rd November 2025

Hyperliquid's onchain order book delivers performance comparable to centralized exchanges: transactions finalize in about 0.2 seconds, and the platform handles around 200,000 orders per second. However, the public WebSocket endpoint limits you to 100 simultaneous connections and 1,000 subscriptions, which becomes restrictive for serious trading operations. Dwellir's hosted order book server removes these limits, provides access to detailed Level 4 (L4) order data, and reduces median latency by 24.1% compared to the public feed.

Quick answer: Use authenticated WebSocket connections to access Dwellir's order book server. Subscribe to trade feeds, L2 order book depth, and L4 detailed order data using the open-source Python examples. Add reconnection handling, analytics, and data storage as needed. Combine this with Dwellir's HyperEVM RPC, gRPC snapshots, and dedicated nodes for a complete Hyperliquid data solution.

This tutorial walks through using Dwellir's order book server. We'll cover the prerequisites, work through each Python example, and share tips for building production-ready systems on Hyperliquid.

Why Use Dwellir's Order Book Server

Why Dwellir? One account gives you access to the entire Hyperliquid data stack: WebSocket feeds, HyperEVM RPC, gRPC APIs, historical datasets, and dedicated node infrastructure.

Prerequisites

  1. Request access - Contact our team to get access to Dwellir's Hyperliquid services, including the order book server.
  2. Workspace setup - Clone the official hyperliquid-orderbook-server-code-examples repository.
  3. Environment variables - Copy .env.example to .env, then add the WebSocket URL provided by Dwellir (wss://<your-instance>.dwellir.com/ws).
  4. Python toolchain - Python 3.8+, pip, and optionally virtualenv.
  5. API key security - Store credentials outside source control and use separate keys for each service.

Understanding the Example Repository

In this article, we'll walk through seven Python examples that take you from basic WebSocket connections to running your own order book monitoring system. Here's how they're organized:

StageExample DirectoryConceptProduction Takeaway
101_websocket_basicsSingle-feed trade subscriptionBaseline connection, message decoding
202_l2_orderbook_basicsAggregated depth with spreadsValidate parity with UI, tune nLevels/nSigFigs
303_multiple_subscriptionsMulti-coin routingMessage dispatch, concurrency patterns
404_multi_coin_trackerAdvanced multi-coin trackingTrack metrics across multiple coins, VWAP calculations
505_reconnection_handlingExponential backoff + resubscriptionStay live through upstream restarts
606_data_analysisMarket metrics and analyticsReal-time VWAP, spreads, buy/sell ratios
707_l4_orderbookIndividual order visibility with L4 dataWallet-level liquidity, order tracking, market microstructure

We’ll expand each stage, highlight the key code paths, and layer in Dwellir-specific guidance.

Step 1 – WebSocket Basics

Goal: connect, subscribe to BTC trades, and stream payloads.
Key files: python-examples/01_websocket_basics/websocket_basics.py

Focus on three lines:

  1. ws_url = os.getenv("WEBSOCKET_URL") – keep environment injection external so secrets never hit commits.
  2. await websocket.send(json.dumps(subscription)) – Dwellir follows Hyperliquid’s JSON schema ({ "method": "subscribe", "subscription": { ... } }). The payloads match the official WebSocket docs.
  3. async for message in websocket: – messages arrive as text frames; decode with json.loads and dispatch by channel.
import asyncio
import json
import os
import websockets
from dotenv import load_dotenv

load_dotenv()

async def main():
    ws_url = os.getenv("WEBSOCKET_URL")

    # Connect to WebSocket
    websocket = await websockets.connect(ws_url)

    # Subscribe to BTC trades
    subscribe_message = {
        "method": "subscribe",
        "subscription": {
            "type": "trades",
            "coin": "BTC"
        }
    }
    await websocket.send(json.dumps(subscribe_message))

    # Listen for messages
    async for message in websocket:
        data = json.loads(message)
        print(f"Received: {json.dumps(data, indent=2)}")

if __name__ == "__main__":
    asyncio.run(main())

Production tips

Step 2 – L2 Order Book Basics

Goal: reconstruct aggregated depth and calculate spreads. Key files: python-examples/02_l2_orderbook_basics/l2_orderbook.py

Important subscription arguments:

{
  "type": "l2Book",
  "coin": "ETH",
  "nLevels": 20,
  "nSigFigs": 5
}

Validation: Log the best bid and ask prices, then compare them with app.hyperliquid.com to verify they match.

Production tips

Step 3 – Multiple Subscriptions

Goal: subscribe to trades and books for multiple coins concurrently.
Key files: python-examples/03_multiple_subscriptions/multiple_subscriptions.py

Patterns to copy:

Production tips

Step 4 – Multi-Coin Tracker

Goal: track trades from multiple coins simultaneously and compare metrics across markets. Key files: python-examples/04_multi_coin_tracker/multi_coin_tracker.py

This example introduces a class-based architecture for tracking multiple coins:

class CoinTracker:
    """Track trading metrics for a specific coin"""

    def __init__(self, coin):
        self.coin = coin
        self.trades = deque(maxlen=50)  # Last 50 trades
        self.total_volume = 0
        self.buy_volume = 0
        self.sell_volume = 0

The multi-coin tracker calculates real-time metrics for each coin:

Production tips

Step 5 – Reconnection Handling

Goal: survive node restarts, network hiccups, and intentional server exits.
Key files: python-examples/05_reconnection_handling/robust_client.py

Essentials:

async def resilient_stream(subscriptions):
    backoff = 1
    while True:
        try:
            async with websockets.connect(WS_URL, extra_headers=HEADERS, open_timeout=10) as websocket:
                for subscription in subscriptions:
                    await websocket.send(json.dumps(subscription))
                async for raw in websocket:
                    handle_message(json.loads(raw))
        except websockets.ConnectionClosedError as err:
            logger.warning("socket closed (%s) retrying in %ss", err.code, backoff)
            await asyncio.sleep(backoff)
            backoff = min(backoff * 2, 60)
        else:
            backoff = 1

Add metrics (success counts, failure reasons) and surface them via Prometheus or CloudWatch to track reliability.

Step 6 – Market Metrics and Data Analysis

Goal: calculate comprehensive market statistics from real-time order book and trade data. Key files: python-examples/06_data_analysis/market_metrics.py

The MarketAnalyzer class provides a complete analytics framework:

class MarketAnalyzer:
    """Analyze market data and calculate metrics"""

    def __init__(self, history_size=100):
        self.trades = deque(maxlen=history_size)
        self.spreads = deque(maxlen=history_size)
        self.prices = deque(maxlen=history_size)
        self.volumes = deque(maxlen=history_size)

    def get_vwap(self):
        """Calculate Volume-Weighted Average Price"""
        total_value = sum(t['price'] * t['size'] for t in self.trades)
        total_volume = sum(t['size'] for t in self.trades)
        return total_value / total_volume if total_volume > 0 else 0

The analyzer tracks multiple metrics simultaneously:

Production tips

Step 7 – L4 Order Book (Individual Orders)

Goal: unlock per-order visibility with individual order IDs and user addresses. Key files: python-examples/07_l4_orderbook/l4_orderbook.py

The L4 subscription provides the most detailed market microstructure data available:

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

The L4 order book tracks individual orders with full details:

class L4OrderBook:
    def __init__(self):
        # Store orders by order ID: {oid: {user, limitPx, sz, side}}
        self.orders = {}
        # Store bids and asks by price: {price: [oid1, oid2, ...]}
        self.bids = defaultdict(list)
        self.asks = defaultdict(list)

L4 data enables advanced market analysis:

Dwellir's server provides authenticated L4 access, bypassing the public API's 100 connection limit and unlocking analytics that would otherwise require self-hosting infrastructure.

Production tips

Extending Beyond the Examples

With all seven examples mastered, integrate Dwellir's complementary services:

Hardening for Production

  1. Rate-limit awareness: even with dedicated infrastructure, respect Hyperliquid’s per-IP and per-user rules (100 connections, 1,000 subscriptions) to avoid unexpected throttles.
  2. State checkpoints: snapshot L4 ladders and trade sequences so you can reconstruct any trading incident.
  3. Latency dashboards: track round-trip and publish-subscribe delays to verify the 51 ms median advantage persists in your deployment.
  4. Security hygiene: rotate API keys quarterly, segment environment variables by service, and store secrets in Vault or AWS Secrets Manager.
  5. Disaster drills: simulate node restarts and network partitions; confirm reconnection logic resubscribes and replays without manual intervention.

Troubleshooting & Monitoring Playbook

Comparing to Public Endpoints

FeaturePublic Hyperliquid APIDwellir Order Book Server
Connections100 WebSockets per IPDedicated capacity with managed routing
Data depthTrades + L2Trades + L2 + private L4
Latency0.26 s median (example benchmark)0.21 s median (51 ms faster)
Rate limits1,200 REST weight/min, 1,000 subscriptionsTuned per client; SLA-backed
ReliabilitySelf-managed24/7 monitored infrastructure

Public limits hamper multi-market bots and advanced analytics; Dwellir clears the path by hosting co-located infrastructure and layering operational support.

Dwellir’s Hyperliquid Infrastructure Options

FAQ

How do I know my feed is in sync with Hyperliquid?
Track a reference market (e.g., BTC-PERP) and compare top-of-book quotes against app.hyperliquid.com. Any deviation longer than a few milliseconds signals desynchronization - refresh your snapshot or reconnect.

Can I run multiple client instances with one API key?
Yes, but keep separate environment variables per service so a compromised key doesn’t cascade across bots. Use tags in your observability stack to attribute traffic per process.

What if I need REST access alongside WebSockets?
Point your REST clients at Dwellir’s Hyperliquid RPC endpoints. They share auth with the order book server, which simplifies credential management for order placement, funding checks, or HyperEVM contract calls.

How do I store L4 data efficiently? Append updates to columnar formats such as Parquet or Apache Iceberg; partition by market and hour so analytics jobs can prune unnecessary files. Compress with lz4 or zstd for 5–10x size reductions without sacrificing replay speed.

Putting It All Together

By now you have practiced seven core skills: opening a secure WebSocket connection, reading live trades, understanding depth ladders, juggling multiple markets, recovering from dropped links, turning raw data into simple metrics, and inspecting individual orders. That toolkit is enough to stand up a dependable feed for the coins you care about.

With access to Dwellir’s order book server you can turn those skills into real products—a live market dashboard, alerting for sudden spread changes, or a historical replay that powers post-trade reviews—all without running your own Hyperliquid node.

Want credentials for the order book server? Reach out to our team and we’ll help you get started.


Ready to get started? For HyperEVM RPC access, sign up at our dashboard. For access to the order book server with L4 data, contact our team. Check out the Hyperliquid documentation for implementation details.

Get your API key

and join other leading Web3 companies using Dwellir's infrastructure