# Margin Specifications

## **Margin Requirements**&#x20;

Opening and maintaining a position on Demex allows for the use of leverage. Users can allocate as much margin or as little margin as they wish for each position, up to the margin requirements stated below.

{% hint style="info" %}
As Demex has not enabled cross-margin trading, positions on each market is margined separately. Liquidations therefore only affect a single market / position at a time.

Cross-margin and cross-collateral will be enabled on Mainnet in March 2025.
{% endhint %}

There are two types of margin requirements for each market - `Initial Margin` and `Maintenance Margin`. They differ for each market and can be derived from the market parameters in [GET Markets](https://api.carbon.network/swagger/#/Query/MarketAll). The following describes how to calculate each margin requirement based on the market parameters.

### **Initial Margin**

Initial margin is the amount of collateral required to open (or increase) a position.

This margin requirement is based on a fraction (`IMF`) of the position value:

`InitialMargin = IMF * Position Size * Entry Price`

The initial margin fraction (`IMF`) is given by:

`IMF = initial_margin_base + floor(Position Size / risk_step_size) * initial_margin_step`

The underscored parameters can be found in [GET Markets.](https://api.carbon.network/swagger/#/Query/MarketAll)

#### **Example**

For a BTC perp where:

```
# https://api.carbon.network/carbon/market/v1/markets/cmkt%252F118
risk_step_size = 0.1 # this is in human decimals (e.g. 0.1 BTC). Add &raw=true to the above request for raw values.
initial_margin_base = 0.01 # this is a fraction
initial_margin_step = 0.000005 # this is a fraction
```

Opening a 10 BTC long position at $30,000 will require:

`(0.01 + floor(10 / 0.1) * 0.000005) * 10 * 30,000 = 3,150 USDC`

This gives an effective leverage of: `300,000 / 3,150` = `95.23x`

One can quickly find that `1 / initial_margin_base` is the maximum leverage for a market (for position sizes that are smaller than `risk_step_size`).

For the example above, that would be `1 / 0.01 = 100x`.

### **Maintenance Margin**

Maintenance margin is the amount of collateral required to hold a position open.

If the effective margin (allocated margin + unrealized PnL) of a position drops below the required maintenance margin, the position will be liquidated according to the rules [here](/trade/futures/liquidation-engine.md#liquidation).

This margin requirement is based on a fraction of the initial margin requirement for a position:

`MaintenanceMargin = InitialMargin * maintenance_margin_ratio`.

The `maintenance_margin_ratio` can be found in [GET Markets](https://api.carbon.network/swagger/#/Query/MarketAll).

#### **Example**

For a BTC perp where:

```
# GET https://api.carbon.network/carbon/market/v1/markets/cmkt%252F118
risk_step_size = 0.1 # this is in human decimals (e.g. 0.1 BTC). Add &raw=true to the above request for raw values.
initial_margin_base = 0.01 # this is a fraction
initial_margin_step = 0.000005 # this is a fraction
maintenance_margin_ratio = 0.7 # this is a fraction
```

Opening a 10 BTC long position at $30,000 will require:

`(0.01 + floor(10 / 0.1) * 0.000005) * 10 * 30,000 = 3,150 USDC`

Maintaining this position requires that:

`InitialMargin + Unrealized PnL > (3,150 * 0.7 = 2,205 USDC)`

Assuming the user opens this position at maximum leverage (allocated margin = initial margin = 3,150), then the user's position will be liquidated if the market moves against them such that they incur more than `3,150 - 2,205 = 945 USDC` of unrealized losses.

This entails the user's position being taken over by the liquidation engine, and the user will lose the full allocated margin for this position. See the [Liquidation](/trade/futures/liquidation-engine.md) section for the full liquidation procedure.

For the above example, this will occur when the Mark Price of the market reaches `(10 * $30,000 - 945) / 10 = $29,905.50`.

Users can protect this position by manually adding more margin or decreasing their leverage for the market, such that their allocated margin increases above the maintenance margin requirements.


---

# 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://guide.dem.exchange/trade/futures/margin-specifications.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.
