Zero to HYPE

T4 · Trading

Trading mechanics

How the clearinghouse prices, margins, funds and liquidates positions. Most of it is formulas, so most of it becomes workbenches.

LessonChecked against the live API on 22 Oct 2026

Read first

The official docs for this track.

Then

Tutorials and write-ups worth your time.

Build

Hands-on work for this track.

  • Lab: Funding and mark priceLive
  • Workbench: Margin and liquidation priceComing
  • Workbench: Fee tierComing
  • Project: Funding-rate scannerComing

Three prices, three jobs

Every perp has three prices, and each one drives something different.

metaAndAssetCtxs returns all of them. For BTC on Oct 22, 2026:

Field Value
oraclePx 84,712.9
markPx 84,674.0
midPx 84,674.5
impactPxs (bid, ask) 84,674.0, 84,675.0
premium −0.0447%
funding (predicted, per hour) 0.00054%

Funding, worked through

Funding is paid every hour, at one eighth of an 8-hour rate:

F = average premium + clamp(interest − average premium, −0.05%, +0.05%)
interest = 0.01% per 8 hours
hourly payment = position size × oracle price × F / 8

Check it with the BTC numbers above. The impact ask (84,675.0) is below the oracle (84,712.9), so the premium is (0 − 37.9) / 84,712.9 = −0.0447%, exactly the premium field.

The clamp explains the funding fields:

HIP-3 DEXs use a more responsive premium, the middle of the two impact prices against the oracle, so deployers can tune funding with their own multipliers (T7):

premium (HIP-3) = (impact bid + impact ask) / 2 / oracle − 1

Margin

Liquidations

A cross account becomes liquidatable when its value falls below the maintenance margin of its open positions. An isolated position is judged on its own margin.

  1. On the book first. Liquidations are sent as market orders, so anyone can take the flow and the trader keeps whatever margin remains. Positions over 100k USDC (10k on testnet) are liquidated 20% at a time.
  2. Backstop. Below two-thirds of maintenance margin, the liquidator vault, part of HLP, takes over the position. The maintenance margin is not returned.
  3. Auto-deleveraging. If an account’s value still goes negative, positions on the other side are closed in order of unrealized pnl and leverage, keeping the exchange solvent.

The liquidation price for a position:

liq price = price − side × margin available / size / (1 − l × side)
side = 1 for a long, −1 for a short;  l = 1 / maintenance leverage
margin available (cross) = account value − maintenance margin required

For a cross position, leverage doesn’t change the liquidation price; lower leverage only locks more collateral. For isolated positions it does, because the margin set aside depends on it.

Order types

Type What it does
Limit: GTC, IOC, ALO Rest on the book, fill-or-cancel the rest, or post-only (see T3)
Market Executes now, at the best prices available
Stop and take (market or limit) Activate at a trigger price. A stop to buy triggers above the mid; a take-profit to buy triggers below it.
TP/SL Attached to a position; market orders unless you set a limit price
Trailing stop Triggers when the mark price pulls back a set distance or percentage from its best level
TWAP Splits a large order into suborders at least 30 seconds apart, each with at most 3% slippage
Scale, chase Several limits across a range; a post-only order that follows the best bid or ask

Any order can be reduce-only, so it can shrink a position but never open or flip one.

Fees

Fee tiers depend on 14-day weighted volume, where spot volume counts double: perps volume + 2 × spot volume. Makers pay less than takers, and apps can add a builder fee on top of the exchange’s (T5). The full tables and the fee function for developers are on the fees page.