Liquidations and Derivative Trading

February 1, 2023

What are liquidations, and why do they matter in derivative trading?

In a traditional spot market, where instruments like tokens are traded between parties, an account’s value is the sum of balances in the account. While users generally want to see that number go up, and the specific way of determining the value of open positions can vary, the very existence of the underlying exchange is not at risk from changes to any account’s value.

This is a different story when leverage is involved. Let’s consider a perpetual exchange that offers leveraged trading. Here, leverage acts as a loan from the exchange to the traders. This enables traders to take on positions at a fraction of the cost of the underlying asset, but it also requires the exchange to take on the significant risk and responsibility of managing the loan.

How does this work? Exchanges require a certain amount of collateral from borrowers: a minimum amount to open a position, called initial margin, and an ongoing amount called maintenance margin. If an account’s value falls below the margin requirement, the exchange needs to quickly close out the loan before the account’s value can fall any further. Exchanges often use an open market mechanism to “close out” or “liquidate” the account by offering an incentive to parties called liquidators, who prowl the DEXosphere looking for profitable liquidations. The incentive fee is deducted from the delinquent trader, who is having a bad day as is.

Timely liquidation is core to a functioning exchange. Unlike TradFi, where a user might get a “margin call” to add margin to their account, in DeFi, an exchange’s proprietary algorithm must decide when to mark an account for liquidation. This algorithm must balance preventing unexpected liquidations that harm the user experience, and risk waiting too long to liquidate. Waiting too long can lead to the account value dropping precipitously until the loan needs to be repaid first by the exchange’s insurance fund and ultimately by socializing the loss to other accounts.

What makes a good liquidation strategy?

If you’ve read this far, you probably agree that getting liquidations right is important. But what does a good strategy for handling liquidations look like? We propose a few core principles:

First Principle: Properly Valuing Equity and Collateral

Properly assessing the value of an account, even before this value is realized into a profit or loss, is core to proper liquidations. A common practice among exchanges is to use the value of underlying assets (e.g. ETH-USDC), rather than the perpetual contract itself (“mark price”), to value perpetual contracts. Since the two can and do diverge, this can immediately result in unexpected behavior during high volatility. Illiquid assets can be hard to value and easy to manipulate. As a result, a good strategy involves considering historic prices as well as current prices in valuing collateral.

Second Principle: Fast, Transparent, and Independent

Since liquidation can generate fees for the exchange (some exchanges even handle liquidations “in-house”), this creates a significant centralized conflict of interest. It is imperative that exchanges outsource liquidation pricing to a decentralized independent provider, and this delegation must be enshrined in the smart contract. Using an ultra-fast decentralized price provider will help minimize surprise liquidations by enabling the exchange to wait longer to trigger liquidation, knowing they are not going to miss any important updates.

When considering how your exchange tackles liquidations, make sure to consider who will be performing the liquidations — the exchange, market makers, liquidation bots, or someone else. How will the exchange determine the true market value of the account position, and do so in a way that allows you to anticipate and model your expected losses and gains?

How do you build a good liquidation price?

At Stork, we work with our decentralized exchange partners to help break down the requirements for building a good liquidation price.

Oracle Best Practices for Liquidation:

  • Evaluate account health on a frequent basis
  • Use a mark price feed, rather than spot price, when valuing derivative contract; the spot index can easily diverge from the contract price, causing unexpected liquidations
  • More leverage => more frequent updates. If you offer 10x+ leverage, evaluate for liquidations at least every few seconds to avoid missing sudden changes to collateral value
  • Avoid paying for every price update since most updates do not trigger liquidations
  • Minimize the surface area for frontrunning and MEV by using
  • or working with MEV recovery agents.

Decentralized exchanges, like Apex Protocol, use Stork’s oracle to help power a first-class liquidation strategy. Stork provides them with:

  • Extremely low latency price updates, greatly reducing risk of market manipulation
  • Decentralized network of DeFi-specialized price feeds
  • Custom metrics such as the perpetual swap mark price index
  • Responsive oracle network with very fast access to new markets
  • Performant and cost-effective integration options

Interested in learning more? Reach out at Check out our docs and follow us on Twitter at @storkoracle to keep up with the latest at Stork.

About ApeX Protocol

ApeX Protocol’s newest product offering, ApeX Pro, is a permissionless and non-custodial DEX, powered by StarkWare’s Layer 2 scalability engine StarkEx, which operates on an orderbook model and delivers cross-margined perpetual contracts.