> For the complete documentation index, see [llms.txt](https://docs.defx.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.defx.com/docs/trade/defx-perp-dex/liquidation.md).

# Liquidation

### Overview

Liquidations on Defx serve a crucial role in maintaining the stability and fairness of the trading environment. They prevent systemic risk by ensuring that all positions are adequately funded, thus safeguarding the exchange's solvency and protecting users from potential disruptions in volatile markets.

Defx's liquidation process automatically terminates leveraged positions if a trader's margin fails to meet the necessary maintenance margin, preventing their positions from reaching bankruptcy. The specific maintenance margins required are outlined in the "Maintenance Margin Requirements" section of our documentation. These requirements vary by contract, as detailed in the "Contract Specifications."

Liquidation is triggered when the mark price, as determined by the third-party oracle Stork, reaches the designated liquidation price for a position. Defx provides a visible liquidation price to traders at position initiation and throughout the duration of the position. As a position nears its liquidation price, Defx issues margin calls, advising traders to increase their margin by adding funds, thus avoiding liquidation.

### Liquidation Price

In the event that a position's margin falls to the maintenance margin level, Defx's liquidation engine automatically intervenes to assume control of the loss-making position. The primary function of the liquidation engine is to try to close the position at a predetermined liquidation price, calculated according to the following formula:

$$((InitialMargin - MaintenanceMargin) - (Side \* Qty \* avgEntryPrice)) / (Qty \* MMR + Side \* Qty)$$\ <br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.defx.com/docs/trade/defx-perp-dex/liquidation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
