perpTwapSnapshot

Endpoint to get all active TWAP orders across all Hyperliquid perpetual markets.

💧New endpoint - this endpoint is not a part of original Hyperliquid API and is added by us for builder convenience.

Overview

perpTwapSnapshot endpoint allows you to access all active TWAP (Time-Weighted Average Price) orders on Hyperliquid perpetual markets. TWAPs are algorithmic orders that execute over time, splitting large orders into smaller pieces.

There are two ways to access the data:

  1. Metadata Endpoint (Fast): Check for updates without downloading data

  2. Snapshots Endpoint (Heavy): Download actual TWAP snapshot data

Efficient polling pattern

To minimize bandwidth and server load, you should:

  1. Poll the metadata endpoint to check for updates

  2. Only call the snapshots endpoint when data has changed

  3. Cache the snapshot ID locally to avoid unnecessary downloads

Dependencies and best practices

Dependencies

JavaScript

  • zstd: For decompression (e.g., fzstd, @gera2ld/zstd)

  • msgpack: For decoding (e.g., @msgpack/msgpack)

Python

  • zstd: For decompression (e.g., zstandard)

  • msgpack: For decoding (e.g., msgpack)

  • aiohttp: For async HTTP requests


Error handling
  • 404: No TWAP snapshots are available yet. Wait and retry.

  • 500: A server error occurred. Retry with exponential backoff.

  • Network errors: Implement retry logic with jitter to avoid overwhelming the server.

  • Parse errors: Log the issue and continue using cached data if available.

Perp TWAP Snapshot Metadata (Fast)

  • Endpoint: POST /info

  • Purpose: Check if TWAP snapshots have been updated

  • Response Time: ~1ms

Request

Response

Perp TWAP Snapshots (Heavy)

  • Endpoint: POST /info

  • Purpose: Download TWAP snapshot data

  • Response Time: ~50ms+

Request

Query Options (HIP-3 Multi-Dex)

Specific markets:

  • ["BTC", "ETH"] -> Defaults to the main dex

  • ["xyz:BTC", "vntl:ETH"] -> Specify DEX with dex:market format

All markets patterns:

  • ["ALL"] -> All TWAP markets from the main dex

  • ["ALL:xyz"] -> All TWAP markets from xyz DEX

  • ["ALL:ALL_DEXES"] -> All TWAP markets from all available DEXes

Mixed queries:

  • ["ALL", "ALL:xyz", "BTC"] -> All from main dex + all from xyz

  • ["ALL:xyz", "vntl:ETH"] -> All from xyz + specific ETH from vntls

Rules:

  1. ALL:ALL_DEXES takes precedence - if present, returns everything from all dexes

  2. Multiple ALL patterns allowed - one per dex

  3. Specific markets are filtered - if a dex is covered by an ALL pattern, specific markets from that dex are ignored

  4. No duplicates - each dex's ALL pattern is deduplicated

Response Headers

  • Single Market: x-payload-format: msgpack, Content-Encoding: zstd

  • Multiple Markets: x-payload-format: multi-zstd, x-compression: inner-zstd

Data Format

Single Market Response

Format: Raw zstd-compressed MessagePack data

Decompressed Structure:

Snapshot Array Format:

Index
Field
Description

0

snapshot_id

Snapshot identifier

1

market_name

Market name ("BTC" for main dex, "xyz:BTC" for HIP-3 dexes)

2

twaps

Array of TWAP tuples

TWAP Tuple Format:

Index
Field
Description

0

address

User address (hex string)

1

twap_id

TWAP ID (unique per user)

2

asset

Asset symbol (e.g., "BTC", "ETH")

3

is_buy

Direction: true = buy, false = sell

4

total_sz

Total size to execute (normalized)

5

executed_sz

Size already executed (normalized)

6

remaining_sz

Remaining size (total_sz - executed_sz)

7

executed_ntl

Notional value executed (USD)

8

progress_pct

Progress percentage (0-100)

9

duration_secs

Total TWAP duration in seconds

10

start_time_ms

TWAP creation timestamp (milliseconds since epoch)

11

reduce_only

Whether TWAP is reduce-only (boolean)

12

randomize

Whether execution timing is randomized (boolean)

13

next_slice_time

Next slice execution time (ISO timestamp string)

14

slice_number

Current slice number in execution

Multiple Markets Response

Format: Custom binary format with length prefixes

Binary Structure:

Each zstd_data blob, when decompressed, contains a single market's TWAP snapshot in the same array format as the single market response.

Implementation Examples

Note: Make sure to set HYDROMANCER_API_KEY in your .env file

Last updated