StarkEx Perpetual Trading enables running a decentralized, perpetuals exchange that provides its users with self-custody, and settles transactions in a trustless manner.

 A perpetuals exchange is not intended to be a marketplace for NFTs. To create an NFT marketplace, use StarkEx Spot Trading.

A position includes a collateral asset and one or more synthetic assets. Unlike spot trading, a trader can hold a leveraged position, which enables trading in asset amounts that are greater than the amount of funds actually invested.

## Margin

When you create a StarkEx-powered perpetuals exchange, you define the requirements for an initial margin. The maintenance margin determines the level of leverage available to a trader, and when a position’s value falls below the maintenance margin, it is not well-leveraged.

The maintenance margin is similar to total risk.

## Total value and total risk

The total value of a position is the sum of the value of the position’s collateral and synthetic assets, expressed in the collateral currency.

The total risk is a measurement that includes the total value of all synthetic assets in a position, and also takes into account a predetermined risk factor for each synthetic asset. As the risk factor increases, so does the total risk.

You, the operator, determine the risk factor according to your business logic, and include it in the general configuration for your StarkEx instance.

Total risk is related to the maintenance margin as follows:

• When total value is equal to it’s total risk, it is exactly at the maintenance margin.

• When total value is less than it’s total risk, it is below the maintenance margin.

• When a position’s total value is greater than it’s total risk, it is above the maintenance margin.

In the following examples, consider that Alice holds the following position:

 collateral 500 USDC. synthetic 4 BTC. 1 BTC = 20,000 USDC. `Risk_factor` = 0.5 6 ETH. 1 ETH = 1,000 USDC. `Risk_factor` = 0.1
Example: Total value

The total value of Alice’s position is 116,500 USDC, calculated as follows:

`500 + (4 * 20,000) + (6 * 6,000) = 116,500`

Example: Total risk

The total risk of Alice’s position is 116,000 USDC, calculated as follows:

`500 + (4 * 20,000 * 0.5) + (6 * 6,000 * 0.1) = 43,600`

## Requirements for maintaining a position

A position must be well-leveraged. That is, \text{total_value} \ge \text{total_risk}, which is another way of saying that the total value of a position must be above the maintenance margin.

If 0 \lt \text{total_value} \lt \text{total_risk}, you can liquidate the position without the position owner’s signature by matching the position to another trader’s signed limit order that would result in the position becoming well-leveraged.

If \text{total_value} \lt 0, you can deleverage the position by matching it to another position that has the opposite balance with respect to some assets, without signatures from either position owner.

## Factors that can affect a position’s balance

The following factors can affect a position’s balance, potentially causing a position to be liquidated or deleveraged: