Transaction Order
The essence of Contract Calculation is to deposit margin and record/modify position states when opening/adding a position, and calculate the remaining equity when closing/liquidating a position.
Open/close orders, stop limit/liquidate orders are all position states and changes to be recorded, as long as the states and changes are correctly recorded at right time, the correct states of positions can be correctly calculated, regardless the time of the calculation.
Derify protocol designs a role of Clearing Keeper, these players record price-limit orders within a certain range near the current price based on the state of the system, and waits for the opportunity to modify the state of the position according to these orders.
Therefore, all trading activities can be described as follows:
Position opening orders: If the trader issues a new order to open positions, it's an "position opening orders" which all parameters including opening price are set by the trader. Since the last block time before the order, at the first moment that index price reaches the order price, such moment and price will be recorded.
Position adding orders: If the trader issues a new order to open positions, but already holds positions with same direction, it's an "position adding orders" which all parameters including opening price are set by the trader. Since the last block time before the order, at the first moment that index price reaches the order price, such moment and price will be recorded, and state of the position will also be adjusted accordingly.
Position closing orders: If the trader issues a new order to close existed positions, it's an "position closing orders" which all parameters including opening price are set by the trader. Since the last block time before the order, at the first moment that index price reaches the order price, such moment and price will be recorded, and state of the position will also be adjusted accordingly. Moreover, money after transaction will be allocated in the margin account. Closing all positions can be seen as closing 100% of held position.
Therefore, we standardize all trading activities:
Limit-price orders are typical orders, including all three transaction orders, executed by clearing keepers.
Market-price opening order is a special form of position opening orders, which its price is determined by Oracles, and its state is set as opened instantly.
Market-price adding order is a special form of position adding orders, which its price is determined by Oracles.
Market-price closing order is a special form of position closing orders, which its price is determined by Oracles.
Stop-profit order is a position closing order with pre-set target price, executed by clearing keepers.
Stop-loss order is a position closing order with pre-set target price, executed by clearing keepers.
Automatic-Reduction and Mandatory Liquidation are market-price closing orders triggered by the level of remaining margins, executed by clearing keepers.
At current stage, observer program built by Derify protocol act as the clearing keeper. We will allow any third-party clearing keepers to join the project in the future, and reward clearing keepers who clears transactions first.
最后更新于