> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aultblockchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Orderbook

> Order types, matching priority, and what happens after you submit an order.

> [!NOTE]
>
> Mainnet currently supports Spot DEX only. Perpetuals, Oracle, Margin Trading, Lending, and Vaults are **Testnet-Only**. Use Testnet endpoints and assets for those products.

Ault DEX uses an on-chain central limit order book. Each order sets a side, a size, and the price you accept.

## Order types

| Function | What it does | Spot and Perpetuals |
| - | - | - |
| Limit | Buys at or below a set price, or sells at or above it. Unfilled size stays on the book. | Both are sized in the base asset. |
| Market | Fills immediately against the book within a price limit. Unfilled size is canceled. | On Spot, a buy is sized by the quote asset to spend and a sell by the base asset to sell. Perpetual markets accept limit orders only. For immediate execution, use an IOC limit order with a worst price. |
| Stop Loss (Testnet-Only) | Places an order when the price moves against you: below the trigger for a long, above it for a short. | Spot can place a limit or market order. Perpetuals can place a limit or IOC limit order; use reduce-only to exit a position. |
| Take Profit (Testnet-Only) | Places an order when the price moves in your favor: above the trigger for a long, below it for a short. | The same choices as Stop Loss. |
| TWAP | Splits an order into slices and runs one about every 30 seconds, each with a price limit. A TWAP can run for 5 minutes to 24 hours. Some size can remain unfilled. | Spot slices are market orders sized in the asset you pay. Perpetual slices are IOC limit orders sized in the base asset. Not supported for Margin Trading. |
| Scale | Spreads an order across a price range as multiple limit orders. | Each order follows Spot funding or Perpetual margin checks. Multi-order scale placements are not supported for Margin Trading. |
| Good till time (GTT) | Stays active until it fills, is canceled, or reaches its deadline. | The default for both. Every resting order needs a deadline. |
| Immediate or cancel (IOC) | Fills what it can immediately and cancels the rest. | An option on limit orders. |
| Post-only | Only adds liquidity. An order that would trade immediately is closed instead. | Limit orders only. Cannot be combined with IOC. |
| Reduce-only (Testnet-Only) | Only reduces a position. It cannot open, increase, or flip one. | Perpetuals only. |

## Stop Loss and Take Profit

**Testnet-Only.** Stop Loss and Take Profit are conditional orders. Both trigger on the **last traded price on Ault DEX**, not the mark or index price. You cannot place a conditional order whose trigger is already met.

A waiting conditional order holds no funds or margin. When it triggers, the new order goes through funding and margin checks. If those checks fail, the conditional order closes with no fill. Triggering does not guarantee a fill.

For example, a long position can use a reduce-only stop with a trigger of 95 and an IOC sell limit of 94. When the last trade reaches 95 or below, it tries to sell at 94 or better. If the price gaps below 94, it may not fill.

## Scheduled execution

Each slice is the remaining size divided by the number of slices left, so size that did not fill moves into later slices. A slice can be at most 3 times the original slice size. A slice below the minimum order size is raised to that minimum, and the TWAP ends once the remaining size is below it.

For example, a 10-minute TWAP for 1,000 has 20 slices of 50. If the first 10 slices do not fill, the next slice is 100 (1,000 / 10). If the first 14 do not fill, the next slice is capped at 150 instead of about 167 (1,000 / 6).

On Mainnet, placing a TWAP holds the full amount, and unused funds and proceeds return when it ends. On Testnet, nothing is held for the whole schedule. Each slice is checked and funded when it runs.

To stop a TWAP, [cancel its parent ID](https://docs.aultblockchain.com/dex-api/trading/cancel-order.md#cancelling-a-twap-schedule). Slices already created are not canceled, and their fills stand. You cannot cancel or modify an individual slice.

## Matching and priority

Orders are matched by price, then by time. A trade executes at the resting order's price. Your place in the queue depends on when the chain executes your transaction, not on when your request reached an API.

If your order would match your own resting order, the resting order closes with no fill or fee, and your incoming order continues against other orders. This also applies across your derived trading accounts. A post-only order that would trade immediately is rejected first, so it does not close your resting order.

## Price ticks and protection

The price step depends on the market's `tick_precision` and the size of the price, so it is not a fixed number of decimals. A price that is not on a valid step is rejected, not rounded. See the [price examples](https://docs.aultblockchain.com/dex-api/trading/place-or-modify-order.md#tick-examples).

Spot market orders are limited to a price band around the last trade, and you can set a tighter band. A market with no trades cannot accept market orders.

## Order lifecycle

1. **Orders can be rejected.** An order can be rejected for its price step, size, minimum value, or the account's order count. The minimum value is currently 10 in the market's quote asset, such as 10 USDC. Each order in a Scale must meet it, a TWAP must total at least 100, and a reduce-only order that closes a full position is exempt. Every limit order needs a deadline.
2. **Changing the size keeps your place.** A quantity-only change keeps the order ID and queue position. Changing the price creates a new order ID and queue position. The new size is the total including fills: after 3 of 10 units fill, setting the size to 5 leaves 2 open.
3. **A fill beats a cancel.** If a fill is committed first, it stands. Canceling a partly filled order releases only the unfilled part.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.