Apex Docs
  • Overview
  • How it works
    • The Basics of Perpetual Futures and Perpetual Protocol
    • APEX Limit Order Design
    • Comparison with order book exchanges
  • User Guide
    • Add xDai Chain to Your Wallet
    • Acquiring xDAI tokens
    • Getting USDC on xDai
    • Interacting with xDai
    • Spawn your smart wallet
    • Funding your smart wallet
    • Approve Spend
    • Fees
    • Creating Orders
      • Creating Limit orders
  • Order Types
    • Understanding Slippage
    • Market Orders
    • Limit Orders
    • Stop Orders
      • Stop Market
      • Stop Limit
      • Stop Market vs Stop Limit
      • Trailing Stop Orders
  • Developer Guide
    • Smart Contracts
      • Limit Order Book
      • Smart Wallet Factory
      • Smart Wallet
    • Keeper Bots
      • Overview
      • Running your own bot
      • Documentation
Powered by GitBook
On this page
  • Overview
  • Smart Contracts

Was this helpful?

Developer Guide

PreviousTrailing Stop OrdersNextSmart Contracts

Last updated 4 years ago

Was this helpful?

Overview

Advanced orders are conceptually simple to understand. They can be executed by saying “If price is above or below a certain value, execute buy/sell order”. However, this sort of command is impossible to execute on a block chain. Any transaction on the block chain must be initiated by a user, therefore it is not possible to have this sort of conditionality.

Our solution at apex, is to utilise ‘keepers’. A keeper is anybody that monitors the orders that have been placed and calls the execute() function when their conditions have been met. In doing so, the order will be executed.

As keepers will have the ability to execute orders, we must ensure that it is never possible for a keeper to execute an order incorrectly. The smart contract must verify the conditions of the order before that order can be executed. If the conditions have not been met, then the execute() transaction will revert.

The keepers are providing a service (indeed, apex could not operate without keepers), therefore there must be an economic incentive for keepers to exist. Every order created on apex, will have a ‘botFee’ attached to it. This fee will go to the keeper that executes the orders.

Smart Contracts

The LimitOrderBook contains all the advanced orders within apex.win. It has functions to create/modify/remove advanced orders (Limit, Stop, StopLimit, Trailing Stop, Trailing Stop Limit).

The SmartWalletFactory allows users to create and deploy their own smart wallets. It also ensures that each unique user can only create one smart wallet.

The SmartWallet is a hybrid between a smart contract and a personal wallet (hence the name). The owner of the smart wallet is able to relay functions as though it was the smart wallet executing those functions. This smart wallet will allow a keeper to execute an advanced order if and only if its conditions are met.

Limit Order Book
Smart Wallet Factory
Smart Wallet