# Liquidation Engine

## When will liquidation happen?

It is determined using the following formula:

$$
Net Collateral = Initial Collateral + Unrealized PnL - Fees
$$

*Only unrealized loss will be considered in this calculation. Any unrealized profit will not be taken into consideration*

**When Net Collateral <= 0, liquidation will be triggered.**

Under a very simplified situation:

User A opened a long position of BTC at 100 today with $10 as collateral with liquidation price showed on UI is 80

Position Fee: $0.09\
Borrow Fee: $0.01\
Liquidation Fee: $5, or 5% of collateral

User A could get liquidate if:

1. BTC price is below 80;
2. BTC price is at 85, but the leverage is high, and the unrealised loss is $20 (which will show on UI), it may cause full/partial liquidation, since collateral ($10) cannot payoff the Loss + Fees ($20+$5+$0.09+$0.01)

## How does Fulcrom calculate the liquidation price?

**Condition A: Full Liquidation**

For long positions, when markPrice is less than entryPrice, users will have negative PnL.

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FXtLULx57N9JO0buLAVHf%2FScreenshot%202023-11-27%20at%205.17.55%20PM.png?alt=media&#x26;token=2fb97d3f-ec48-4a86-a36f-bd602ed8b3a1" alt=""><figcaption></figcaption></figure>

When the collateral minus fee and PnL reaches 0, the position will be liquidated.

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FlEo02MRP7uZNnrVyKn7C%2FScreenshot%202023-11-27%20at%205.19.29%20PM.png?alt=media&#x26;token=2e8ac4fd-27c4-4ac2-8fef-3d406fe464bc" alt=""><figcaption></figcaption></figure>

When the markPrice continues to drop, the negative PnL will increase. When the remainCollateral finally reaches 0, the position will be liquidated. markPrice at that point will be the liquidation price.

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2F57s0pW9GFP1R1HulP7gJ%2FScreenshot%202023-11-27%20at%205.21.00%20PM.png?alt=media&#x26;token=12019d29-cc37-4658-a257-ac8ef8e519e4" alt=""><figcaption></figcaption></figure>

The liquidation price can be calculated as:

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FznPlv3lwdLULNU6lkZTt%2FScreenshot%202023-11-27%20at%205.21.35%20PM.png?alt=media&#x26;token=f3f9de45-31fc-46b0-b634-b05c4177dbef" alt=""><figcaption></figcaption></figure>

**Condition B: Partial Liquidation**

For partial liquidation, fee is not taken into consideration when calculating the remainCollateral.

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FFYe7gvgYPF95ECp7HSfq%2FScreenshot%202023-11-27%20at%205.22.52%20PM.png?alt=media&#x26;token=a67a9fd8-e879-4f72-93f5-b5872b163b5e" alt=""><figcaption></figcaption></figure>

When the remainCollateral reaches the maxLeverage required collateral, the position will be liquidated.

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FT775xxCpqhKDoxkUl3hD%2FScreenshot%202023-11-27%20at%205.24.30%20PM.png?alt=media&#x26;token=d68a78eb-fd4e-4e96-a809-2921489a8aaf" alt=""><figcaption></figcaption></figure>

The liquidation price can be calculated as:

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FWMngX30eL4fTXIzVsOnq%2FScreenshot%202023-11-27%20at%205.25.34%20PM.png?alt=media&#x26;token=640e3f0c-1249-4f7e-8114-06671f9f0982" alt=""><figcaption></figcaption></figure>

liquidationPrice B will be used when the following condition is met:

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FugXrfoaEUfcSyLQYtJOs%2FScreenshot%202023-11-27%20at%205.26.13%20PM.png?alt=media&#x26;token=0346d397-4eed-461b-b3f9-34f4c43a7f5c" alt="" width="252"><figcaption></figcaption></figure>

Otherwise, liquidationPrice A will be used

<figure><img src="https://1647136421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkF01syfy7zFMzhDL9cH%2Fuploads%2FJp3lio9tAdcQ9vwAj2Hs%2FScreenshot%202023-11-27%20at%205.26.57%20PM.png?alt=media&#x26;token=eea22113-0794-49a4-bd33-c9f4fba56a92" alt=""><figcaption></figcaption></figure>

#### Final liquidation price is calculated as the following:

For long position:&#x20;

Liquidation price = Math.max (Liquidation price A or Liquidation price B)&#x20;

For short position:&#x20;

Liquidation price = Math.min (Liquidation price A or Liquidation price B)

where

* fees = position\_fee + liquidation\_fee + borrow\_fee
* position\_fee = position\_size \* 0.1%
* liquidation\_fee = USD 5
* borrowing\_fee is calculated based on the borrowing time and borrowing rate.

When the market is fluctuating, the [spread](https://docs.fulcrom.finance/fulcrom-finance/about-fulcrom/spread) of the asset may be high, giving a higher chance of liquidation, meaning liquidation trigger point (spread + market price) could be lower than expected in a short position and vice versa.

{% hint style="warning" %}
There is possibility that your position is not liquidated at the expected specific price due to very sharp price changes.
{% endhint %}

{% hint style="warning" %}
When your position has reached the liquidation condition, you may not be able to manage your collateral / close your position as it is already pending liquidation.
{% endhint %}


---

# Agent Instructions: 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.fulcrom.finance/fulcrom-finance/core-modules/liquidation-engine.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.
