Limit and TPSL Order Execution
Once a user places an order through OrderManager.createOrders() similar to market order, the keeper bots listen to the order being created on the OrderManager contract, and when the limit price for Limit Orders and trigger price for TPSL orders matches the current market price:
Keeper bots call OrderManager.executeMultipleOrders() function with:
accountAddresses[]: address of users for whose orders are being triggered
orderIndices[]: each order for a user has a unique index, which is required while executing an order.
_feeReceiver: address of the executor to whom the execution fee is transferred.
executeMultipleOrders() supports executing multiple orders in a single transaction, thus increasing the overall throughput of the system.
If an order passes two main validation checks:
The trigger price of an order should match the current on-chain price in PriceFeed contract.
If it's a close order, then the user should have a valid open position to execute the order
An order is executed successfully, and in the case of:
Open order: The user's collateral is transferred to the vault, and the user’s position is increased via Vault.increasePosition()
Close Order: The user's position is decreased via Vault. decreasePosition(), and collateral plus the PnL of the trade is transferred back to the trader.
Last updated