Configuration
HyperConfig
Initialization
Available Actions
Margin Management
deposit
deposit
Description: Deposit quote token as margin.Parameters:Effects:
amount_e18(u128): Amount to deposit
- Deducts
amount_e18quote from wallet - Increases user margin balance
withdraw
withdraw
Description: Withdraw margin (with maintenance check).Parameters:Checks:
amount_e18(u128): Amount to withdraw
- Post-withdrawal margin must remain >= maintenance requirement:
- Credits
amount_e18quote to wallet - Reduces user margin balance
Trading
market_order
market_order
Description: Execute a market order (long or short).Parameters:Example (short 0.5 ETH):Mechanics:
base_delta_e18(i128): Signed base delta (positive = long, negative = short)reduce_only(bool, optional): If true, only allows closing/reducing position
- Execute at current mark price
- Charge taker fee on notional
- Realize PnL if crossing sides (close old position)
- Update position and entry price
- Check post-trade margin >= maintenance requirement
- Updates
pos_base_e18(signed position) - Updates
entry_price_e18 - Adjusts margin for fee and realized PnL
close
close
Description: Close up to a specified size towards flat.Parameters:Mechanics:
size_e18(u128): Size to close (unsigned)
- Close min(size_e18, abs(position))
- Realize PnL at mark price
- Charge taker fee
- Reduce position towards zero
- Reduces
pos_base_e18 - Adjusts margin for PnL and fee
- Sets entry price to 0 if fully closed
liquidate
liquidate
Description: Liquidate an undercollateralized position.Parameters:Eligibility:Mechanics:
target(u32): User ID to liquidate
- Check target is eligible (margin ratio < maintenance)
- Close entire position at mark price
- Realize PnL
- Take liquidation fee from remaining margin → insurance fund
- Zero out position
- Position set to 0
- Margin reduced by liq fee
- Receives liquidation fee
Admin/Oracle
set_price
set_price
Description: Update mark price (oracle action).Parameters:Effects:
price_e18(u128): New mark price
- Updates mark price immediately
- Affects unrealized PnL for all positions
set_funding
set_funding
Description: Update funding rate (admin/oracle action).Parameters:Example (shorts pay longs):Sign Convention:
funding_rate_ray_per_tick(i128): Signed funding rate (RAY format)
+→ longs pay shorts-→ shorts pay longs
set_fees
set_fees
Description: Update taker fee.Parameters:
taker_fee_bps(u32)
set_maint
set_maint
Description: Update maintenance margin requirement.Parameters:
maint_margin_bps(u32)
Funding Mechanism
Funding is applied on each tick viaon_tick():
Example
PnL Calculation
Unrealized PnL
Realized PnL
Realized when closing or reducing position:Margin Requirements
Maintenance Margin
Effective Margin
Margin Ratio
>= maint_margin_bps: Healthy< maint_margin_bps: Liquidatable
View Methods
view_user
view_market
Usage Examples
Open Long Position
Short with Leverage
Reduce-Only Close
Liquidation Bot
Protocol-Specific Behavior
Entry Price Updates
When increasing position size (same side):Funding Symmetry
Funding is zero-sum (excluding dust to insurance):Liquidation Socialization
If liquidation leaves negative margin (underwater), shortfall goes to insurance fund:Limitations
Advanced: Funding Arbitrage
See Also
- Protocol Overview - Registry setup
- Source:
source/protocols/hyperliquid/src/lib.rs - Hyperliquid Docs