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

# Order Lifecycle

> What actually happens between placing an order and having a position

An order goes through several distinct stages between the moment you place it and the moment it turns into a position. Here's the full path.

```mermaid theme={null}
flowchart TD
    A[You sign the order\nin your wallet] --> B[Quick off-chain check]
    B -- Malformed --> Z[Rejected immediately]
    B -- Looks valid --> C[Order enters the\nmarket's order book]
    C --> D{Matches an\nexisting order?}
    D -- No match yet --> E{Limit or market order?}
    E -- Limit --> F[Rests on the book,\nwaiting for a match]
    E -- Market --> G[Unmatched portion\nis dropped]
    F --> D
    D -- Matched --> H[Live checks: price,\nslippage, risk limits]
    H -- Fails --> Y[Match rejected]
    H -- Passes --> I[Sent on-chain\nfor settlement]
    I -- Succeeds --> J[Position opened,\nincreased, or closed]
    I -- Fails --> K[Rechecked against\ncurrent state]
    K -- Still valid --> I
    K -- No longer valid --> L[Cancelled,\nyou resubmit]
```

## Signing

Everything starts with your wallet. You sign the exact details of your order, market, direction, size, collateral, price boundary, and how much price movement you're willing to tolerate. See [Order Signing](/order-signing-eip712) for how that signature actually works, and [Slippage & Execution](/slippage-and-execution) for what your price and tolerance settings actually control.

## A fast sanity check

Before your order goes anywhere near the matching process, it gets a quick check, mainly to catch anything obviously malformed or forged. This is just a fast filter, not the final say, that authority always sits on-chain.

## Entering the order book

Once it passes that check, your order enters its market's order book and is immediately checked against the opposite side for a possible match, best available price first.

* If it matches right away, it moves on to live validation.
* If it doesn't match, what happens depends on the order type: a **limit order** rests on the book waiting for a future match, a **market order**'s unmatched portion is simply dropped rather than waiting. See [Off-Chain Matching Engine](/off-chain-matching-engine) for more on how that book works.

## Live validation

A match found in the book still has to clear a second, separate check against current live conditions, has the price moved too far, would this breach a risk limit, is the market even still active. This is deliberately kept apart from the book itself. See [Off-Chain Matching Engine](/off-chain-matching-engine) for why.

## Settlement

Once a match clears live validation, it's sent on-chain to actually settle. If it succeeds, your position is opened, increased, decreased, or closed depending on what the order was for. If it fails, it's rechecked against whatever's true right now and retried, if it still can't go through, it's cancelled and you'll need to submit a new order rather than waiting on the old one.

## Cancelling or letting an order expire

At any point before it's fully matched, you can cancel a resting order directly. Every order also carries an expiry, if it's still unmatched once that time passes, it's automatically swept off the book.
