All calculations on BitMEX are using XBT values.

For example, the XBTUSD perpetual swap contract is quoted in USD. 10,438 XBT/USD means 10,438 USD per XBT. If we want to quote the price in XBT. It is calculated as below.

1. Divided by the XBTUSD price  1/10,438 = 0.00009580379
2. Round the value up to 8 decimal places. 0.00009580 is the XBT value of 10,438 USD. As we now understand how to quote the price of the contract in XBT value. We will calculate the entry price in different cases.

Scenario 1: The order executed at the same price

You bought 100 contracts of XBTUSD Perpetual Swap contract, and your order filled for 100 contracts at \$7500. In this case, you don’t need to calculate the average entry price. As you can see, the average entry price is \$7500.

Conversely, you sold 100 contracts of the same contract and filled as above, and the average entry price is \$7500 as well.

Scenario 2: The order executed at different prices

You bought or sold 100 contracts of XBTUSD and are filled for 80 contracts at \$7500, and 20 contracts at \$7800. You need to calculate the average entry price in XBT, then convert to the USD price.

1. You quote \$7,500 in XBT value.

1/7,500 = 0.00013333333
We round the value up to 8 decimal places.
The XBT value of \$7,500 is 0.00013333 XBT.

2. You quote \$7,800 in XBT value.

1/7,800 = 0.00012820512
We round the value up to 8 decimal places.
The XBT value of \$7,800 is 0.00012821 XBT.

3. You need to get the total value of the executed order

{(\$7,500 quoted in XBT value)*80 + (\$7,500 quoted in XBT value)*20}
= {(0.00013333 * 80) + (0.00012821 * 20)} = 0.0132306

4. Next, you can calculate the average entry price in XBT value as below.

0.0132306 / 100 = 0.000132306 XBT If you went long, you round down to the eighth decimal place and then, we can convert to the USD price. As stated above, we rounded down the value and it is 0.00013231 XBT for the long position.

If we want to convert it to USD price, we can divide 1 by the value calculated as below.

1/ 0.00013230 XBT  = \$7,558.58

The average entry price for the short position is \$7,558.58.

Conversely, If you went short, you round up to the eighth decimal place and then, we can convert to the USD price. We rounded up the value, and it is 0.00013231 XBT for the short position. We can divide 1 by the value calculated as below to convert it to USD price.

1/ 0.00013231 XBT  = \$7,558.01

The average entry price for the short position is \$7,558.01.