Sub topic 3
Perpetual futures: the main venue for crypto leverage
This chapter assumes you know what a long and a short position are, can work with percentages, and can read short Python functions. It also assumes you have seen the idea of margin from the previous chapters: a deposit that backs a position larger than the deposit.
What a perpetual future is
A perpetual future (often called a "perp") is a derivative contract that tracks the price of an asset such as BTC or ETH and has no expiry date. A derivative is a contract whose value depends on another asset. You do not own any coins when you hold a perp. You hold a claim on the profit or loss from a price move, settled in a currency such as USDT, USDC or the coin itself.
Traditional futures expire on a fixed date, and the price converges to the spot price by then. Perps never expire, so a trader can hold a position for as long as the margin lasts. This is one reason perps became the dominant leveraged product in crypto. Traders do not have to roll positions from one contract month to the next, and all the liquidity concentrates in one contract per asset.
Perps are popular for several practical reasons:
- Leverage is built in. A trader picks a leverage setting and posts margin.
- Shorting is as easy as going long. There is no borrowing of coins to arrange.
- Trading runs 24 hours a day, every day, which matches the crypto market.
- One contract per market keeps order books deep, so large orders move the price less.
Linear and inverse contracts
Perps come in two common designs. The difference matters because it changes how profit and loss behave.
| Property | Linear (USDT or USDC margined) | Inverse (coin margined) |
|---|---|---|
| Margin posted in | A stablecoin | The underlying coin (for example BTC) |
| Profit and loss paid in | The stablecoin | The underlying coin |
| Value of margin when the price falls | Stays constant | Falls with the coin |
| Profit and loss vs. price | Linear | Convex (nonlinear) |
In a linear contract, each unit of the asset gains or loses a fixed amount of stablecoin per dollar of price move. The code in this tutorial uses this simpler linear model.
In an inverse contract, the margin is the coin itself. A long BTC position margined in BTC loses twice: the position loses value, and the BTC collateral is worth fewer dollars. Liquidation prices for inverse contracts therefore sit closer to entry than a linear formula suggests for the same leverage, and the loss accelerates as the price falls.
How leverage works on a perp
When you open a perp position, you choose a position size (the notional value, which is the contract quantity times the price) and a leverage setting. The exchange requires initial margin equal to the notional divided by the leverage.
For example, a $10,000 position at 10x leverage needs $1,000 of margin. If the price moves 5% in your favor, the position gains $500, which is 50% of your margin. The first code example from this tutorial shows that relationship:
def equity_return(leverage, price_move):
"""Return on the trader's own margin for a long position, ignoring fees and funding."""
return leverage * price_move
for lev in (1, 5, 10):
print(lev, equity_return(lev, 0.05), equity_return(lev, -0.05))
# 10x leverage turns a 5% price move into a 50% gain or loss on margin.The leverage setting is a limit on how large a position the margin may support. It is not a loan you repay. The exchange does not lend you the coins. Instead, the exchange guarantees the contract and holds your margin as security against the loss you might owe. This distinction explains why a perp position can be closed out by the exchange at any time once the margin is no longer enough.
The moving parts of a perp market
Several mechanisms work together to keep the perp price close to the spot price and to keep the exchange solvent. Later chapters cover each in detail. This section gives the overview you need to follow them.
- Index price. An average of spot prices across several large exchanges. It represents the "true" market price of the asset.
- Mark price. A price the exchange calculates, based on the index price and other inputs, which it uses to value positions and trigger liquidations. It is covered in its own chapter.
- Last price. The price of the most recent trade on that exchange's perp order book.
- Funding rate. A periodic payment between longs and shorts that pulls the perp price toward the index price. It is covered in its own chapter.
- Insurance fund. A pool of money the exchange uses to cover losses when a liquidated position cannot be closed at a price that covers its debt.
Why perps need a funding rate
A future with an expiry has a built-in anchor: on the expiry date, the contract settles at the spot price. A perp has no such date, so something else has to hold the perp price near spot.
That something is the funding rate. At fixed intervals (commonly every 8 hours, although some venues use 1 hour or other intervals), one side of the market pays the other.
- When the perp trades above the index price, the funding rate is positive. Longs pay shorts. This makes holding a long more expensive and encourages shorts to enter, which pushes the perp price down.
- When the perp trades below the index price, the funding rate is negative. Shorts pay longs.
The payment equals the position's notional value times the funding rate. For example, a $10,000 long with a funding rate of 0.01% pays $1 per interval. At three intervals per day, that is $3 per day, or roughly 11% per year on the notional. At 10x leverage, that is roughly 110% per year on the margin. Funding is small in quiet markets and large in euphoric ones, and it is a real cost of holding a leveraged position for a long time.
Funding is paid between traders, not to the exchange. The exchange only facilitates the transfer.
A position lifecycle
The next diagram shows what happens to a perp position between opening and closing. The key point is that the exchange checks the position continuously, using the mark price.
A worked example
A trader opens a long on a linear BTC perp. The entry price is $100, to keep the numbers readable, and the trader uses 10x leverage with a maintenance margin rate of 0.5%.
- The notional is $10,000 (100 units at $100), so the initial margin is $1,000.
- The price rises 4%. Profit is $400, so equity is $1,400, a 40% return on margin.
- The price then falls back and goes 8% below entry. Loss is $800, so equity is $200, which means 80% of the margin is gone.
- At roughly 9.55% below entry, equity reaches the maintenance requirement and the exchange liquidates the position.
You can check step 4 with the liquidation formula used later in this tutorial:
def liquidation_price(entry, leverage, maintenance_rate, side):
"""Approximate liquidation price for an isolated linear position.
Ignores fees, funding and exchange-specific tiering.
Liquidation happens when equity equals maintenance_rate * position value.
"""
initial = 1.0 / leverage
if side == 'long':
return entry * (1 - initial) / (1 - maintenance_rate)
if side == 'short':
return entry * (1 + initial) / (1 + maintenance_rate)
raise ValueError('side must be long or short')
print(round(liquidation_price(100.0, 10, 0.005, 'long'), 2)) # 90.45
print(round(liquidation_price(100.0, 10, 0.005, 'short'), 2)) # 109.45The long liquidates at $90.45, which is 9.55% below the $100 entry. A 10x long can lose almost its whole margin before the exchange steps in, but the exchange acts before the margin reaches zero. That leftover buffer is what pays the liquidation fees and covers slippage.
Common errors and misconceptions
- Confusing leverage with borrowing. On a perp you post margin and the exchange guarantees the contract. You are not repaying a loan with interest. You do pay funding, which is a different cost.
- Reading funding as an exchange fee. Funding moves between longs and shorts. Trading fees are separate and go to the exchange.
- Assuming the last price triggers liquidation. Most exchanges use the mark price, so a brief spike in the last price on a thin order book does not necessarily liquidate you.
- Ignoring fees and funding in the liquidation estimate. The formula above is an approximation. Real liquidation prices are closer to entry once fees and accrued funding reduce your equity.
- Treating inverse and linear contracts as the same. With an inverse contract, falling prices also shrink the value of your collateral.
- Believing perps track spot exactly. The perp can trade at a premium or discount to spot. Funding limits the gap but does not remove it, and the gap can widen sharply in a fast market.
Why perps matter for the rest of this tutorial
Perps concentrate a large amount of leveraged positioning in one place, on a market that never closes. Every leveraged long has a price at which it will be forced to sell, and every leveraged short has a price at which it will be forced to buy. The exchange's liquidation engine turns those prices into real orders on the order book. When many positions share similar liquidation prices, the orders arrive together. The later chapters on open interest and liquidation cascades show how that clustering turns a modest price move into a larger one.
Exercise
A trader opens a $20,000 long on a linear BTC perp at 5x leverage. The funding rate is +0.02% every 8 hours and stays constant. (a) How much initial margin is required? (b) How much funding does the trader pay in one day? (c) What percentage of the trader's margin does that daily funding cost represent?
Show answer
(a) Initial margin is notional divided by leverage: $20,000 / 5 = $4,000. (b) There are three 8-hour intervals per day. Each payment is $20,000 x 0.0002 = $4, so the daily cost is $12. (c) $12 / $4,000 = 0.3% of margin per day. Because the long pays when the rate is positive, this cost reduces equity and moves the liquidation price slightly closer to the entry price over time.
Exercise
Using the liquidation_price function from this chapter, what is the approximate liquidation price of a short opened at an entry price of 200 with 5x leverage and a 0.5% maintenance rate? Is the distance from entry larger or smaller than for a 10x short?
Show answer
initial = 1/5 = 0.2, so the price is 200 x (1 + 0.2) / (1 + 0.005) = 240 / 1.005, which is about 238.81. The distance from entry is about 19.4%. A 10x short at the same entry would liquidate near 218.9 (about 9.45% away), so lower leverage puts the liquidation price much further from entry.