⚡
All-In
  • Introduction
    • Intro to Prediction Markets
  • Creating your own Market
    • Create your own market
    • Market Rules and Guidelines
    • Assumptions and Default Interpretations
    • Usage of AI agents during market creation
  • Trading on an existing market
    • Market Resolution
    • Market Settlement
  • Developer Docs
    • Order Types
    • Matching Engine
    • Collateral Requirements & Fees
    • API Reference
  • Additional Resources
    • Tutorials & How-to guides
    • Glossary
    • FAQs
Powered by GitBook
On this page
  1. Developer Docs

Matching Engine

Matching Engine is entered through from a takerTrade() Prices with orders stored are initialized with a UNIV3 tick bitmap, which is used for searching the book. Each price with orderbook liquidity has an array of the ids mapped to it, which are the order ids for that price.

Matching itself consists of 2 core functions, * _match() — which gets orders on the best price and loops through each to pair with the market order * _matchPair() which first bounds the fill amount by MIN(market order amount, limit order amount, [maker position if limit order is reduce-only]) from there, it uses the fill amount to update the position of the taker & maker, and updates the orderbook Once the last order on a tick is filled, the next best price is found and the loop starts again in _match(). This continues until either the market order is filled or liquidity is exhausted.

There are filling functions for limit & market orders, which both call into a shared _routeTrade() function, which routes ultimately routes the order to _increasePosition(), _decreasePosition(), or _closePosition().

PreviousOrder TypesNextCollateral Requirements & Fees

Last updated 8 months ago