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

# Order History

> Query your terminated orders — filled, cancelled, rejected, or triggered. Paginated by time window and filterable by contract.

The `orderHistory` query returns your account's **terminated** orders: fully filled, cancelled, rejected, or conditional orders that have triggered or been cancelled. Orders that are still resting or only partially filled do **not** appear here — query those with [`userOrders`](/info/user-orders).

It shares its request parameters, pagination contract, and value conventions with [`userFills`](/info/user-fills) and [`userFundingFlows`](/info/user-funding-flows).

## Request

```json theme={null}
{"type": "orderHistory", "accountId": "5"}
```

<ParamField body="type" type="string" required>
  Must be `"orderHistory"`.
</ParamField>

<ParamField body="accountId" type="string" required>
  Your account ID. Must be greater than zero. A numeric value is also accepted.
</ParamField>

<ParamField body="contractId" type="int">
  Restrict results to one contract. Use `0` or omit for all contracts.
</ParamField>

<ParamField body="startTime" type="int64">
  Inclusive start of the time window, in Unix milliseconds. `0` or omitted means unbounded.
</ParamField>

<ParamField body="endTime" type="int64">
  Inclusive end of the time window, in Unix milliseconds. `0` or omitted means unbounded. A `startTime` later than `endTime` returns `400 BAD_REQUEST`.
</ParamField>

<ParamField body="limit" type="int">
  Maximum rows in this page. Defaults to **1000**, which is also the maximum; a larger value returns `400 BAD_REQUEST`.
</ParamField>

## Response

```json theme={null}
{
  "type": "orderHistory",
  "accountId": "5",
  "contractIdFilter": 0,
  "orders": [
    {
      "updatedTimeMs": 1700000000002,
      "height": 42,
      "seq": 3,
      "orderId": "101",
      "clientOrderId": "777",
      "contractId": 7,
      "marketDeployerId": 5,
      "orderSide": "S",
      "orderType": "SL",
      "timeInForce": "Gtc",
      "reduceOnly": true,
      "triggerPrice": "49000",
      "triggerPriceType": 1,
      "price": "50000",
      "origQty": "10",
      "filledQty": "10",
      "leavesQty": "0",
      "status": "Filled",
      "origin": "PassiveFill",
      "cancelReason": -1,
      "rejectCode": 26,
      "createdTimeMs": 1700000000001
    }
  ],
  "count": 1,
  "truncated": false
}
```

### Envelope fields

<ResponseField name="contractIdFilter" type="int">
  Echoes the `contractId` filter that was applied. `0` means no filter.
</ResponseField>

<ResponseField name="count" type="int">
  Number of rows in this page. When `count` equals your `limit`, another page may be available.
</ResponseField>

<ResponseField name="truncated" type="boolean">
  `true` when the page was cut short at a row boundary because the response reached its byte ceiling.
</ResponseField>

### Order object fields

<ResponseField name="updatedTimeMs" type="number">
  Time the order reached its final state, in Unix milliseconds. This is the field you page on.
</ResponseField>

<ResponseField name="height" type="number">
  Block height at which the order was finalized.
</ResponseField>

<ResponseField name="seq" type="number">
  Sequence number within the block.
</ResponseField>

<ResponseField name="orderId" type="string">
  Exchange-assigned order ID.
</ResponseField>

<ResponseField name="clientOrderId" type="string | null">
  The client order ID you assigned at placement, or `null` when none was set.
</ResponseField>

<ResponseField name="contractId" type="number">
  Contract the order was placed on.
</ResponseField>

<ResponseField name="marketDeployerId" type="number">
  Market deployer the contract belongs to.
</ResponseField>

<ResponseField name="orderSide" type="string">
  `"B"` for buy, `"S"` for sell.
</ResponseField>

<ResponseField name="orderType" type="string">
  `L`, `M`, `SL`, `SM`, `TPL`, or `TPM`. See the enum table below.
</ResponseField>

<ResponseField name="timeInForce" type="string">
  `Gtc`, `Alo`, `Ioc`, or `Fok`.
</ResponseField>

<ResponseField name="reduceOnly" type="boolean">
  `true` when the order could only reduce an existing position.
</ResponseField>

<ResponseField name="triggerPrice" type="string">
  Trigger price for a conditional or TP/SL order (raw integer string). `"0"` for an ordinary order.
</ResponseField>

<ResponseField name="triggerPriceType" type="number">
  Which price feed the trigger watched: `0` for mark price, `1` for oracle price.
</ResponseField>

<ResponseField name="price" type="string">
  Limit price of the order (raw integer string).
</ResponseField>

<ResponseField name="origQty" type="string">
  Original order quantity (raw integer string).
</ResponseField>

<ResponseField name="filledQty" type="string">
  Quantity filled before the order terminated.
</ResponseField>

<ResponseField name="leavesQty" type="string">
  Quantity still unfilled when the order terminated.
</ResponseField>

<ResponseField name="status" type="string">
  `Open`, `Filled`, `Canceled`, or `Untriggered`.
</ResponseField>

<ResponseField name="origin" type="string">
  How the order came about. See the enum table below.
</ResponseField>

<ResponseField name="cancelReason" type="number">
  Signed cancellation reason. `-1` indicates a cancellation internal to the matching engine.
</ResponseField>

<ResponseField name="rejectCode" type="number">
  Rejection code for a rejected order.
</ResponseField>

<ResponseField name="createdTimeMs" type="number">
  Time the order was created, in Unix milliseconds.
</ResponseField>

<Note>
  There is no order-level fee or realized-PnL total in this response. Derive both by summing the matching rows in [`userFills`](/info/user-fills) for the same `orderId`.
</Note>

## Pagination

Rows come back in ascending `updatedTimeMs` order, at most `limit` per page. Pass the last row's `updatedTimeMs` as the next request's `startTime`; because `startTime` is inclusive, deduplicate the repeated boundary row by `orderId`. A page with `count` below `limit` is the last one. See [`userFills`](/info/user-fills) for the full walkthrough.

### Enumerations

| Field                  | Values                                                                                                                       |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `orderSide`            | `B` (buy) · `S` (sell)                                                                                                       |
| `orderType`            | `L` (limit) · `M` (market) · `SL` (stop limit) · `SM` (stop market) · `TPL` (take-profit limit) · `TPM` (take-profit market) |
| `timeInForce`          | `Gtc` · `Alo` (post-only) · `Ioc` · `Fok`                                                                                    |
| `status`               | `Open` · `Filled` · `Canceled` · `Untriggered`                                                                               |
| `origin`               | `Normal` · `Modify` · `Liquidation` · `Conditional` · `PassiveFill` · `Cancel`                                               |
| Any unrecognized value | `Unknown`                                                                                                                    |
