For the complete documentation index, see llms.txt. This page is also available as Markdown.

L4 orderbook streaming

Maintain a real-time L4 orderbook locally using snapshot + delta sync.

How it works

  1. Subscribe to l4BookUpdates and buffer incoming updates

  2. Fetch L4PerpBookSnapshot snapshot with block height

  3. Apply buffered updates where height > snapshot_height

  4. Continue applying live updates

This gives you a complete L4 orderbook with user addresses for every resting order.

Use cases

  • HIP-3 liquidity incentives - monitor which users qualify for LP rewards based on their orderbook presence

  • BBO tracking - identify which users are providing best bid/offer

  • Market making - track your queue position, monitor competitor liquidity

  • Analytics - real-time orderbook metrics, spread analysis, depth tracking

SDK

The Hydromancer Python SDK handles sync automatically:

from hydromancer_sdk import L4OrderbookClient

client = L4OrderbookClient(coins=["ETH", "BTC"])
await client.run()

book = client.get_book("ETH")
print(book.best_bid_str(), book.best_ask_str())

See examples for streaming orderbook and validation usage. Use meta to call correct markets.

Manual implementation

If implementing without the SDK, handle the three diff types from l4BookUpdates:

  • new - insert order into book at price level, store oid, user, side, px, sz. If the diff carries insertBefore (an oid), splice the order into the level's queue immediately before that resting order instead of appending to the tail — this is how Hyperliquid's ALO priority (priority fees) expresses queue position. Fall back to tail-append if the target oid is not at the level. The SDK's L4OrderbookClient handles this automatically.

  • update - find order by oid, update sz (partial fill occurred)

  • remove - delete order by oid (filled or cancelled)

Maintain orders indexed by oid for fast lookups. Use sorted structures (e.g. sorted map) keyed by price for efficient BBO queries.

Important: Order matching is mandatory. When inserting new orders, run your matching engine to cross any orders that would trade (bid >= ask). Without matching, your book will become stale and show crossed markets.

Key details

  • Updates arrive per-block (~70ms block time)

  • Perp and spot markets are both included

  • Includes all resting limit orders with user addresses

  • Does not include untriggered stop/take-profit orders

Last updated