> For the complete documentation index, see [llms.txt](https://docs.txflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.txflow.com/perp/order-types-and-matching/order-matching.md).

# Order Matching

TxFlow uses a **Price-Time Priority** Central Limit Order Book (CLOB).

### Matching Priority

1. **Best price first** — highest bid (for sells) or lowest ask (for buys) matches first
2. **Oldest Order First** — among orders at the same price, the earliest order is matched first

### Matching Process

When a taker order arrives:

1. Find the best maker order on the opposite side.
2. Execute at the maker's price (takers receive price improvement when possible).
3. Repeat until the taker order is fully filled or no more crossing orders exist.
4. If unfilled remainder exists — limit orders rest in the book; market and IOC orders are cancelled.

### Example

**Order book state:**

<table><thead><tr><th width="117.17578125">Bids (Buy)</th><th width="115.75">Price</th><th width="136.62890625">Asks (Sell)</th></tr></thead><tbody><tr><td>2 BTC</td><td>$49,950</td><td></td></tr><tr><td>5 BTC</td><td>$49,900</td><td></td></tr><tr><td></td><td>$50,000</td><td>3 BTC</td></tr><tr><td></td><td>$50,050</td><td>4 BTC</td></tr></tbody></table>

**Scenario:** You place a Market BUY for 5 BTC.

1. Match 3 BTC @ $50,000 (oldest ask at best price)
2. Match 2 BTC @ $50,050 (next best ask)
3. Order fully filled; average execution price = **$50,020**

### Related Pages

<table><thead><tr><th width="154.7265625">Pages</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/NDldhSbYgqXJRED554ln">Order Types</a></td><td>Market, Limit, and advanced orders</td></tr><tr><td><a href="/pages/z986rTaJ8Z98daTE3x0N">Liquidation</a></td><td>Detailed liquidation mechanics</td></tr><tr><td><a href="/pages/qHStLNd4Ek6xhOePLqG1">Trading Fees</a></td><td>Trading and funding fees</td></tr></tbody></table>
