> For the complete documentation index, see [llms.txt](https://docs.v12.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.v12.trade/build/getting-started-as-a-developer/order-book-technical-reference.md).

# Order Book Technical Reference

**Limit Order Definition and Partial Execution**

A limit order is an instruction from a trader to buy or sell a specified quantity of an asset at a specified price or better. The order will only be executed if the market price meets the conditions set by the trader.

Let us define:

* $$P\_{\text{limit}}$$: the limit price set by the trader.
* $$P\_{\text{market}}$$: the current market price.
* $$Q\_{\text{order}}$$: the total quantity of the asset in the order.

For a **buy limit order**, the condition for execution is:

$$
P\_{\text{market}} \leq P\_{\text{limit}}
$$

For a **sell limit order**, the condition for execution is:

$$
P\_{\text{market}} \geq P\_{\text{limit}}
$$

If the respective condition is met, the order is executed for the available quantity at the best available price up to $$P\_{\text{limit}}$$ for buys or down to $$P\_{\text{limit}}$$ for sells.

### **Partial Fill and Remaining Order**

When a limit order is partially filled, only a portion of the order's total quantity is executed. The remaining unfilled quantity remains in the order book at the original limit price until it is fully filled or canceled.

Let us define:

* $$Q\_{\text{initial}}$$: the initial quantity specified in the limit order.
* $$Q\_{\text{filled}}$$: the quantity that has been executed (filled).
* $$Q\_{\text{remaining}}$$: the remaining quantity after partial fill.

The relationship between these quantities is:

$$
Q\_{\text{remaining}} = Q\_{\text{initial}} - Q\_{\text{filled}}
$$

The limit price $$P\_{\text{limit}}$$ remains unchanged after partial execution.

**Price Calculation and Asset Quantities**

In the context of exchanging assets, the price and quantities are represented as follows:

* $$Q\_{\text{offer}}$$: the quantity of the asset being offered (e.g., currency being sold).
* $$Q\_{\text{ask}}$$: the quantity of the asset being asked for (e.g., currency being bought).
* $$P$$: the price at which the exchange occurs, defined as:

$$
P = \frac{Q\_{\text{offer}}}{Q\_{\text{ask}}}
$$

After a partial fill, the quantities are updated:

* $$C\_{\text{offer}}$$: the amount of the offered asset that has been executed.
* $$C\_{\text{ask}}$$: the amount of the asked asset that has been received in exchange.
* $$Q'*{\text{offer}} = Q*{\text{offer}} - C\_{\text{offer}}$$: the updated offered quantity.
* $$Q'*{\text{ask}} = Q*{\text{ask}} - C\_{\text{ask}}$$: the updated asked quantity.

The price $P$ remains unchanged for the remaining unfilled portion:

$$
P = \frac{Q\_{\text{offer}}}{Q\_{\text{ask}}} = \frac{Q'*{\text{offer}}}{Q'*{\text{ask}}}
$$

**Summary**

After a limit order is partially filled, the unfilled portion of the order remains active in the order book at the same limit price $$P\_{\text{limit}}$$. The execution continues to adhere to the original conditions until the entire order is filled or canceled. The consistent price $$P$$ ensures that the ratio of the offered and asked quantities remains constant for the remaining order.

This mechanism allows traders to maintain control over the price at which they buy or sell an asset, even if their order cannot be filled immediately in its entirety.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.v12.trade/build/getting-started-as-a-developer/order-book-technical-reference.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
