# Order System

## Decentralized Orderbook

The on-chain order book is a crucial element of the PNIX DEX. Unlike centralized exchanges, the orders submitted are matched with the orders on the order book through the smart contract algorithm on the chain, eliminating the need for an external arbitration service. Any remaining orders are then recorded in the order book. All of these processes are transparently executed and recorded on the chain, following the chain's consensus algorithm.

The order book is represented as a smart contract for each market pair. The information of each order recorded on the chain is organized and maintained in a data structure optimized for the matching algorithm based on price.

<div align="center"><figure><img src="/files/jCWNnqT2ICcBj4CxRJP8" alt="" width="563"><figcaption><p>Conceptual Orderbook Data Structure in Pair Contract</p></figcaption></figure></div>

To enhance the efficiency of the order book, the contract defines the minimum unit for increasing or decreasing the quantity of the base asset in the market (Lot Size) and the minimum unit for changing the order price (Tick Size). Moreover, specific rules for transaction restrictions, such as the maximum order quantity and the minimum/maximum size, are also set in the contract and can only be altered by mutual agreement. These applicable rules for each market are specified in the [Market Parameter](/decentralized-exchange/market-parameter.md).

The process and characteristics of order submission are summarized as follows:

1. Submit Order: \
   A user submits an order for an asset in the market by signing it to the order book contract through the service interface. The order should include essential information such as the order side (buy or sell), order type, remaining order holding period, price, and quantity. Unlike centralized exchanges, users are required to deposit the necessary assets in advance at the time of submission. The deposited amount should cover the quantity intended for exchange, as well as the associated fees, considering the highest potential fee. This measure ensures that the order remains valid even after matching, preventing cancellation due to insufficient funds for asset exchange and fee payment.
2. Order Matching: \
   Orders submitted to the order book contract are matched using the matching algorithm, starting from the best price order of the opposite side. If the order type is Limit Price, matching is attempted up to the submitted price, and any remaining orders are recorded in the order book.
3. Order Execution: \
   Once orders are matched, the assets are exchanged accordingly. The exchanged assets are directly withdrawn to the user's wallet, and the corresponding fee is collected. Fees are determined based on each user's level through the relevant contract. All these processes occur transparently through the contract logic, without the need for any intermediaries.
4. Transparency and Auditability: \
   The order book's status and the matching process are conducted by the blockchain's consensus algorithm, ensuring transparency and verifiability. This stands in stark contrast to centralized exchanges, where users can only access their individual transaction results without further insights into the overall process.
5. Order Book Update: \
   The order book undergoes real-time updates during the entire process of order submission, matching, and recording of remaining orders. These updates are conducted transparently and verifiably through the blockchain's consensus algorithm. This stands in stark contrast to centralized exchanges, where users have limited visibility and can only access their own trading results. PNIX DEX's on-chain order book enables enhanced security without the need for a third-party trustee.
6. Price Tracking: \
   PNIX DEX is continually enhancing its system to facilitate multiple algorithm-based order submissions by closely tracking market prices. For this purpose, a contract is in place to record prices whenever matching occurs, allowing various conditional orders to be submitted based on the contract's events. This strategic implementation further enhances the flexibility and effectiveness of trading on the platform.

## Order Types

* [Market Order](/decentralized-exchange/order-system/limit-market-order.md#market-order)
* [Limit Order](/decentralized-exchange/order-system/limit-market-order.md#limit-order)
* [Stop Order](/decentralized-exchange/order-system/conditional-order-types.md#stop-order)
* [OCO (One Cancels the Other) Order](/decentralized-exchange/order-system/conditional-order-types.md#oco-order)
* [Trailing Stop Order](/decentralized-exchange/order-system/conditional-order-types.md#trailing-stop-order)


---

# 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-en.pnix.exchange/decentralized-exchange/order-system.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.
