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

# Order statuses

> What each order status means and which ones are final.

| `status` | Final | Meaning |
| - | - | - |
| `pending` | No | Lean accepted the order. The venue has not confirmed it yet. |
| `open` | No | Resting on the venue's book. |
| `partially_filled` | No | Some shares filled; the rest is still working. |
| `cancel_requested` | No | You canceled the order and the venue has not confirmed the cancel yet. It ends `canceled`, or `filled` if a fill beat the cancel. `filled_quantity` shows any shares filled so far. |
| `filled` | Yes | Every share filled. |
| `canceled` | Yes | Canceled by you, or the unfilled part of an `ioc` order. `filled_quantity` shows any shares that filled first; an `ioc` order that matched nothing is `canceled` with `0`. A canceled `ioc` order has `status_reason.code` `IOC_REMAINDER_CANCELED`. |
| `rejected` | Yes | Not placed. `status_reason.code` and `status_reason.message` say why. |
| `expired` | Yes | The venue expired the order. |
| `unconfirmed` | No | The venue did not confirm the order, so it may or may not be on the venue. Read it back by `client_order_id`; do not resend it. `status_reason.code` is `SUBMISSION_UNKNOWN`. |
| `needs_attention` | No | A leg Lean cannot settle on its own. It stays live until Lean's operators resolve it. `status_reason.code` is `NEEDS_ATTENTION` or a more specific code. |

`status_reason` is `{ code, message }` on `rejected`, `unconfirmed` and `needs_attention`, and on a
canceled `ioc` order and its canceled legs. It is `null` otherwise. On `rejected`, `unconfirmed` and
`needs_attention` the order copies it from the first leg in the order's status.

| `status_reason.code` | Meaning |
| - | - |
| `VENUE_REJECTED` | The venue refused the order. A venue rejection can carry a more specific venue code instead. |
| `SUBMISSION_UNKNOWN` | The venue did not confirm the submit. |
| `VENUE_UNKNOWN` | An unconfirmed order the venue still had no record of ten minutes after placement. |
| `NEEDS_ATTENTION` | Lean cannot settle the leg on its own. |
| `ROUTE_PAYMENT_FAILED` | The routed order's payment did not go through. |
| `IOC_REMAINDER_CANCELED` | An `ioc` order or leg ended `canceled`: the venue canceled whatever did not fill at once. `filled_quantity` is what filled, `0` if nothing matched. |

New codes can appear without a new version; treat one you do not recognize by the order's
`status`.

`venue_status` carries the venue's own state, and `venue_order_id` its order ID, for your
reconciliation. On a split order both are `null`. Each entry in `legs` has its own `status`,
`status_reason`, `venue_status` and `venue_order_id`, and the order's `status` is worked out from all
of them:

* When every leg is final, the order is `filled` if every leg filled. Otherwise it is `canceled` if any
  leg filled or was canceled, then `expired`, then `rejected`.
* While any leg is working, the first that applies wins: `needs_attention`, `unconfirmed`,
  `cancel_requested` (a leg waits on its venue to confirm a cancel), `partially_filled` (any shares
  filled), `open`, `pending`.

## Typical paths

```mermaid theme={"dark"}
stateDiagram-v2
  [*] --> pending
  pending --> open
  pending --> filled
  pending --> canceled
  pending --> rejected
  pending --> unconfirmed
  unconfirmed --> open
  unconfirmed --> filled
  unconfirmed --> rejected
  open --> partially_filled
  open --> filled
  open --> canceled
  open --> expired
  partially_filled --> filled
  partially_filled --> canceled
  open --> cancel_requested
  partially_filled --> cancel_requested
  cancel_requested --> canceled
  cancel_requested --> filled
```

`needs_attention` can follow any working status and is left out of the diagram.

An `ioc` order never rests: it ends `filled`, or `canceled` with whatever filled first, `0` if
nothing matched, and `status_reason.code` `IOC_REMAINDER_CANCELED`.


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