---
title: "🤝 Order Matching Mechanism"
description: >-
  Learn how Forkast's order matching engine prioritizes normal, mint, and merge
  matching to ensure fair and efficient prediction market trades.
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

Forkast employs a robust order matching system that prioritizes efficiency and fairness in its prediction markets. The matching engine follows specific rules to match buy and sell orders, ensuring seamless trade execution.

### 📏 Standard Matching Rules

1. **Normal Matching** (Priority 1)
   Matches buy orders (bids) with sell orders (asks) based on the following rules:
- **Price Priority**: Buy orders with higher bid prices are matched first with sell orders having lower ask prices.
- **Refunds**: If a buy order's bid price exceeds the matched sell order's ask price, the buyer is refunded the price difference.
 **Example**:
   - Sellers:
     - Seller A: 0.6 Yes (30 shares)
     - Seller B: 0.7 Yes (30 shares)
   - Buyer:
     - Buyer C: 0.8 Yes (30 shares)
   - Matching: Buyer C is matched with Seller A at 0.6, and Buyer C receives a refund for the price difference.
2. **Mint Matching** (Priority 2)
   If no normal match is possible, the system matches two bids from "Yes" and "No" buyers, provided their combined prices equal 1 TC. The system mints Yes-No tokens for both buyers.
 **Example**:
   - Buyer A: 0.6 Yes (30 shares)
   - Buyer B: 0.4 No (30 shares)
   - Matching: Tokens are minted as **Yes price (0.6) + No price (0.4) = 1 TC**.
3. **Merge Matching** (Priority 3)
   If no normal match is available, the system matches two asks from "Yes" and "No" sellers, provided their combined prices equal 1 TC. Tokens are merged, and sellers are paid in TC.
 **Example**:
   - Seller A: 0.7 Yes (30 shares)
   - Seller B: 0.3 No (30 shares)
   - Matching: Orders are merged as **Yes price (0.7) + No price (0.3) = 1 TC**, and sellers are paid in TC.

***

### 📏 Additional Matching Rules

1. **First-Come, First-Served**
   If multiple orders have the same price, the matching engine prioritizes them based on the time they were submitted.
2. **Redundant Matching**
- **Market Orders**: Remaining unmatched amounts are canceled and refunded immediately.
- **Limit Orders**: Remaining unmatched amounts stay on the order book and continue in the order queue until expiration or market closure.

**What happens to unfulfilled buy orders when a market resolves?**
If a market resolves before your buy order is fulfilled, the order is automatically canceled, and your funds are fully refunded.

***

### 🧾 Order Matching Examples

1. **Partial Fill**
   - Seller places a limit order: Sell Yes @ 0.7 (30 shares).
   - Buyer places a market order: Buy Yes (20 shares).
   - Result: 20 shares are matched at 0.7. The remaining 10 shares stay on the order book.
2. **Excess Demand**
   - Seller places a limit order: Sell Yes @ 0.7 (30 shares).
   - Buyer places a market order: Buy Yes (50 shares).
   - Result: 30 shares are matched at 0.7. The remaining 20 shares are canceled and refunded.

This matching system ensures efficient and fair trade execution while maintaining transparency and encouraging active participation.
