# Matching Algorithm

The order book uses a ladder matching algorithm that ensures the taker receives the best execution.\
This is different from single-price-per-trade matching algorithms that are employed elsewhere. Order\
matching is atomic (in the same blockchain transaction as the incoming taker order): the orderbook will\
never have overlapping orders from two sides. Orders in the book at the same price are sorted by time\
priority, the earliest orders at the same price are matched first.

For example: The book contains two buy orders, one at $100, quantity 2, another at $101, quantity 3. A sell order comes in that’s priced at $99, quantity 4. Two trades are created: one trade at $101, quantity 3, and another at $100, quantity 1.

If the exchange did not implement this algorithm, a secondary smart contract could break incoming orders atomically and automatically, as the order book is fully lit. To prevent flow re-routing and provide the same outcome for all users, the exchange must therefore implement this algorithm.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.world.inc/details/matching-algorithm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
