## How to calculate the opening cost of a perpetual futures contract?

Traders should ensure that there is a minimum amount of funds in the wallet balance before opening a position. The cost of opening a position includes initial margin and opening loss. An opening loss occurs when the price of a futures contract moves unfavorably (that is, the mark price is lower than the order price for a long order). FTK includes opening loss into the cost of opening a position to avoid liquidation when traders place an order. If the opening loss is not included in the cost of opening a position, there is a high chance that a user's position will be liquidated as soon as they place an order.

The formula for calculating the cost of opening a position is as follows:

Cost = Initial Margin + Opening Loss (if applicable)

## 1. The cost of placing a limit order

**Step 1: Calculate Initial Margin**

Initial Margin = Contract Value / Leverage = (9,253.30 * 1 BTC) / 20 = 462.66

**Step 2: Calculate opening loss**

Opening loss = contract quantity * absolute value {{min[0, order direction * (mark price - order price)]}} Order direction: 1 for long order; -1 for short order

Open loss for long order = contract quantity * absolute value {{min[0, order direction * (mark price - order price)]} } = 1 * absolute value {{min[0, 1 * (9,259.84 - 9,253.30)]}} = 1 * absolute value {{min[0, 6.54]}} = 1 * 0 = 0

Opening Loss of Short Order = Contract Quantity * Absolute Value {{min[0, Order Direction x (Mark Price - Order Price)]}} = 1 * Absolute Value {{min[0, -1 * (9,259.84 - 9,253.30) ]}} = 1 * absolute value {{min[0, -6.54]}} = 1 * 6.54 = 6.54

### Step 3: Calculate the cost of opening a position

Because of long positions There is no opening loss for the order, so the cost of opening a long position is equal to the initial margin.

The cost of posting a long position = 462.66 + 0 = 462.66

Short orders have an opening loss, so the cost of posting a short position is higher because we have a Opening losses need to be included.

Cost of posting a short position = 462.66 + 6.54 = 469.20 (rounding difference)

## 2. Cost of placing a market order

### Step 1: Calculate initial margin

Initial Margin = Notional Value/Leverage

Initial Margin for Long Orders = Mark Price * Contract Quantity / Leverage = 10467.0009 * 0.2 / 20 = 104.670009

Initial Margin for Short Order = Mark Price * Contract Quantity / Leverage = 10461.78 * 0.2 / 20 = 104.6178

**Step 3: Calculate opening loss**

Opening loss = contract quantity * absolute value {{min[0, order direction * (mark price - order price)]}}

Order direction: 1 for long order; -1 for short order

Open loss for long order = contract quantity * absolute value {{min[0, order direction * (mark price - order price)]}} = 0.2 * absolute value {{min[0, 1 * (10461.78 - 10467.0009)]}} = 0.2 * absolute value {{min[0, -5.2309]}} = 0.2 * 5.2309 = 1.04418

The user has an opening loss when placing a long order.

Open loss for short order = contract quantity * absolute value {{min[0, order direction * (mark price - order price)]}} = 0.2 * absolute value {{min[0, - 1 * (10461.78 - 10461.78)]}} = 0.2 * absolute value {{min[0, 0]}} = 0.2 * 0 = 0

The user posted a short order without opening a loss.

**Step 4: Calculate the cost of opening a position**

Long orders have opening losses, so the cost of posting a long position is higher because we need to account for opening losses in addition to the initial margin.

Opening loss for long order = 104.670109 + 1.04418 = 105.71 (rounding difference)

Since there is no opening loss for short order, the cost of opening a short position is equal to the initial margin .

Opening loss for short order = 104.6178 + 0 = 104.61 (rounding difference)