Dex
Understanding the hyperliquid dex
This a collection of extra documentation on the workings of Hyperliquid L1.
It is not exhaustive, rather it complements the Hyperliquid Docs.
For each section under Sources where the Parent is
- Datastreams then entity is the Kafka Topic name
- Snowflake then the entity is the table name
Assets
In a lot of the data sources, especially datastreams and tables in the raw schema you will find assets listed as a number.
This is how Hyperliquid refers to them. They are normally a trading Pair.
Where the asset is simply an index.
Perpetuals - index in the universe field returned by the meta
response.
Spot - 10000 + index in the universe field returned by the spotMeta
response.
For example, when submitting an order for PURR/USDC, the asset that should be used is 10000 because its asset index in the spot metadata is 0.
Spot
Spot Pairs are prefixed by an @
The Spot Pair PURR/USDC is the only one not referred to by an @index and instead you will see it referred by PURR/USDC
You can fetch the Hyperliquid Spot metadata here.
Samples
Looking at the universe section we can see a index 107
with name @107
@107
is what you will see in the hyperliquid data, and this refer to the trading pair HYPE/USDC
Perpetuals
You can fetch the Hyperliquid Perpetual metadata here.
Perpetuals are easier than Spot, as the name is the Token which trades against USDC.
For example
- HYPE will be HYPE/USDC.
- BTC will be BTC/USDC
Orders
For order types and options see the hyperliquid docs
Market order fills
- Sources
- Datastreams
- hyperliquid.orders
- hyperliquid.fills
- Snowflake
- hyperliquid.raw.orders
- Datastreams
- Filter by:
status = 'filled'
type = 'market'
Limit order fills
- Sources
- Datasteam
- hyperliquid.orders
- hyperliquid.fills
- Snowflake
- hyperliquid.raw.orders
- Datasteam
- Filter by
status = 'filled'
type = 'limit'
What are TWAP Orders?
It is an order which is divided into multiple suborders over a period of time set by user.
A suborder is sent every 30 seconds during the course of the TWAP.
TWAP stands for Time-Weighted Average Price.
In hyperliquid TWAPs are executed automatically by the validators and as such they do not have a transaction hash, only the order to place a twap has a transaction hash. As such you will very often see trades and fills with 0x0000000000000000000000000000000000000000000000000000000000000000
as the transaction hash.
For trades this means one side of the trade is a TWAP.
For fill this means it is a TWAP fill.
Twap fills
- Sources
- Datastreams
- hyperliquid.trades
- hyperliquid.fills
- Snowflake
- hyperliquid.raw.transactions
- Datastreams
- Filter by
hash = '0x0000000000000000000000000000000000000000000000000000000000000000'
Twap Open
- Sources
- Datastreams
- hyperliquid.transactions
- Snowflake
- hyperliquid.raw.transactions
- Datastreams
- Filter by
action:type = 'twapOrder'
Twap Cancel
- Sources
- Datastreams
- hyperliquid.transactions
- Snowflake
- hyperliquid.raw.transactions
- Datastreams
- Filter by
action:type = 'twapCancel'
Staking Activity
- Sources
- Datastream
- hyperliquid.misc_events
- Snowflake
- hyperliquid.raw.misc_events
- Datastream
- Filter by
inner: { CDeposit
for depositsinner: { CWithdrawal
for withdrawals
Liquidations
There are two types of liquidations in hyperliquid.
Market Liquidations
This is when Hyperliquid places an order to sell (for longs) and buy (for shorts) a user’s position on the market.
HLP Vault Liquidations
This is a last effort, when the above Market Liquidations fails, ie due to lack of liquidity. In this case the HLP Vault acquires the position, and takes the loss (if any).
Market Liquidations
- Datastreams
- hyperliquid.fills
- Snowflake
- hyperliquid.raw.fills
Market Liquidation Example
This will be wrapped in a payload key
HLP Vault Liquidations
- Sources
- Datastreams
- hyperliquid.misc_events
- hyperliquid.fills
- Snowflake
- hyperliquid.raw.misc_events
- hyperliquid.raw.fills
- Datastreams
The HLP Vault Liquidation shows up in both the misc events and the fills.
In the fills
it will show up with both sides, and one side being the HLP Vault.
Fills
Liquidated User Fill
HLP Vault Fill
Misc Events
Order Book
The easiest way to keep an updated order book is to read from the Datastream orders
and applying it to a snapshot of the L2 Orderbook.
Once you have the snapshot, you can use the orders
datastream to update the snapshot.
All the possible order statuses can be found in the Hyperliquid Docs
We are working on providing an L4 Orderbook snapshot.