# CLOB Mechanism Details

**Bid/Ask Spread and Order Book Integration:** The hybrid model’s pricing means the **best bid/ask on the order book and AMM should align**. To ensure fairness, the AMM’s quote price is set to **match the top-of-book** price if the book has depth, or to closely follow the index price plus/minus half the spread if the book is empty. If a large market order eats all order book asks, the next available liquidity is the AMM which will start at a price slightly worse than the last filled order book price. This continuity prevents sudden jumps.

**On-Chain Limit Order Fill Equation:** When matching against limit orders, slippage is simply determined by the resting order distribution:

* Suppose the order book has orders such that at price level $p\_k$ there is $\delta q\_k$ quantity. For a buy market order of size $Q$, the execution price is $P\_{avg} = \frac{1}{Q}\sum\_k p\_k \min(Q\_{\text{remaining}}, \delta q\_k)$ summing until $Q$ is filled. The structure of the book (which often can be modeled as having more depth further from mid) determines slippage. Unlike AMM, order book liquidity is not a continuous function but a step function at each order.
* Our hybrid model effectively combines the above: part of the sum might be discrete fills from the book, and the last part an integral from the AMM curve.


---

# 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.nunchi.trade/research/nunchi-engine-nclob-core-concepts/clob-mechanism-details.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.
