# Maintenance Margin

# Overview

In the Nekuti Matching Engine, accounts can become undercollateralized when market conditions move against the trader's positions. This document outlines the liquidation workflow, a safety mechanism designed to minimize the risk for both the exchange and traders while handling accounts that breach their maintenance margin requirements.

The workflow attempts to resolve the undercollateralized state through several stages before fully liquidating the account. Each stage aims to reduce the account's margin requirements progressively and stop once the account meets its margin requirements again.

# Background

# Key Concepts

  • Leverage: The use of borrowed funds to increase a position size. Higher leverage increases the risk and the potential for liquidation.
  • Margin Requirement: The minimum account balance required to hold a leveraged position.
    • Initial Margin: The required balance to open a position or place an order.
    • Maintenance Margin: The minimum balance needed to keep a position or resting orders open. If the account's total equity falls below this level, the account becomes subject to liquidation.
  • Risk Limit: A tiered system defining the maximum position size (denominated in cost units) for a given margin requirement. Higher risk limits typically require a higher initial and maintenance margin requirement. Each account can configure any arbitrary risk limit, with margin requirements set as a function of the configured risk limit.
  • Margin Currency: Each instrument allocates margin by reserving balances in a margin currency. The Nekuti Matching Engine implements Cross-Margin, which means that multiple instruments can share the same margin currency on the same account.

# Liquidation Trigger

When an account's equity falls below the maintenance margin for a particular Margin Currency, the account enters liquidation for that Margin Currency. The liquidation process attempts to reduce risk and margin requirements incrementally before fully taking over the account.

# Liquidation Workflow

# Step 1: Reduce Risk Limit

Objective: Attempt to lower the account's risk limit tier to reduce the margin requirement.

  1. Check Risk Limit Tier: Determine the current risk limit tier for the account's position.
  2. Evaluate Lower Tier: Assess if reducing to a lower risk limit tier is possible based on the current position size, outstanding orders, and deposit balance.
  3. Reduce Risk Limit: If eligible, lower the risk limit tier. This reduces the margin requirement, potentially bringing the account back within its maintenance margin.

Exit Condition: If reducing the risk limit restores sufficient margin, the liquidation process ends here.

# Step 2: Cancel Outstanding Orders

Objective: Cancel all open orders on the instrument to free up reserved margin.

  1. Cancel Orders: Cancel all outstanding orders that allocate margin on the given Margin Currency.
  2. Recalculate Margin: Recalculate the account's available margin and check if it meets the maintenance margin requirement.

Exit Condition: If cancelling the orders restores sufficient margin, the liquidation process ends here.

# Step 3: Partially Close Positions

Objective: Reduce the position size if and only if it enables the account to move to a lower risk limit tier and decrease margin requirements sufficiently to exit liquidation.

  1. Evaluate Position Size: Determine if reducing the position size can allow the account to qualify for a lower risk limit tier and resolve the undercollateralized state.
  2. Partial Close: Execute a market order to partially reduce the position size.
  3. Adjust Risk Limit: Reduce the risk limit tier based on the new, smaller position size.

Exit Condition: If the partial close succeeded, the liquidation process ends here.

# Step 4: Take Over the Account

Objective: As a last resort, transfer all positions and balances to the insurance fund, where they will be liquidated and prevent further losses.

  1. Compute adjusted bankruptcy prices: Compute a price at which the account will have no remaining margin, including a liquidation taker fee (if such a fee is set). The liquidation taker fee is capped to prevent the insurance fund receiving positions with negative equity.
  2. Full Account Takeover: The exchange's insurance fund receives all positions at these computed prices, leaving the account at zero.

# Workflow Summary

The liquidation process follows a cascading approach, where it attempts to resolve the undercollateralized state through progressive risk reduction steps:

  1. Reduce Risk Limit: Decrease margin requirements by lowering the risk tier.
  2. Cancel Outstanding Orders: Free up margin by removing open orders.
  3. Partially Close Positions: Decrease position size to reduce the margin requirement.
  4. Full Liquidation: If all else fails, transfer all positions and balances to the insurance fund.

Each step is designed to minimize the impact on the user while protecting the exchange's risk exposure.

# Margin Calculation Example

Let’s consider an example to illustrate the margin adjustments:

  • Initial Position:

    • Position Size: 1 BTC
    • Risk Limit Tier: 2
    • Maintenance Margin Requirement: 5%
    • Taker Fee: 0.2%
    • Equity: $10,000
    • Position Value: $100,000
    • Maintenance Margin Needed: (0.05 + 0.002) * $100,000 = $5,200
  • Scenario: Market moves against the trader, reducing equity to $4,000.

  • Maintenance Margin Needed: $5,200 (5.2% of position value at Tier 2).

Liquidation Workflow:

  1. Step 1: Reduce Risk Limit: Lower to Tier 1 (1% margin requirement).
    • New Requirement: $1,200 (1% + 0.2% Taker fee = 1.2% of position value).
    • Equity ($4,000) > Requirement ($1,200): Exit Workflow.

In this case, the liquidation process stops after Step 1. If equity was lower, the process would continue to Step 2 and beyond as needed.

# Notes

  • The liquidation workflow is atomic and non-recursive. It attempts each step once and stops if the account recovers its margin.
  • The matching engine tracks all accounts inside the loop and initiates the liquidation workflow when an account breaches its maintenance margin, resolving the undercollateralized state before proceeding to process any further commands.
  • Market conditions (e.g., low liquidity or high volatility) may impact the effectiveness of partial position closures, potentially triggering a full account takeover.
  • There is no mechanism built in to the engine for the Insurance Fund to automatically liquidate. It is expected that exchanges incorporating the Nekuti Matching engine will implement a managed liquidation algorithm for the Insurance Fund.

# Edge Cases

Illiquid Markets: If the market cannot handle the partial closure without significant slippage, the liquidation engine may directly proceed to full account takeover.