1. How Does Order Matching Work?
System matches order according to the create time and price. "Open long" and "close short" belong to the buying side. While "close long" and "open short" belong to the selling side.
On the buying side, the order which was placed the earliest and has the highest price will be the first to be matched. On the selling side, the order which was placed the earliest and has the lowest price will be the first to be matched.
When the price of first buying order is larger than or equal to the first selling order, the two orders will be matched.
2. What Happens After the Orders are Matched?
After an open-order is matched, corresponding position(s) will be opened. The average position price and settlement price will be updated accordingly. When a close-order is matched, corresponding position(s) will be closed. The average position price and settlement price will remain the same.
Average price = contract face value * (positions held + new positions opened) / (contract face value * positions held / original average position price + contract face value * new positions opened / average new positions price)
Average new positions price = contract face value * new positions opened / (contract face value * filled price 1 contracts / filled price 1 + contract face value * filled price 2 contracts / filled price 2 + ...)
New positions opened = filled price 1 contracts + filled price 2 contracts + ...
Example: The latest filled price is USD600. A user holds 6 BTC long contracts and his average position price is USD500.
The user now opens extra 5 long contracts with the details below:
The average position price of the 5 contracts is: 100 * 5 / ( 100 * 1 / 580 + 100 *1 / 570 + 100 * 3 / 560) = 565.89
Therefore, the new average position price will be: 100 * ( 6 + 5 ) / ( 100 * 6 / 500 + 100 * 5 / 565.89) = 527.95
The number of contracts will be: 5 + 6 = 11