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:

  1. 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.

  1. executeMultipleOrders() supports executing multiple orders in a single transaction, thus increasing the overall throughput of the system.

  2. 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

  1. An order is executed successfully, and in the case of:

    1. Open order: The user's collateral is transferred to the vault, and the user’s position is increased via Vault.increasePosition()

    2. 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