Message: CreateTpSlPerpOrder
This operation allows to add conditional take-profit and/or stop-loss perpetual position orders. The message is rejected if the pool is in the stopped state.
The message must carry sufficient TON to cover the order executionFee and the createPerpOrderGas fees for all the conditions specified. The fees must thus be paid once if only a take-profit or stop-loss order is requested, and they must be paid twice if both conditions are specified. A condition is considered not requested if the size or trigger price is zero. Technically, it is possible to not specify either condition. This is not an issue for the pool, as it only causes the user to waste gas fees.
Next, the requested take-profit and/or stop-loss orders are inserted. Each order is assigned a unique incremental ID, used as a key to store the order details into the perpOrders map. An event is emitted for each inserted order to aid off-chain observers.
Finally, the totalExecutionFee amount of total fees collected to be paid to executors is increased, and any excess TON is returned to the message sender.
Inputs
The incoming message has the following structure:
executionFeeValidation: Must be sufficient to cover the
self.perpMinExecutionFeefor however many orders will be created.Impact: The fee to be paid to the executor for executing the order.
tokenIdValidation: None.
Impact: Identifier of the asset for which the user wants to take a position in.
isLongValidation: None.
Impact: Whether the user wants to take a long or short position. If
true, for take-profit orders,triggerAbovewill betrue, and for stop-loss orders,triggerAbovewill befalse. Iffalse, the opposite will be true.
tpSizeValidation: None.
Impact: The size of the take-profit order. This is the amount of the asset that will be sold if the take profit is triggered.
tpPriceValidation: None.
Impact: The price at which the take-profit order will be triggered.
slSizeValidation: None.
Impact: The size of the stop-loss order. This is the amount of the asset that will be sold if the stop loss is triggered.
slPriceValidation: None.
Impact: The price at which the stop-loss order will be triggered.
trxIdValidation: None.
Impact: Identifier for the message — does not affect handler logic.
requestTimeValidation: None.
Impact: N/A.
Test coverage
Intended branches
Negative behavior