Trading Mechanics
Key Concepts
| ID | Term | Definition |
|---|---|---|
| 1 | Bid | A buy order in the order book. |
| 2 | Ask | A sell order in the order book. |
| 3 | Slippage | The difference between the expected price and the actual average execution price. |
| 4 | Market order | Order that executes immediately against available liquidity. |
| 5 | Limit order | Order that executes at the selected price or better. |
| 6 | Stop order | Order that becomes active only after a trigger price is reached. |
| 7 | Take Profit | Order used to close a position when a profit target is reached. |
| 8 | Stop Loss | Order used to close a position when a loss threshold is reached. |
| 9 | TWAP | Time-weighted average price order. A large order split into smaller suborders over time. |
| 10 | Cross margin | Margin mode where collateral is shared across cross positions. |
| 11 | Isolated margin | Margin mode where collateral is limited to one asset or position. |
| 12 | Leverage | Allows a user to open a position larger than the margin posted. |
| 13 | Maintenance margin | Minimum margin required to keep a position open. |
| 14 | Liquidation | Process of closing a position when margin is no longer sufficient. |
| 15 | GTC | Good Til Cancel - Order option where the order stays on the order book until it is filled or canceled. |
| 16 | IOC | Immediate or Cancel - Order option where the order executes immediately as much as possible, and any unfilled size is canceled. |
| 17 | EMA | Exponential Moving Average. A smoothed average that reacts more to recent price changes. |
| 18 | HIP-3 | Hyperliquid Improvement Proposal 3. |
1. Summary
This document explains the following trading mechanics using Hyperliquid as the reference:
- Order types: Market, Limit, Stop Market, Stop Limit, Take Market, Take Limit, Scale, TWAP
- Strategies: Take Profit, Stop Loss
- Account modes
- Margin modes
- Leverage
- Liquidations
- Funding
2. Order Types
2.1 Market Order
An order that executes immediately at the current market price.
A buy market order consumes asks from the lowest price upward. A sell market order consumes bids from the highest price downward.
The final execution price is not necessarily the best bid or best ask. If the order size is larger than the liquidity available at the best price, the order continues matching against the next price levels.
The average execution price is calculated as:
average_execution_price = sum(fill_price * fill_size) / total_filled_size
2.1.1 Example: Market Order
Order:
| Side | Size |
|---|---|
| Buy | 4 BTC |
Ask book:
| Price | Available size |
|---|---|
| 100,000 | 1 BTC |
| 100,100 | 2 BTC |
| 100,200 | 3 BTC |
Execution:
| Fill price | Fill size | Fill value |
|---|---|---|
| 100,000 | 1 BTC | 100,000 |
| 100,100 | 2 BTC | 200,200 |
| 100,200 | 1 BTC | 100,200 |
| Total | 4 BTC | 400,400 |
The average execution price is the weighted average of all fills:
average_execution_price = sum(fill_price * fill_size) / total_filled_size
Applying it to the example:
average_execution_price = 400,400 / 4
average_execution_price = 100,100
So even though the best ask was 100,000, the market order executed at an average price of 100,100 because it consumed multiple ask levels.
2.1.2 Slippage
For a buy market order:
slippage = average_execution_price - best_ask
In this example:
slippage = 100,100 - 100,000
slippage = 100 (0.10%)
2.2 Limit Order
A limit order executes at the selected limit price or better.
For a buy limit order, the order can execute at the limit price or lower.
For a sell limit order, the order can execute at the limit price or higher.
On Hyperliquid, limit orders interact with the order book using price-time priority. If the order can immediately match against existing liquidity at a defined price, it executes. If it cannot fully execute and the order type allows resting, the remaining size stays on the order book.
The main difference from a market order is that a limit order protects the execution price, but it may not fully fill.
2.2.1 Example: Limit Order
Order:
| Side | Size | Limit price |
|---|---|---|
| Buy | 4 BTC | 100,100 |
Ask book:
| Price | Available size |
|---|---|
| 100,000 | 1 BTC |
| 100,100 | 2 BTC |
| 100,200 | 3 BTC |
Because this is a buy limit order with a limit price of 100,100, it can only execute at 100,100 or lower.
Execution:
| Fill price | Fill size | Fill value |
|---|---|---|
| 100,000 | 1 BTC | 100,000 |
| 100,100 | 2 BTC | 200,200 |
| Total filled | 3 BTC | 300,200 |
The order does not execute at 100,200, because that price is above the user’s limit price.
Remaining order:
| Remaining size | Resting price |
|---|---|
| 1 BTC | 100,100 |
If the order is GTC, the remaining 1 BTC stays on the order book until it is filled or canceled.
If the order is IOC, the remaining 1 BTC is canceled immediately.
The average execution price is the weighted average of all filled amounts:
average_execution_price = sum(fill_price * fill_size) / total_filled_size
Applying it to the example:
average_execution_price = 300,200 / 3
average_execution_price = 100,066.67
So even though the user set a limit price of 100,100, the average execution price was 100,066.67, because part of the order filled at a better price.
2.2.2 Price Protection
For a buy limit order:
execution_price <= limit_price
For a sell limit order:
execution_price >= limit_price
In this example:
average_execution_price = 100,066.67
limit_price = 100,100
100,066.67 <= 100,100
So the limit order respected the user’s maximum acceptable buy price.
2.2.3 Main Risk
The main risk of a limit order is partial fill or no fill.
Market order = prioritizes execution.
Limit order = prioritizes price.
2.3 Stop Market Order
A stop market order is a trigger order. It stays inactive until the selected trigger price is reached. Once triggered, it becomes a market order.
On Hyperliquid, for a long stop market order, the trigger price must be above the current mid price. For a short stop market order, the trigger price must be below the current mid price.
Trigger price reached
↓
Stop market order activates
↓
Market order is sent
↓
Order executes against available liquidity
The main idea is that the user defines when the order should activate, but not the exact execution price after activation. Once triggered, execution works like a normal market order, so the final price depends on the liquidity available in the order book.
2.3.1 Example: Stop Market Order
Initial market state:
| Current mid price |
|---|
| 99,800 |
Order:
| Side | Size | Trigger price |
|---|---|---|
| Buy | 4 BTC | 100,000 |
When the price reaches 100,000, the stop market order is triggered and becomes a market order.
Ask book at trigger time:
| Price | Available size |
|---|---|
| 100,000 | 1 BTC |
| 100,100 | 2 BTC |
| 100,200 | 3 BTC |
Execution:
| Fill price | Fill size | Fill value |
|---|---|---|
| 100,000 | 1 BTC | 100,000 |
| 100,100 | 2 BTC | 200,200 |
| 100,200 | 1 BTC | 100,200 |
| Total | 4 BTC | 400,400 |
The average execution price is calculated the same way as a normal market order:
average_execution_price = sum(fill_price * fill_size) / total_filled_size
Applying it to the example:
average_execution_price = 400,400 / 4
average_execution_price = 100,100
So even though the trigger price was 100,000, the order executed at an average price of 100,100 because, after being triggered, it became a market order and consumed multiple ask levels.
2.3.2 Slippage
For a buy stop market order, slippage can be measured against the trigger price or the best ask at trigger time.
slippage = average_execution_price - trigger_price
In this example:
slippage = 100,100 - 100,000
slippage = 100 (0.10%)
2.3.3 Main Risk
The main risk of a stop market order is that the trigger price is not guaranteed to be the execution price.
Stop Market = activate at trigger price, then execute immediately as a market order.
This gives high execution probability after the trigger, but it can suffer from slippage if liquidity is thin or the market moves quickly.
2.4 Stop Limit Order
A stop limit order is a trigger order. It stays inactive until the selected trigger price is reached. Once triggered, it becomes a limit order.
This means the user defines two prices:
| Price | Meaning |
|---|---|
| Trigger price | The price that activates the order. |
| Limit price | The maximum price for a buy, or the minimum price for a sell, after the order is activated. |
Trigger price reached
↓
Stop limit order activates
↓
Limit order is placed
↓
Order executes only at the limit price or better
The main difference from a stop market order is that a stop limit order protects the execution price, but it may not fully fill.
2.4.1 Example: Stop Limit Order
Initial market state:
| Current mid price |
|---|
| 99,800 |
Order:
| Side | Size | Trigger price | Limit price |
|---|---|---|---|
| Buy | 4 BTC | 100,000 | 100,100 |
When the price reaches 100,000, the stop limit order is triggered and becomes a buy limit order at 100,100.
Ask book at trigger time:
| Price | Available size |
|---|---|
| 100,000 | 1 BTC |
| 100,100 | 2 BTC |
| 100,200 | 3 BTC |
Because this is a buy limit order with a limit price of 100,100, it can only execute at 100,100 or lower.
Execution:
| Fill price | Fill size | Fill value |
|---|---|---|
| 100,000 | 1 BTC | 100,000 |
| 100,100 | 2 BTC | 200,200 |
| Total filled | 3 BTC | 300,200 |
The order does not execute at 100,200, because that price is above the user’s limit price.
Remaining order:
| Remaining size | Resting price |
|---|---|
| 1 BTC | 100,100 |
If the order is GTC, the remaining 1 BTC stays on the order book until it is filled or canceled.
If the order is IOC, the remaining 1 BTC is canceled immediately.
The average execution price is the weighted average of all fills:
average_execution_price = sum(fill_price * fill_size) / total_filled_size
Applying it to the example:
average_execution_price = 300,200 / 3
average_execution_price = 100,066.67
So even though the trigger price was 100,000 and the limit price was 100,100, the order executed at an average price of 100,066.67, because part of the order filled at a better price.
2.4.2 Price Protection
For a buy stop limit order:
execution_price <= limit_price
In this example:
100,066.67 <= 100,100
So the order respected the user’s maximum acceptable buy price.
For a sell stop limit order:
execution_price >= limit_price
2.4.3 Main Risk
The main risk of a stop limit order is partial fill or no fill.
Stop Market = trigger reached, then execute immediately as a market order.
Stop Limit = trigger reached, then place a limit order with price protection.
A stop limit order gives more control over the execution price, but it does not guarantee execution.
2.5 Take Market and Take Limit Orders
Take orders are trigger orders used to close a position when a profit target is reached.
On Hyperliquid, TP/SL orders are triggered by the mark price. A Take Market order becomes a market order after the trigger price is reached. A Take Limit order becomes a limit order after the trigger price is reached.
Take Market → trigger reached → market order is sent
Take Limit → trigger reached → limit order is placed
The main difference is execution behavior:
| Type | Behavior | Main risk |
|---|---|---|
| Take Market | Executes immediately after being triggered. | Slippage. |
| Take Limit | Executes only at the limit price or better. | Partial fill or no fill. |
2.5.1 Example: Take Market Order
Position:
| Side | Size | Entry price |
|---|---|---|
| Long | 4 BTC | 100,000 |
Order:
| Type | Trigger price |
|---|---|
| Take Market | 110,000 |
When the mark price reaches 110,000, the Take Market order is triggered and becomes a sell market order to close the long position.
Bid book at trigger time:
| Price | Available size |
|---|---|
| 110,000 | 1 BTC |
| 109,900 | 2 BTC |
| 109,800 | 3 BTC |
Because this is a sell market order, it consumes bids from the highest price downward.
Execution:
| Fill price | Fill size | Fill value |
|---|---|---|
| 110,000 | 1 BTC | 110,000 |
| 109,900 | 2 BTC | 219,800 |
| 109,800 | 1 BTC | 109,800 |
| Total | 4 BTC | 439,600 |
The average execution price is the weighted average of all fills:
average_execution_price = sum(fill_price * fill_size) / total_filled_size
Applying it to the example:
average_execution_price = 439,600 / 4
average_execution_price = 109,900
So even though the trigger price was 110,000, the order executed at an average price of 109,900 because, after being triggered, it became a market order and consumed multiple bid levels.
Slippage:
slippage = trigger_price - average_execution_price
Applying it to the example:
slippage = 110,000 - 109,900
slippage = 100 (0.09%)
2.5.2 Example: Take Limit Order
Position:
| Side | Size | Entry price |
|---|---|---|
| Long | 4 BTC | 100,000 |
Order:
| Type | Trigger price | Limit price |
|---|---|---|
| Take Limit | 110,000 | 109,900 |
When the mark price reaches 110,000, the Take Limit order is triggered and becomes a sell limit order at 109,900.
Bid book at trigger time:
| Price | Available size |
|---|---|
| 110,000 | 1 BTC |
| 109,900 | 2 BTC |
| 109,800 | 3 BTC |
Because this is a sell limit order with a limit price of 109,900, it can only execute at 109,900 or higher.
Execution:
| Fill price | Fill size | Fill value |
|---|---|---|
| 110,000 | 1 BTC | 110,000 |
| 109,900 | 2 BTC | 219,800 |
| Total filled | 3 BTC | 329,800 |
The order does not execute at 109,800, because that price is below the user’s limit price.
Remaining order:
| Remaining size | Resting price |
|---|---|
| 1 BTC | 109,900 |
If the order is GTC, the remaining 1 BTC stays on the order book until it is filled or canceled.
If the order is IOC, the remaining 1 BTC is canceled immediately.
The average execution price is:
average_execution_price = 329,800 / 3
average_execution_price = 109,933.33
So even though the trigger price was 110,000 and the limit price was 109,900, the average execution price was 109,933.33, because part of the order filled at a better price.
2.5.3 Price Protection
For a sell Take Limit order:
execution_price >= limit_price
In this example:
109,933.33 >= 109,900
So the order respected the user’s minimum acceptable sell price.
For a buy Take Limit order, usually used to close a short position:
execution_price <= limit_price
2.5.4 Main Risk
Take Market = more likely to execute, but can suffer slippage.
Take Limit = protects price, but may partially fill or not fill.
2.6 Scale Order
TBD
2.7 TWAP Orders
TBD
2.8 Order Types Comparison
| Order type | Trigger needed? | What happens when active? | User controls | Main benefit | Main risk | Typical use |
|---|---|---|---|---|---|---|
| Market Order | No | Executes immediately against available liquidity | Size and side | Highest execution probability | Slippage. | Enter or exit a position quickly |
| Limit Order | No | Executes only at the limit price or better. If not fully filled, the remaining size may rest on the order book depending on the order option. | Size, side and limit price. | Price protection. | Partial fill or no fill | Enter or exit at a specific price |
| Stop Market Order | Yes | When the trigger price is reached, it becomes a market order | Size, side and trigger price | High execution probability after trigger | Trigger price is not guaranteed as execution price; slippage can occur. | Breakout entry or stop loss with priority on execution. |
| Stop Limit Order | Yes | When the trigger price is reached, it becomes a limit order | Size, side, trigger price and limit price | Trigger logic with price protection | Partial fill or no fill after trigger | Breakout entry or stop loss with controlled execution price |
| Take Market Order | Yes | When the profit target is reached, it becomes a market order to close the position | Position size, trigger price and side | More likely to close the position once profit target is reached. | Slippage after trigger | Take profit with priority on execution |
| Take Limit Order | Yes | When the profit target is reached, it becomes a limit order to close the position | Position size, trigger price, limit price and side | Takes profit with price protection | Partial fill or no fill | Take profit while controlling the minimum acceptable execution price |
3. Strategies
TP/SL orders close a position when a profit or loss condition is reached.
Hyperliquid uses mark price to trigger TP/SL orders.
3.1 Take Profit
A Take Profit order is used to close a position when the trade reaches a profit target.
For a long position, the Take Profit trigger is above the entry price.
Long position: Take Profit triggers when mark_price >= take_profit_price
For a short position, the Take Profit trigger is below the entry price.
Short position: Take Profit triggers when mark_price <= take_profit_price
3.1.1 Example: Long Take Profit
Position:
| Side | Size | Entry price |
|---|---|---|
| Long | 1 BTC | 100,000 |
Take Profit:
| Trigger price |
|---|
| 110,000 |
Trigger condition:
mark_price >= 110,000
If the mark price reaches 110,000, the Take Profit order is activated and attempts to close the position.
3.1.2 Profit Calculation
For a long position:
profit = (exit_price - entry_price) * position_size
Applying it to the example:
profit = (110,000 - 100,000) * 1
profit = 10,000 USDC
Before fees and funding, the trade has 10,000 USDC of profit.
3.2 Stop Loss
A Stop Loss order is used to close a position when the trade reaches a loss threshold.
For a long position, the Stop Loss trigger is below the entry price.
Long position: Stop Loss triggers when mark_price <= stop_loss_price
For a short position, the Stop Loss trigger is above the entry price.
Short position: Stop Loss triggers when mark_price >= stop_loss_price
3.2.1 Example: Long Stop Loss
Position:
| Side | Size | Entry price |
|---|---|---|
| Long | 1 BTC | 100,000 |
Stop Loss:
| Trigger price |
|---|
| 95,000 |
Trigger condition:
mark_price <= 95,000
If the mark price reaches 95,000, the Stop Loss order is activated and attempts to close the position.
3.2.2 Loss Calculation
For a long position:
loss = (exit_price - entry_price) * position_size
Applying it to the example:
loss = (95,000 - 100,000) * 1
loss = -5,000 USDC
Before fees and funding, the trade has 5,000 USDC of loss.
3.3 TP/SL Market vs TP/SL Limit
TP/SL orders can be configured as market or limit orders.
| Type | Trigger condition | After trigger | Slippage control | Main benefit | Main risk |
|---|---|---|---|---|---|
| TP/SL Market | Mark price reaches the trigger price | A market order is sent | Fixed 10% slippage tolerance | Higher chance of execution | Slippage |
| TP/SL Limit | Mark price reaches the trigger price | A limit order is placed. | User controls slippage through the limit price. | Price protection. | Partial fill or no fill |
For TP/SL market orders, Hyperliquid applies a fixed 10% slippage tolerance. This means the order triggers at the trigger price, but the final execution can move within that tolerance depending on available liquidity in the order book.
For TP/SL limit orders, the user controls the maximum acceptable slippage through the limit price. A more aggressive limit price increases the chance of filling after the trigger, but it also allows more potential slippage.
4. Account Abstraction Modes
Account abstraction mode defines how a user’s spot balances, perp balances and collateral interact.
In Hyperliquid, the modes are:
- Unified Account
- Portfolio Margin
- Manual / Standard
4.1 Unified Account
Unified Account is the default and recommended mode for most users.
In this mode, each collateral asset has a single balance. That balance can be used across spot and perps that use the same collateral asset.
Unified Account =
one balance per collateral asset
+ spot and perps are unified for that asset
+ cross margin is shared across DEXs with the same collateral
Example:
| Asset | Used for |
|---|---|
| USDC balance | USDC-settled perps and USDC spot quote trading |
| USDH balance | USDH-settled perps and USDH spot quote trading |
The important detail is that margin is shared only across cross-margin positions that use the same collateral asset.
USDC collateral supports USDC-settled cross positions.
USDH collateral supports USDH-settled cross positions.
So unified account improves usability and capital efficiency, but it does not mean every asset backs every position.
4.2 Portfolio Margin
Portfolio Margin is the most capital-efficient mode, but it is designed for advanced users and is still more restricted.
In portfolio margin, eligible spot assets and perp positions are margined together as one portfolio.
Portfolio Margin =
spot balances
+ perp positions
+ eligible collateral assets
+ portfolio-level margin calculation
Eligible collateral assets can include assets such as:
HYPE
BTC
USDH
USDC
The key difference from unified account is that portfolio margin can use eligible non-settlement assets as collateral.
Example:
A user holds 1 BTC in spot and opens a short BTC perp.
In a normal margin system, the perp position may need settlement collateral such as USDC.
In portfolio margin, the BTC spot balance and the BTC perp position can offset each other economically.
BTC spot position gains when BTC goes up.
BTC short perp gains when BTC goes down.
Together, they can reduce portfolio risk.
This makes strategies like carry trades more capital efficient, because spot and perp exposure can be considered together.
4.2.1 Portfolio Margin Liquidation
Portfolio margin liquidation is based on the whole portfolio, not only one DEX or one isolated position.
Portfolio margin liquidation =
entire portfolio value
vs
portfolio maintenance margin requirement
So instead of checking only one position, the system checks whether the whole portfolio is sufficiently collateralized.
4.3 Manual / Standard Mode
This mode is mainly recommended for automated traders, market makers, high-volume users and builders.
In this mode:
Manual / Standard =
separate spot and perp balances
+ separate DEX balances
+ cross margin applies separately within each DEX
Example:
| DEX | Balance behavior | Cross margin scope |
|---|---|---|
| DEX A | Separate balance | Cross margin only inside DEX A |
| DEX B | Separate balance | Cross margin only inside DEX B |
This gives more manual control, but it is less intuitive for normal users because balances and margin are not automatically unified across the account.
4.4 Account Mode Comparison
| Account mode | Recommended for | Balance model | Cross-margin behavior | Main benefit | Main risk / limitation |
|---|---|---|---|---|---|
| Unified Account | Most users | One balance per collateral asset | Shared across DEXs with the same collateral asset | Easier UX and better capital efficiency than separated balances | Collateral is still separated by asset |
| Portfolio Margin | Advanced users | Eligible spot and perp positions are margined together | Portfolio-level margin | Highest capital efficiency | More complex and subject to eligibility/caps |
| Manual / Standard | Automated traders, market makers, builders | Separate spot, perp and DEX balances | Cross margin applies separately within each DEX | More explicit control | Less intuitive and less unified |
5. Margin Modes
Margin is the collateral that supports a perp position.
When a user opens a position, they do not need to pay the full notional value of the trade. Instead, they post margin. This margin acts as collateral against losses and determines how much risk the position can absorb before it becomes liquidatable.
position_notional = abs(position_size) * mark_price
initial_margin = position_notional / leverage
Example:
| Item | Value |
|---|---|
| Position size | 1 BTC |
| Mark price | 100,000 |
| Leverage | 10x |
position_notional = 1 * 100,000
position_notional = 100,000 USDC
initial_margin = 100,000 / 10
initial_margin = 10,000 USDC
This means the user controls a 100,000 USDC position with 10,000 USDC of margin.
Hyperliquid supports:
- Cross margin
- Isolated margin
- Strict isolated margin
- HIP-3 margin mode
5.1 Cross Margin
Cross margin is the default margin mode on Hyperliquid. In cross margin, collateral is shared across all cross-margin positions. This means available collateral and unrealized PnL can support multiple positions.
5.1.1 Example
Account:
| Item | Value |
|---|---|
| USDC collateral | 20,000 |
| BTC unrealized PnL | +3,000 |
| ETH unrealized PnL | -2,000 |
Account value:
account_value = collateral + unrealized_pnl
account_value = 20,000 + 3,000 - 2,000
account_value = 21,000
In cross margin, this 21,000 USDC account value can support all cross-margin positions.
5.1.2 Main Benefit
Cross margin = higher capital efficiency
Unused collateral and positive unrealized PnL can help support other positions.
5.1.3 Main Risk
Cross margin = shared liquidation risk
A large loss in one position can reduce the margin available for the whole cross account.
5.2 Isolated Margin
Isolated margin limits collateral to one specific position or asset.
This means the liquidation risk is isolated to that position.
5.2.1 Example
Account:
| Position | Margin mode | Allocated margin |
|---|---|---|
| BTC long | Isolated | 10,000 |
| ETH long | Cross | Shared account margin |
If the BTC isolated position is liquidated, only the BTC isolated margin and position are affected. The cross-margin account and other isolated positions are not affected.
5.2.2 Main Benefit
Isolated margin = limited risk per position
5.2.3 Main Risk
Isolated margin = lower capital efficiency
5.3 Strict Isolated Margin
Strict isolated margin is a protocol-level restriction used by Hyperliquid for some assets.
It works like normal isolated margin, but with one additional constraint: margin cannot be manually removed from the position. The goal is to reduce protocol risk by preventing users from manually reducing the collateral behind a position.
For example, if an asset is marked as strict isolated by Hyperliquid, the user can still reduce or close the position, but cannot manually withdraw margin from that position. Margin is only removed proportionally as the position size is reduced or closed.
5.4 HIP-3 Margin Modes
HIP-3 allows builders to create their own perpetual markets inside Hyperliquid.
A HIP-3 DEX is not an external DEX like Jupiter or Drift. It runs inside Hyperliquid and can have its own markets, collateral asset, leverage limits and margin rules.
Examples of HIP-3 DEXs are HyENA and trade.xyz.
Users may have perp positions across different HIP-3 DEXs, and because of that, cross margin depends on:
- the DEX
- the collateral asset
- the user's account mode
In Unified Account and Portfolio Margin, cross-margin positions can share margin across different HIP-3 DEXs if they use the same collateral asset.
Same collateral asset = same cross-margin pool
Different collateral asset = separate margin pool
Example:
| DEX | Collateral | Position | Margin pool |
|---|---|---|---|
| DEX A | USDC | BTC perp | USDC cross-margin pool |
| DEX B | USDC | ETH perp | ETH cross-margin pool |
| DEX C | USDH | SOL perp | USDH cross-margin pool |
In this example, the BTC and ETH positions can share margin because both use USDC.
The SOL position uses USDH, so it has a separate margin pool.
The shared cross-margin pool can be represented as:
cross_margin_pool_value = collateral_balance + sum(unrealized_pnl_of_positions_using_same_collateral)
In Manual Account, cross margin is separated by DEX. This means that even if two positions use the same collateral asset, they do not share margin if they are in different DEXs.
HIP-3 DEXs can also support no-cross margin mode. In this mode, the position does not share collateral with other positions. It behaves like isolated-style margin, but margin removal is still allowed if the remaining margin requirements are satisfied.
HIP-3 no-cross =
isolated-style margin
+ margin removal allowed
+ no cross margin
5.4.1 Summary
| Mode | Margin sharing | Margin pool |
|---|---|---|
| Unified / Portfolio | Shared across HIP-3 DEXs if same collateral | Grouped by collateral asset |
| Standard / Manual | Shared only inside the same DEX | Grouped by DEX |
| HIP-3 no-cross | Not shared | Dedicated to the position |
5.4.2 Margin Modes Comparison
| Margin mode | Collateral scope | Cross margin | Margin shared across DEXs | Margin removal | Capital efficiency | Risk isolation | Main idea |
|---|---|---|---|---|---|---|---|
| Cross margin | Shared across cross positions | Yes | Depends on account mode: unified/portfolio can share across DEXs with the same collateral; manual shares only within each DEX | Subject to margin requirements | High | Low | Maximizes capital efficiency, but losses in one position can affect the shared margin pool |
| Isolated margin | Dedicated to one position | No | No | Yes, if margin requirements remain satisfied | Lower | High | Limits liquidation risk to a specific position |
| Strict isolated margin | Dedicated to one position | No | No | No manual removal | Lower | High | More conservative isolated margin controlled by the protocol. Margin is removed proportionally as the position is reduced or closed |
| HIP-3 no-cross | Isolated-style margin for HIP-3 DEXs | No | No | Yes, if margin requirements remain satisfied | Lower | High | Allows isolated-style margin with margin removal, but disables cross-margin sharing |
6. Leverage
Leverage allows a trader to open a position larger than the margin they post.
The user does not need to provide the full notional value of the position. Instead, they provide an initial margin amount, and leverage defines the relationship between margin and position size.
position_notional = abs(position_size) * mark_price
initial_margin = position_notional / leverage
Equivalent formula:
initial_margin = abs(position_size) * mark_price / leverage
On Hyperliquid, users can set leverage to any integer between 1x and the asset’s max leverage.
The max leverage is not the same for every asset. It depends on:
asset
notional position size
margin tier
This means larger positions can have lower max leverage, because they create more risk for the protocol.
For example, BTC can have up to 40x max leverage for smaller notional sizes, but max leverage is reduced for larger BTC positions according to the margin tier.
The implementation rule is:
selected_leverage <= max_leverage_for_asset_and_notional
To open a position, the system needs to check:
1. Calculate position_notional: position_notional = abs(position_size) * mark_price
2. Get the max leverage for that asset and notional size.
3. Check: selected_leverage <= max_leverage
4. Calculate required initial margin: initial_margin = position_notional / selected_leverage
5. Check: available_margin >= initial_margin
7. Margin Tiers and Maintenance Margin
Margin tiers define how much margin a position needs as its size increases.
On Hyperliquid, larger positions can move into higher margin tiers. Higher tiers reduce max leverage and increase maintenance margin requirements.
7.1 Maintenance Margin
Maintenance margin is the minimum margin required to keep a position open.
The formula is:
maintenance_margin = notional_position_value * maintenance_margin_rate - maintenance_deduction
Where:
notional_position_value = abs(position_size) * mark_price
7.2 Maintenance Margin Rate
The maintenance margin rate is half of the initial margin rate at max leverage.
maintenance_margin_rate = initial_margin_rate_at_max_leverage / 2
Since:
initial_margin_rate_at_max_leverage = 1 / max_leverage
Then:
maintenance_margin_rate = (1 / max_leverage) / 2
7.3 Example: 20x Max Leverage
max_leverage = 20x
Initial margin rate at max leverage:
initial_margin_rate = 1 / 20
initial_margin_rate = 5%
Maintenance margin rate:
maintenance_margin_rate = 5% / 2
maintenance_margin_rate = 2.5%
Position:
| Item | Value |
|---|---|
| Notional position value | 100,000 |
| Maintenance margin rate | 2.5% |
| Maintenance deduction | 0 |
Maintenance margin:
maintenance_margin = 100,000 * 2.5% - 0
maintenance_margin = 2,500 USDC
If the position falls below this maintenance margin, it becomes liquidatable.
7.4 Maintenance Deduction
Maintenance deduction exists to make maintenance margin continuous across tiers.
For tier 0:
maintenance_deduction = 0
For tier n:
maintenance_deduction_n = maintenance_deduction_(n-1) + lower_bound_n * (maintenance_margin_rate_n - maintenance_margin_rate_(n-1))
The system needs to:
1. Calculate position notional.
2. Find the correct tier.
3. Get maintenance margin rate for that tier.
4. Get maintenance deduction for that tier.
5. Apply the maintenance margin formula.
8. Liquidations
A liquidation happens when a trader no longer has enough margin to support their position.
8.1 Cross Margin Liquidation Condition
For cross margin, the whole cross account is considered.
account_value < maintenance_margin_required
Where:
account_value = collateral + unrealized_pnl
And:
maintenance_margin_required = sum(maintenance_margin_for_each_cross_position)
So, cross margin liquidation happens when:
collateral + unrealized_pnl < sum(maintenance_margin_for_each_cross_position)
8.2 Example: Cross Margin Liquidation
Account:
| Item | Value |
|---|---|
| Collateral | 10,000 |
| Unrealized PnL | -8,000 |
Account value:
account_value = 10,000 - 8,000
account_value = 2,000
Maintenance margin required:
| Item | Value |
|---|---|
| Required maintenance margin | 2,500 |
Liquidation check:
account_value < maintenance_margin_required
2,000 < 2,500
true
The account is liquidatable.
8.3 Isolated Margin Liquidation Condition
For isolated margin, only the isolated position and isolated margin are considered.
isolated_margin < maintenance_margin_required
The rest of the user’s cross account does not support the isolated position.
8.4 Hyperliquid Liquidation Flow
When an account becomes liquidatable, Hyperliquid first attempts to close the position through market orders on the order book.
Account equity falls below maintenance margin
↓
Liquidation market orders are sent to the order book
↓
If enough position is closed:
margin requirements may be restored
↓
If margin requirements are restored:
remaining collateral stays with the trader
If the account falls below 2/3 of maintenance margin and the order-book liquidation is not enough, the liquidation can be backstopped through the liquidator vault.
account_equity < 2/3 * maintenance_margin_required
↓
backstop liquidation through liquidator vault
8.5 Partial Liquidations
For liquidatable positions larger than 100k USDC, Hyperliquid first sends only 20% of the position as a market liquidation order.
partial_liquidation_size = position_size * 20%
Example:
| Position size | Partial liquidation |
|---|---|
| 10 BTC | 2 BTC |
After a partial liquidation, there is a 30 second cooldown. During this cooldown, future market liquidation orders for that user can target the entire position.
8.6 Liquidation Price
The liquidation price is the price where the position/account becomes liquidatable.
Hyperliquid’s formula is:
liq_price = price - side * margin_available / position_size / (1 - l * side)
Where:
side = 1 for long
side = -1 for short
l = 1 / maintenance_leverage
For cross margin:
margin_available = account_value - maintenance_margin_required
For isolated margin:
margin_available = isolated_margin - maintenance_margin_required
8.7 Example: Long Liquidation Price
Position:
| Item | Value |
|---|---|
| Side | Long |
| Current price | 100,000 |
| Position size | 1 BTC |
| Margin available | 10,000 |
| Maintenance leverage | 40 |
Values:
side = 1
l = 1 / 40 = 0.025
Formula:
liq_price = mprice - side * margin_available / position_size / (1 - l * side)
Apply values:
liq_price = 100,000 - 1 * 10,000 / 1 / (1 - 0.025 * 1)
liq_price = 100,000 - 10,000 / 0.975
liq_price = 100,000 - 10,256.41
liq_price = 89,743.59
So the estimated liquidation price is 89,743.59.
9. Mark Price
Mark price is the reference price used by Hyperliquid for margining, liquidations, TP/SL triggers and unrealized PnL.
The goal of the mark price is to avoid relying only on the last traded price or on a single order book price, which could be easier to manipulate.
Hyperliquid calculates mark price using a price index based on three inputs:
1. Oracle price adjusted by an EMA of the difference between Hyperliquid mid price and oracle price
2. Median(best bid, best ask, last trade on Hyperliquid)
3. Median of external perp mid prices from major exchanges
The final mark price is the median of these inputs.
mark_price = median(candidate_1, candidate_2, candidate_3)
Where:
candidate_1 = oracle_price + EMA(hyperliquid_mid_price - oracle_price)
candidate_2 = median(best_bid, best_ask, last_trade)
candidate_3 = median(external_perp_mid_prices)
Hyperliquid’s mark price logic:
1. Get oracle price.
2. Get Hyperliquid order book data:
best_bid
best_ask
last_trade
3. Get external perp mid prices.
4. Compute: candidate_1 = oracle_price + EMA(hyperliquid_mid_price - oracle_price)
5. Compute: candidate_2 = median(best_bid, best_ask, last_trade)
6. Compute: candidate_3 = median(external_perp_mid_prices)
7. Final mark price: mark_price = median(candidate_1, candidate_2, candidate_3)
10. Funding
Funding is the mechanism that helps keep the perp price close to the underlying spot/oracle price.
It is a peer-to-peer payment between traders:
Positive funding → longs pay shorts
Negative funding → shorts pay longs
Hyperliquid does not collect fees from funding payments. The payment is transferred between long and short positions.
10.1 How Funding Works on Hyperliquid
Hyperliquid calculates funding from the difference between the perp market price and the oracle price.
If the perp trades above the oracle price, funding tends to be positive, so longs pay shorts.
If the perp trades below the oracle price, funding tends to be negative, so shorts pay longs.
Funding is paid every hour.
10.2 Funding Rate
The funding formula is:
F = P + clamp(interest_rate - P, -0.0005, 0.0005)
Where:
F = funding rate
P = average premium index
The premium is based on how far the perp price is from the oracle price:
premium = impact_price_difference / oracle_price
impact_price_difference =
max(impact_bid_price - oracle_price, 0)
- max(oracle_price - impact_ask_price, 0)
The premium is sampled every 5 seconds and averaged over the hour.
Important Hyperliquid detail: the formula calculates an 8-hour funding rate, but funding is paid every hour using one eighth of that rate.
hourly_funding_rate = funding_rate / 8
10.3 Funding Payment
At the funding interval, the payment is:
funding_payment = position_size * oracle_price * hourly_funding_rate
Hyperliquid uses the oracle price to convert position size into notional value for funding.
10.4 Example
Inputs:
| Item | Value |
|---|---|
| Oracle price | 10,000 |
| Impact bid price | 10,100 |
| Position size | 10 |
| 8-hour funding rate | 0.95% |
Hourly funding rate:
hourly_funding_rate = 0.95% / 8
hourly_funding_rate = 0.11875%
Funding payment:
funding_payment = 10 * 10,000 * 0.0011875
funding_payment = 118.75 USDC
Because funding is positive, the long side pays the short side.
10.5 Implementation Logic
To calculate funding, the system needs to:
1. Get oracle price.
2. Calculate impact bid price and impact ask price.
3. Calculate impact price difference:
max(impact_bid_price - oracle_price, 0) - max(oracle_price - impact_ask_price, 0)
4. Calculate premium:
premium = impact_price_difference / oracle_price
5. Average premium over the funding interval.
6. Calculate 8-hour funding rate:
F = P + clamp(interest_rate - P, -0.0005, 0.0005)
7. Convert to hourly funding rate:
hourly_funding_rate = F / 8
8. Calculate payment:
funding_payment = position_size * oracle_price * hourly_funding_rate
9. Apply direction:
if funding_rate > 0: longs pay shorts
if funding_rate < 0: shorts pay longs
References
- Hyperliquid Docs: https://hyperliquid.gitbook.io/hyperliquid-docs
- HyENA Docs: https://docs.hyena.trade/
- XYZ docs: https://docs.trade.xyz/