> ## 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.

# modify: Update an Open Order Price, Size, or TIF

> Modify a resting order's price, quantity, time-in-force, or client order ID. Locate the order by exchange order ID or client order ID.

The `modify` action updates a resting (OPEN status) order without requiring you to cancel and replace it. You can change the price, total size, time-in-force (Gtc or Alo only), and client order ID. Direction (`b`), contract (`a`), and `reduceOnly` (`r`) cannot be changed — cancel the order and place a new one if you need to alter those fields.

## Endpoint

```
POST https://dev.upsidemax.xyz/exchange
Content-Type: application/json
```

## Priority Rules

How you locate and modify the order determines whether it retains its queue position:

* **Same price, reduce size only** — the modification is applied in-place. The order keeps its existing FIFO queue priority.
* **Change price, increase size, or change TIF/cloid** — the order is removed from its current position and re-queued at the back of the new price level. It loses its original queue priority.

<Warning>
  If the new price would immediately cross the book and match against a resting opposite-side order, the modification request is rejected. Cancel the order and place a new one to execute at a marketable price.
</Warning>

## Request Body

<Tabs>
  <Tab title="Locate by Order ID">
    Use `oid` to identify the order by the exchange-assigned ID returned in `resting.oid`.

    ```json theme={"system"}
    {
      "action": {
        "type": "modify",
        "a": 1,
        "oid": 12345,
        "p": "150",
        "s": "8",
        "tif": "Gtc"
      },
      "signature": { "r": "0x...", "s": "0x...", "v": 28 },
      "nonce": 1778858100000
    }
    ```
  </Tab>

  <Tab title="Locate by Client Order ID">
    Use `cloid` to find the order by its client-assigned ID, and optionally update the client order ID at the same time with `c`.

    ```json theme={"system"}
    {
      "action": {
        "type": "modify",
        "a": 1,
        "cloid": "1778763737044",
        "p": "151",
        "c": "1778858200000"
      },
      "signature": { "r": "0x...", "s": "0x...", "v": 28 },
      "nonce": 1778858200100
    }
    ```
  </Tab>
</Tabs>

## Action Fields

<ParamField body="type" type="string" required>
  Fixed value: `"modify"`.
</ParamField>

<ParamField body="a" type="int32" required>
  **asset** — The integer contract ID of the order to modify.
</ParamField>

<ParamField body="oid" type="int64">
  **orderId** — Exchange-assigned order ID from `resting.oid`. Takes priority over `cloid` when both are provided. At least one of `oid` or `cloid` must be present.
</ParamField>

<ParamField body="cloid" type="string">
  **clientOrderId (locate)** — Client order ID used to find the order when `oid` is not provided. Must match the `c` field set at placement.
</ParamField>

<ParamField body="p" type="string">
  **price** — New limit price as a decimal string. Omit to keep the existing price unchanged.
</ParamField>

<ParamField body="s" type="string">
  **size** — New total target size as a decimal string. This is the **total** quantity including any already-filled amount, not just the remaining leaves size. Omit to keep the existing size unchanged.
</ParamField>

<ParamField body="tif" type="string">
  **timeInForce** — New time-in-force for the order. Only `"Gtc"` (good-til-cancel) or `"Alo"` (add-liquidity-only / post-only) are accepted. Omit to keep the existing TIF unchanged.
</ParamField>

<ParamField body="c" type="string">
  **clientOrderId (update)** — New client order ID to assign to the order after modification. Omit to keep the existing client order ID unchanged.
</ParamField>

<Note>
  You must provide at least one of `oid` or `cloid` to identify the order. All other fields (`p`, `s`, `tif`, `c`) are optional — include only the fields you want to change.
</Note>

## Responses

<Tabs>
  <Tab title="Success">
    The order was modified. The response reflects the new state of the order.

    ```json theme={"system"}
    {
      "status": "ok",
      "response": {
        "type": "modify",
        "data": {
          "orderId": 12345,
          "limitPrice": 150,
          "totalSize": 8,
          "leavesSize": 5,
          "clientOrderId": 1778858200000
        }
      }
    }
    ```
  </Tab>

  <Tab title="Rejected">
    The modification was rejected. Check `errorCode` and `errorMessage` for the reason.

    ```json theme={"system"}
    {
      "status": "ok",
      "response": {
        "type": "modify",
        "data": {
          "orderId": 0,
          "limitPrice": 0,
          "totalSize": 0,
          "leavesSize": 0,
          "clientOrderId": 0,
          "errorCode": 7,
          "errorMessage": "orderId not found"
        }
      }
    }
    ```
  </Tab>
</Tabs>

### Response Fields

<ResponseField name="orderId" type="int64">
  The unchanged exchange-assigned order ID of the modified order.
</ResponseField>

<ResponseField name="limitPrice" type="number">
  The new limit price after the modification is applied.
</ResponseField>

<ResponseField name="totalSize" type="number">
  The new total size of the order (including already-filled quantity).
</ResponseField>

<ResponseField name="leavesSize" type="number">
  The remaining unfilled quantity still resting in the book after the modification.
</ResponseField>

<ResponseField name="clientOrderId" type="number">
  The updated client order ID. Reflects the new value if `c` was provided, or the previous value if it was not.
</ResponseField>

<ResponseField name="errorCode" type="int">
  Absent or `0` indicates success. Any non-zero value indicates a rejection; read `errorMessage` for details. On rejection, all numeric fields are `0`.
</ResponseField>

<ResponseField name="errorMessage" type="string">
  Human-readable rejection reason. Only present when `errorCode` is non-zero.
</ResponseField>

## Known Errors

| errorMessage                                                                                | Cause                                                                                               |
| ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `orderId not found`                                                                         | The `oid` or `cloid` does not match any active order                                                |
| `clOrdId not found`                                                                         | Located by `cloid`, but no matching active order was found                                          |
| `order already canceled`                                                                    | The target order was already cancelled before this request arrived                                  |
| `order not open`                                                                            | The order is in a terminal state (fully filled or cancelled)                                        |
| `new size must exceed already-filled amount`                                                | The requested `s` is less than or equal to the quantity already filled                              |
| `modify supports resting TIF only (GTC / POST_ONLY)`                                        | `tif` was set to `"Ioc"` or another non-resting value                                               |
| `modified price is marketable (would cross the book); cancel and place a new order instead` | The new `p` would immediately match against a resting opposite-side order                           |
| `newClientOrderId already in use by an active order`                                        | The `c` value collides with another active order's client order ID                                  |
| `insufficient margin for modified order`                                                    | Increasing `s` would require more margin than is available; the change is automatically rolled back |
