# Positions

## Position Margin Calculation

### Linear Futures
Position margin is dynamically calculated based on the mark price:

```
Position Margin = Position Size × Mark Price × Initial Margin Rate
```

#### Example - Linear Future
Given:
- Position: Long 2 BTC
- Mark Price: $50,000
- Initial Margin Rate: 1%

```
Position Margin = 2 × $50,000 × 0.01 = $1,000 USD
```

If mark price changes to $51,000:
```
New Position Margin = 2 × $51,000 × 0.01 = $1,020 USD
```

### Inverse Futures
Position margin remains constant regardless of mark price changes, because the instrument is denominated in the margin currency. The contract value does not change in margin currency terms.

```
Position Margin = (Position Size / Entry Price) × Initial Margin Rate
```

#### Example - Inverse Future
Given:
- Position: Short 100,000 USDT
- Entry Price: $50,000
- Initial Margin Rate: 1%

```
Position Margin = (100,000 / 50,000) × 0.01 = 0.02 BTC
```

If mark price changes to $51,000, margin requirement remains 0.02 BTC.

## Position-Closing Orders

### Basic Position-Closing

Position-closing orders do not consume additional margin.

#### Example
Given:
- Current Position: Long 2 BTC
- Available Margin: $100 USD
- Mark Price: $50,000

A sell order for 2 BTC will be accepted even with minimal available margin, as it closes the position.

### Position-Closing with Existing Orders

When placing a position-closing order while other closing orders exist, margin may be required for existing orders.

#### Example
Given:
- Current Position: Long 3 BTC
- Existing Sell Order: 3 BTC at $52,000
- New Sell Order: 3 BTC at $51,000
- Initial Margin Rate: 1%

```
Required Margin for Existing Order = 3 × $52,000 × 0.01 = $1,560 USD
```
The new order requires margin for the existing order since it would execute first, meaning that the existing order no longer offsets the position, and therefore consumes margin.

## Mixed Position and Order Scenarios

### Partial Position-Closing

Orders that both close positions and open new positions have split margin requirements.

#### Example
Given:
- Current Position: Long 2 BTC
- New Sell Order: 5 BTC
- Mark Price: $50,000
- Initial Margin Rate: 1%

```
Position-Closing Portion (2 BTC): No margin required
Position-Opening Portion (3 BTC): 3 × $50,000 × 0.01 = $1,500 USD
```

### Net Margin Calculation

The system evaluates both sides independently and uses the higher margin requirement.

#### Example
Given:
- Current Position: Long 3 BTC
- Buy Orders: 2 BTC
- Sell Orders: 4 BTC
- Mark Price: $50,000
- Initial Margin Rate: 1%

```
Long Side Calculation:
Position (3 BTC) + Buy Orders (2 BTC) = 5 BTC
Margin Required = 5 × $50,000 × 0.01 = $2,500 USD

Short Side Calculation:
Position (3 BTC) + Sell Orders (4 BTC) = 4 BTC
(Only counting the position-opening portion)
Margin Required = 4 × $50,000 × 0.01 = $2,000 USD

Final Margin Required = max($2,500, $2,000) = $2,500 USD
```

## Emergency Position-Closing

Accounts can always place position-closing orders, even when the account exceeds maximum initial margin usage.

#### Example
Given:
- Position: Long 5 BTC
- Available Margin: $0 USD
- Initial Margin Usage: 100%

A sell order for ≤ 5 BTC will be accepted as it reduces position risk.
