Apex Docs
Search…
APEX Limit Order Design
This is a general overview of how APEX works, if you are interested in the technical details please check our Developer Guide.

Smart Wallets

Like the Perpetual Protocol, APEX is deployed to the XDai chain. When a user first uses APEX, he or she must create a smart wallet.
A smart wallet is a smart contract which:
  1. 1.
    Is fully controlled by the user.
  2. 2.
    Can hold funds and interact with our smart contracts.
The user must then deposit funds to the smart wallet. The smart wallet is the only wallet which is capable of spending money on APEX. This is analogous to multi signature smart contracts, and is based on the open source Gnosis safe implementation which has been extensively audited.
Once the smart wallet is funded, you can start trading. You can create market orders which are equivalent to those on Perp.Exchange. In addition, you can create limit orders and other advanced order types. These orders are executed by keeper-bots if the asset price reaches your order price.

Keeper-bots

Keeper-bots are a decentralised network of bots that monitor the prices on the Perp AMM. Once the price reaches a point where an order can be executed, the keeper-bots call a function to execute it.
Anyone can run a keeper-bot. It requires no permission and it is as simple as running a python script.
When the bot executes the order, the smart contract then verifies that:
  • The order is executed at the correct price.
  • The order can be executed correctly (e.g. slippage is not exceeded).
Given that the contract verifies the execution price is correct, users can be certain that malicious bots will not execute the order prematurely.

Bot fee

In order to create a limit order, users must pay a fee to add the order to our decentralised limit order book. This fee ensures the order is executed by the keeper-bots. It is up to the user to determine the fee they are willing to pay the bot to execute the order as long as it is over the minimum fee of $0.10. The fee must be paid upon submission to the orderbook. Keep in mind that keeper-bots are only able to execute a single order at a time. Hence, a higher fee ensures priority.
For most advanced order types keeper-bots receive 100% of the fee. For orders where the trigger price can change over time, such as orders with a trailing limit price, there is an additional step. The keeper-bots monitor the exchange price and update the trigger price for each order every time it is possible to do so. The smart contract then verifies the updated price is correct. The order fee then gets split between two bots: the last bot that updated the trigger price and the bot that executed the order.

Examples

Example 1:

Alice wants to buy 1 bitcoin at 50k USD. The current price of bitcoin is 55k. She sets a limit buy order on APEX, with a keeper fee of 1 USD. The order is submitted to the orderbook, and keeper-bots constantly monitor the price of bitcoin on the perp AMM.
If the price reaches 50k, the keeper-bots execute the order. Alice will have then opened a 1 bitcoin long position at an average entry of 50k. During the execution, our smart contracts verify that the right price conditions have in fact been met. If a keeper-bot tries to execute the order at the wrong price, the transaction will fail.

Example 2:

Ethereum is currently trading at 1600 USD. Bob has been long since 1000, but he wants to take profit on his position should Ethereum drop below 1500 USD. He creates a reduce-only stop market sell order, such that if Ethereum trades at the trigger price of 1500 or below his order will be closed.
Last modified 7mo ago