# Conditional Order Types

## Algorithmic Order

PNIX DEX provides an infrastructure that allows for the execution of various strategic orders as the trading price in the order book changes. It includes some of the most commonly used types of orders in its basic contract logic and has the flexibility to add other algorithm-based strategy orders. This aligns with the principles of blockchain DeFi technology, which aims to enhance connectivity.&#x20;

The conditional orders offered by PNIX DEX by default are as follows:

* [**Stop Order**](#stop-order)
  * **Take Profit (Bargain Hunting) Market/Limit Order**
    * Sell Take Profit (Buy Low) Market/Limit Order
  * **Stop Loss (Buying Spree) Market/Limit Order**
    * Sell Stop Loss (Buy Chase) Market/Limit Order
* [**OCO Order**](#oco-order)
* [**Trailing Stop Order**](#trailing-stop-order)

<figure><img src="/files/6n9nWw7QRLYNr09hZZx2" alt=""><figcaption><p>Algorithmic Order Flow (Buy side)</p></figcaption></figure>

### PriceLog Contract & Stacker

PNIX DEX utilizes the PriceLog contract as an infrastructure to track prices. Contracts for each trading pair update the PriceLog contract after order execution. Additionally, Stacker, an external keeper, executes several order types provided by the DEX based on price conditions. The conditional orders included in each pair are internally checked through the PriceLog contract's price check upon request, and then the order is submitted.

To ensure increased security and fairness of transactions, PNIX DEX maintains transaction information as private for conditional orders provided by default. When submitting, transaction details like trigger price are encrypted and not exposed. Traders can rely on trusted Stakers to access trade information and carry out trades based on specified conditions. In this process, the MerkleProof mechanism is employed to verify the integrity of the information submitted by both traders and Stakers.

<figure><img src="/files/TlafvMDHxhTkSwStTjAN" alt=""><figcaption><p>Stop Order sequence</p></figcaption></figure>

## Stop Order

A stop order is one of the fundamental conditional orders offered by PNIX DEX. With a stop order, when the market price reaches the stop price you specify, Stacker will only submit a regular (market or limit) order. Since external factors are involved in regular orders, additional fees are required as incentives for this process. However, if you have a strategic need for it, it can be a worthwhile option. For examples of strategic use, you can refer to[ the provided link.](/strategy/extending-dex-networks/breakthrough-strategy-using-conditional-orders.md)

### Stop Order vs. Limit Order

A limit order and a stop order may appear similar in appearance since you can specify the price and quantity for both. However, their functionalities are entirely different. When you place a limit order and there is no matching order on the order book, it is immediately exposed on the order book. On the other hand, a stop order remains hidden on the order book until the market price reaches the stop price that you have submitted. This distinction allows stop orders to facilitate trades that cannot be achieved with limit orders.

To illustrate, suppose the current best buy order price on the order book is $100. If you place a sell order at $90, it will be executed immediately at the prevailing market price. However, if you wish to sell only when the price drops to $90 for risk management purposes, you can use a stop sell order that triggers at $90. In this way, stop orders provide a unique and strategic advantage over limit orders in terms of both functionality and management.

### Stop Order Category

\
Stop orders are categorized based on the relationship between the stop order price you submit and the current market price, as well as the order side (buy or sell). This division is made for the trader's convenience, while the actual contract code treats it as a more fundamental division.

Each category of stop orders can be further classified into market and limit orders.

<table data-header-hidden><thead><tr><th width="152.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Order Side</strong></td><td><strong>Price Level of Trigger Price</strong></td><td><strong>Stop Order Type</strong></td></tr><tr><td>Buy</td><td>market price &#x3C;= stop price </td><td>Buying Spree</td></tr><tr><td></td><td>stop price &#x3C; market price </td><td>Bargain Hunting</td></tr><tr><td>Sell</td><td>market price &#x3C; stop price </td><td>Take Profit</td></tr><tr><td></td><td>stop price &#x3C;= market price </td><td>Stop Loss</td></tr></tbody></table>

<figure><img src="/files/sLkNhXW64Xj1OV8bVZIw" alt=""><figcaption><p>Stop Order Category</p></figcaption></figure>

### Advantages of a Stop Order

#### Customization & Strategy

Stop orders enable traders to respond to specific situations that regular orders cannot address. Moreover, they offer opportunities for strategic order submissions. For instance, traders can employ [a breakthrough strategy](/strategy/extending-dex-networks/breakthrough-strategy-using-conditional-orders.md) by strategically placing orders at the boundaries of a price band to capitalize on potential price movements.&#x20;

#### Risk management

When purchasing volatile assets, having an exit strategy to monitor the price and execute profitable trades or stop losses at the appropriate time is crucial. In such cases, a stop order can be an excellent choice. By setting a stop order at a specific price above or below your holdings, you can efficiently exit a position without constantly tracking price changes. Similarly, stop orders can also be used as a strategic tool to enter the market at the right time.

## OCO Order

OCO (One Cancels the Other) orders simplify the use of stop orders. When discussing the advantages of stop orders in terms of risk management, it was explained that by placing orders at both stop-loss and take-profit prices as an exit strategy, traders can avoid missing the right timing to close their positions. However, if two stop orders are placed simultaneously and one is triggered to close the position, the remaining stop orders must be manually canceled. Failing to do so may result in undesirable positions.

With OCO orders, this issue is resolved automatically. When one of the two orders is executed, the other order is automatically canceled. In essence, two orders are placed, but only one is executed based on the market conditions. OCO orders provide a convenient way to establish or exit a position with minimal cost and effort.

* OCO Order = Take profit limit order + Stop loss order (market or limit)

## Trailing Stop Order

Once traders become familiar with stop orders, they often utilize them for risk management to exit positions. However, there are situations where the market moves rapidly in their favor after placing a stop order or an OCO order. In such cases, traders might consider canceling the original order and re-submitting it with more favorable terms. To address this scenario, a useful tool is the trailing stop order, which can also be used for entry purposes.

Trailing stop orders share the same underlying logic as regular stop orders, but with a key difference: the stop price of a trailing stop order adjusts dynamically based on market conditions. If the market moves favorably for the position, the trailing stop price moves along with a submitted percentage, thereby allowing traders to lock in increased profits during liquidation. On the other hand, if the market moves unfavorably, the trailing stop order maintains the existing stop price until the market price meets it, triggering an order placement and liquidation.

The terms of a trailing stop order differ slightly from those of a regular stop order, making it a valuable tool for traders seeking to maximize their gains while managing risks effectively.

* **Activation Price**\
  The Activation Price is the condition under which a Trailing Stop Order will begin tracking the price movement. If not explicitly submitted, the current market price will be used as a substitute. For a buy order, the Activation Price must be set lower than the current market price, while for a sell order, it should be higher. Trailing stop orders are triggered only when the market's highest or lowest price has updated and surpassed the Activation Price after the order was initially submitted. This mechanism ensures that the order is activated based on the latest market conditions, allowing traders to effectively manage their positions in response to price fluctuations.
* **Trailing Delta**\
  Unlike regular stop orders, trailing stop orders do not have a fixed stop price. Instead, they use a delta value to dynamically calculate the stop price for placing orders. For a buy order, the stop price is continuously updated based on the ratio of the delta value to the lowest price whenever the lowest price changes. This dynamic adjustment enables traders to achieve more favorable trading timing. Similarly, for sell orders, the trailing stop price is adjusted in the opposite direction based on the ratio of the delta value to the highest price whenever the highest price changes. This mechanism ensures that the stop price moves in line with market fluctuations, allowing traders to secure potential profits or limit losses effectively.

<figure><img src="/files/Pk65ySvuKqAe2x9Od2Z2" alt=""><figcaption><p>Trailing Stop Buy Order</p></figcaption></figure>


---

# 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/conditional-order-types.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.
