L2 Order Book - Aggregated Price Levels
Stream aggregated Level 2 order book data from Hyperliquid. Real-time bid/ask levels with configurable depth and price aggregation.
Stream aggregated order book data showing total size at each price level. The L2 book provides a consolidated view of market depth, with configurable levels and price aggregation for bandwidth optimization.
Code Examples Repository
Clone our complete examples: github.com/dwellir-public/hyperliquid-orderbook-server-code-examples
How to Subscribe
Send a subscription message to the WebSocket endpoint:
{
"method": "subscribe",
"subscription": {
"type": "l2Book",
"coin": "BTC",
"nSigFigs": 5,
"nLevels": 20,
"strict": true
}
}Subscription Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | Yes | - | Must be "l2Book" |
coin | string | Yes | - | Trading pair symbol (e.g., "BTC", "ETH", "xyz:MSTR", "@150") |
nSigFigs | number | No | 5 | Price aggregation: 2-5 significant figures |
nLevels | number | No | 20 | Number of levels per side: 1-100 |
strict | bool | No | False | Only send data on updates within the subscribed level interval |
HIP3 Markets
For HIP3 (permissionless perpetuals) markets, use the full coin label format with the xyz: prefix. For example, use "xyz:MSTR" for the MicroStrategy perpetual, not just "MSTR". Standard perpetuals like BTC and ETH do not require a prefix.
Spot Markets
For spot markets, use the @{index} format where the index is the spot asset index. For example, use "@150" for a specific spot market.
Understanding nSigFigs (Price Aggregation)
The nSigFigs parameter controls how prices are rounded for aggregation:
| nSigFigs | BTC Example | Effect |
|---|---|---|
| 5 | $106,217 | Most granular - individual price points |
| 4 | $106,200 | Moderate aggregation |
| 3 | $106,000 | Coarse aggregation |
| 2 | $110,000 | Very coarse - major levels only |
Lower nSigFigs values reduce message frequency and bandwidth but sacrifice price precision.
The first websocket message after subscribing is a subscriptionResponse; subsequent messages carry the l2Book payloads.
Response Field Reference
| Field | Type | Description |
|---|---|---|
channel | string | Always "l2Book" for this subscription type |
data.coin | string | Trading pair symbol |
data.time | number | Unix timestamp in milliseconds |
data.levels | array | Two-element array: [bids, asks] |
levels[0] | array | Bid levels (buyers), sorted best (highest) to worst |
levels[1] | array | Ask levels (sellers), sorted best (lowest) to worst |
Level Object Fields
| Field | Type | Description |
|---|---|---|
px | string | Price level |
sz | string | Total size at this price level |
n | number | Number of orders aggregated at this level |
Use Cases
Market Making
Monitor spread and depth to optimize quote placement:
- Spread monitoring: Track bid-ask spread for quote width
- Inventory management: Adjust quotes based on book imbalance
- Competition analysis: Count orders at each level to gauge competition
Liquidity Analysis
Assess market depth for large order execution:
- Slippage estimation: Calculate expected price impact for order sizes
- Best execution: Find optimal order sizes and timing
- Market quality metrics: Track spread, depth, and resilience
Support/Resistance Detection
Identify significant price levels from order concentration:
- Order clusters: Large
nvalues indicate many orders at a level - Size walls: High
szvalues suggest strong support/resistance - Level breaks: Monitor when significant levels get absorbed
Algorithmic Trading Signals
Generate trading signals from book dynamics:
- Imbalance signals: Buy when bids dominate, sell when asks dominate
- Spread compression: Trade when spread narrows (high liquidity)
- Depth changes: Alert on sudden liquidity additions or removals
Subscription Management
Adjusting Parameters
Change depth or aggregation by resubscribing:
# Switch from 20 levels to 50 levels
await websocket.send(json.dumps({
"method": "unsubscribe",
"subscription": {"type": "l2Book", "coin": "BTC", "nLevels": 20}
}))
await websocket.send(json.dumps({
"method": "subscribe",
"subscription": {"type": "l2Book", "coin": "BTC", "nLevels": 50}
}))Bandwidth Optimization
For high-frequency updates, use lower nSigFigs:
{
"method": "subscribe",
"subscription": {
"type": "l2Book",
"coin": "BTC",
"nSigFigs": 3,
"nLevels": 10
}
}This reduces message size and frequency while maintaining key price levels.
Get Access
Ready to integrate real-time Hyperliquid L2 order book data?
- Volume Calculator - Estimate monthly message volume
- Contact Sales - Get your WebSocket credentials
- Dashboard - Manage your subscription
Stream institutional-grade Hyperliquid order book data with Dwellir's ultra-low latency infrastructure.
Hyperliquid Order Book WebSocket API
High-performance WebSocket server providing real-time Hyperliquid order book data with ultra-low latency. Stream trades, L2 aggregated books, and L4 individual orders.
L4 Order Book
Stream Level 4 order book data from Hyperliquid with individual order visibility. Access user addresses, order IDs, timestamps, and full order parameters.