TP/SL heatmap streaming

Stream real-time trigger order (take profit / stop loss) updates and build heatmaps showing where TP/SL orders cluster at different price levels.

How it works

  1. Subscribe to tpslUpdates and buffer incoming updates

  2. Fetch tpslBook snapshot with block height

  3. Apply buffered updates where height > snapshot_height

  4. Continue applying live updates

Trigger orders are immutable β€” only add and remove diffs, no modifications. This makes the sync model simpler than L4 orderbooks (no partial fills, no matching required).

Use cases

  • TP/SL heatmaps β€” visualize where stop losses and take profits cluster relative to current price. Dense clusters = potential liquidation cascades or profit-taking zones.

  • Liquidation risk analysis β€” large clusters of stop losses below support indicate potential cascade risk

  • Smart money tracking β€” monitor where large accounts place their TP/SL levels

  • Position-level TP/SL monitoring β€” filter isPositionTpsl: true to see position-attached orders vs standalone triggers

  • Market microstructure research β€” study how TP/SL placement evolves relative to price action

SDK

The Hydromancer Python SDK handles sync automatically:

See examples/stream_tpsl.py for a complete streaming example.

Manual implementation

If implementing without the SDK, maintain a map of oid β†’ order per market:

  • add β€” insert or replace order by oid (idempotent upsert)

  • remove β€” delete order by oid

No matching or modification logic is needed. Every remove diff is terminal β€” just drop the order from your map. The reason field is informational (see tpslUpdates) and doesn't affect handling.

Building a heatmap

To build a trigger-order heatmap:

  1. Bucket by price β€” group orders by triggerPx into price buckets (e.g., $500 intervals for BTC)

  2. Weight by size β€” sum sz within each bucket for volume-weighted heatmap

  3. Split by type β€” separate take profits (orderType contains "Take Profit") from stop losses ("Stop") for distinct color layers

  4. Split by side β€” "A" (sell-side triggers, typically stop losses below price) vs "B" (buy-side triggers, typically take profits above price)

Key details

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

  • ~110K trigger orders across ~330 markets (typical for mainnet)

  • Block processing latency: ~20Β΅s p50 (near-instant)

  • Orders are fully immutable β€” no size or price changes after placement

  • isPositionTpsl: true = attached to a position (auto-cancel when position closes)

  • reduceOnly: true = almost all trigger orders (reduce-only by nature)

Differences from L4 orderbook

L4 orderbook
TPSL book

What

Resting limit orders on the book

Untriggered TP/SL orders

Diffs

new, update, remove

add, remove only

Modifications

Yes (partial fills change size)

No (immutable)

Matching

Required (crossed orders)

Not needed

Snapshot format

Binary (multi-zstd msgpack)

JSON

Typical count

~460K orders

~110K orders

Last updated