Order Types and Matching
Market Orders
A market order is an order that executes immediately at the current market price for a given position size. Users can set an average execution price to limit how much their execution price can deviate from the mid-price of the order book. If there is insufficient liquidity in the market, or if subsequent fills would cause the average execution price to exceed the set limit, the market order will be partially filled.
Limit Orders
A limit order is a buy or sell order that executes at the limit price user sets or better. Limit orders also support enhanced order options like expiration and execution instructions.
Execution options
The Post-Only execution option ensures that a limit order is placed only as a maker order. If there are crossing orders on the opposite side of the order book at the time of placement, the exchange automatically cancels the post-only order to prevent it from becoming a taker order. If no crossing orders are present, the order is inserted into the order book. This guarantees that the order acts only as a maker and will pay maker fees for any trades.
The Allow Taker execution option does not enforce the restrictions of post-only orders. A limit order placed with this option can execute as a taker order if there are crossing orders on the opposite side of the order book at the time of placement. If there is a remaining amount after the initial matching, the order is then placed into the order book as a maker order.
Time in Force
Time-in-force options allow users specify the lifetime of an order.
Good ‘Til Time option allows users to specify a time until which the order remains valid. If the expiry time of an active order in the order book passes, the exchange automatically cancels the order.
The Immediate or Cancel option automatically cancels an order if it is not immediately filled. These orders are not placed into the order book as maker orders.
Order Matching
When matching orders, Lighter uses a price-time priority system. When a new order is placed as the taker, the Lighter Matching Engine finds the highest-priority order on the opposite side of the order book, meaning the order with the best price. If there are multiple orders with the same best price, the oldest one is selected. The matching engine then executes the trade at the maker’s price. If the taker order is not fully filled, this process continues until the taker order is completely filled or until there are no more crossing orders. If the taker order is a limit order that needs to be placed in the order book, the Lighter Matching Engine inserts it on the corresponding side.
The Lighter Matching Engine ensures that price-time priority is always respected by utilizing SNARKs to generate cryptographic proofs for fair order book matching execution. As a result, the Lighter Matching Engine operates as a trustless service, bound to function in a predefined way, making it mathematically impossible for it to act maliciously.
Last updated