> For the complete documentation index, see [llms.txt](https://docs.fulcrom.finance/fulcrom-finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fulcrom.finance/fulcrom-finance/core-modules/liquidation-engine.md).

# 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="/files/SLibPjOU53YUQzhGg2it" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/eDgudTki5BMCu8jm15WL" 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="/files/yNK3ihFob7ookNhxdlap" alt=""><figcaption></figcaption></figure>

The liquidation price can be calculated as:

<figure><img src="/files/blMMs68QCN2rNV9K5BQt" alt=""><figcaption></figcaption></figure>

**Condition B: Partial Liquidation**

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

<figure><img src="/files/UvZqx6FEH5671aANWxzH" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/FChhyNk8o9QlAkxcsM8i" alt=""><figcaption></figcaption></figure>

The liquidation price can be calculated as:

<figure><img src="/files/9ezY65YSjrpsYBAdDN1J" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/U2qa4LYlwc5POdHknfgB" alt="" width="252"><figcaption></figcaption></figure>

Otherwise, liquidationPrice A will be used

<figure><img src="/files/qtTk6okEZP85XPmCEh8P" 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](/fulcrom-finance/about-fulcrom/spread.md) 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 %}
