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

# Order Entry — Modify Order

Orders can be modified over **WebSocket**.\
Only **`price`**, **`quantity`**, **`take_profit`**, and **`stop_loss`** may be changed.

* You **must** specify the order’s **`order_id`** (UUID v4).
* You **must** specify the **`symbol`**.
* You **must** specify the **`side`**.
* You **must** specify the **`order_type`**.
* `client_order_id` cannot be used for modifies.

## 1) Authenticate

Send this immediately after you connect:

```json theme={null}
{ "type": "auth", "params": { "hmac": { "public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..." } } }
```

## 2) Modify Order

```json theme={null}
{
  "type": "modify_order",
  "params": {
    "order_id": "510333ac-3f7b-4d88-934a-4396d48824cc",
    "symbol": "AAPL-USD",
    "side": "BUY",
    "quantity": 2,
    "price": 200,
    "take_profit": 200,
    "stop_loss": 150
  }
}
```

## Parameters

| Field         | Type   | Required | Description                                                                                        |
| ------------- | ------ | -------- | -------------------------------------------------------------------------------------------------- |
| `order_id`    | string | ✅        | UUID v4 of the order to modify.                                                                    |
| `symbol`      | string | ✅        | The market symbol (e.g. `AAPL-USD`).                                                               |
| `side`        | enum   | ✅        | Must match the original order’s side. See [OrderDirection](/api-reference/enums#orderdirection).   |
| `order_type`  | enum   | ✅        | Must match the original order’s type. See [OrderType](/api-reference/enums#OrderType).             |
| `quantity`    | number | Optional | New order quantity. Must respect symbol lot size, min, and max constraints.                        |
| `price`       | number | Optional | New price for limit/ALO orders. Ignored for market orders. Must respect tick size and price bands. |
| `take_profit` | number | Optional | Updated take-profit price. Set `0` if unused.                                                      |
| `stop_loss`   | number | Optional | Updated stop-loss price. Set `0` if unused.                                                        |

> ⚠️ Notes:
>
> * Only `price`, `quantity`, `take_profit`, and `stop_loss` may be modified.
> * `client_order_id` cannot be used for modifies.
> * **The `order_id` changes on modification.** The response will contain a **new** `order_id`. The old `order_id` is replaced. This is because multiple in-flight amends are not currently supported.
> * Modifications that would cause an invalid state (e.g. reducing below partially filled quantity) will be rejected with [OrderStatus](/api-reference/enums#orderstatus) codes such as `CANNOT_MODIFY_PARTIAL_FILL` or `CANNOT_MODIFY_NO_SUCH_ORDER`.

## Sample Code

<CodeGroup>
  ```python python theme={null}
  # Python (websocket-client)
  import json, websocket

  API_KEY = "YOUR_API_KEY"

  def send(ws, obj): ws.send(json.dumps(obj))

  def on_open(ws):
      # Authenticate
      # https://docs.qfex.com/websocket/channels/trade/authenticate#how-it-works
      send(ws, {"type": "auth", "params": { "hmac": { "public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..." }}})
      # Modify order
      send(ws, {
          "type": "modify_order",
          "params": {
              "order_id": "510333ac-3f7b-4d88-934a-4396d48824cc",
              "symbol": "AAPL-USD",
              "side": "BUY",
              "order_type": "LIMIT",
              "quantity": 2,
              "price": 200,
              "take_profit": 200,
              "stop_loss": 150
          }
      })

  ws = websocket.WebSocketApp(
      "wss://trade.qfex.com?api_key=YOUR_API_KEY",
      on_open=on_open,
      on_message=lambda _, m: print("Message:", m)
  )
  ws.run_forever()
  ```

  ```javascript node theme={null}
  // Node.js (ws)
  import WebSocket from "ws";
  const ws = new WebSocket("wss://trade.qfex.com?api_key=YOUR_API_KEY");
  const API_KEY = "YOUR_API_KEY";

  ws.on("open", () => {
    // Authenticate
    ws.send(JSON.stringify({ type: "auth", params: { api_key: API_KEY } }));
    // Modify order
    ws.send(
      JSON.stringify({
        type: "modify_order",
        params: {
          order_id: "510333ac-3f7b-4d88-934a-4396d48824cc",
          symbol: "AAPL-USD",
          side: "BUY",
          order_type: "LIMIT",
          quantity: 2,
          price: 200,
          take_profit: 200,
          stop_loss: 150,
        },
      })
    );
  });

  ws.on("message", (msg) => console.log("Message:", msg.toString()));
  ```

  ```go go theme={null}
  // Go (gorilla/websocket)
  package main

  import (
  	"log"
  	"github.com/gorilla/websocket"
  )

  func mustWriteJSON(c *websocket.Conn, v any) {
  	if err := c.WriteJSON(v); err != nil { log.Fatal("write:", err) }
  }

  func main() {
  	c, _, err := websocket.DefaultDialer.Dial("wss://trade.qfex.com?api_key=YOUR_API_KEY", nil)
  	if err != nil { log.Fatal("dial:", err) }
  	defer c.Close()

  	// Authenticate
  	mustWriteJSON(c, map[string]any{
  		"type": "auth",
  		"params": map[string]any{"hmac": map[string]any{"public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..."}}
  	})

  	// Modify order
  	mustWriteJSON(c, map[string]any{
  		"type": "modify_order",
  		"params": map[string]any{
  			"order_id":           "510333ac-3f7b-4d88-934a-4396d48824cc",
  			"symbol":             "AAPL-USD",
  			"side":               "BUY",
        "order_type":         "LIMIT",
  			"quantity":           2,
  			"price":              200,
  			"take_profit":        200,
  			"stop_loss":          150,
  		},
  	})
  }
  ```

  ```java java theme={null}
  // Java (OkHttp WebSocket)
  import java.util.concurrent.TimeUnit;
  import okhttp3.*;

  public class ModifyOrderWs {
    public static void main(String[] args) {
      OkHttpClient client = new OkHttpClient.Builder()
          .pingInterval(20, TimeUnit.SECONDS).build();

      Request req = new Request.Builder()
          .url("wss://trade.qfex.com?api_key=YOUR_API_KEY").build();

      WebSocketListener li = new WebSocketListener() {
        @Override public void onOpen(WebSocket ws, Response r) {
          // Authenticate
          ws.send("{\"type\": \"auth\", \"params\": { \"hmac\": { \"public_key\": \"qfex_pub_xxxxx\", \"nonce\": \"c0ffee...\..\", \"unix_ts\": 1760545414, \"signature\": \"5f2e...\" }}}");

          // Modify order
          ws.send("{\"type\":\"modify_order\",\"params\":{\"order_id\":\"510333ac-3f7b-4d88-934a-4396d48824cc\",\"symbol\":\"AAPL-USD\",\"side\":\"BUY\",\"order_type\":\"LIMIT\",\"original_quantity\":1,\"quantity\":2,\"price\":200,\"take_profit\":200,\"stop_loss\":150}}");
        }
        @Override public void onMessage(WebSocket ws, String text) {
          System.out.println(text);
        }
      };

      client.newWebSocket(req, li);
      try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException ignored) {}
    }
  }
  ```
</CodeGroup>

## Example Response

When an order is successfully modified, you receive the same `order_response` object as with add, but with status **`MODIFIED`** and a **new** `order_id` (the old one is replaced).

```json theme={null}
{
  "order_response": {
    "order_id": "88888888-4444-4444-4444-1234567890ab",
    "symbol": "AAPL-USD",
    "status": "MODIFIED",
    "quantity": 2.0,
    "price": 200.0,
    "take_profit": 200.0,
    "stop_loss": 150.0,
    "side": "BUY",
    "type": "LIMIT",
    "time_in_force": "GTC",
    "user_id": "0020ce8e-eaee-480e-8d7f-b9241d756ee5",
    "client_order_id": "",
    "quantity_remaining": 2.0,
    "trade_id": null
  }
}
```
