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

# Cancel Off-Chain Order

> Withdraw a resting off-chain order and unlock the balance behind it

Cancels an order placed through the off-chain surface. The `customerRef` in the body must match the one the order was placed under: an order belongs to a customer reference, not to a wallet.

Only `OPEN` and `PARTIALLY_FILLED` orders can be cancelled. Anything else reads as `ORDER_NOT_FOUND`.

The order is removed from the in-memory book, so the depth disappears at once, and the unfilled remainder of the ledger lock is released. A release failure is logged rather than surfaced, and the cancel still succeeds.

## Path Parameters

<ParamField path="orderId" type="string" required>The order's `orderId`. Up to 100 characters.</ParamField>

## Body Parameters

<ParamField body="customerRef" type="string" required>
  Reference the order was placed under, 1 to 256 characters.
</ParamField>

## Response Fields

Returns the cancelled order, with `status: "CANCELLED"` and `cancelReason: "USER_CANCELLED"`.

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.trusset.org/orderbooks/stocks/api/offchain/orders/b7c1e0d4-6f2a-4f1e-9d33-5c8a1f0b2e77" \
    -H "X-API-Key: trusset_your_key_here" \
    -H "Content-Type: application/json" \
    -d '{ "customerRef": "cust_1042" }'
  ```

  ```typescript TypeScript theme={null}
  const res = await fetch(
    `https://api.trusset.org/orderbooks/stocks/api/offchain/orders/${orderId}`,
    {
      method: 'DELETE',
      headers: {
        'X-API-Key': 'trusset_your_key_here',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ customerRef: 'cust_1042' })
    }
  );
  const { data } = await res.json();
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "orderId": "b7c1e0d4-6f2a-4f1e-9d33-5c8a1f0b2e77",
      "orderBookId": "clx_ob_stock_001",
      "userAddress": "offchain:cust_1042",
      "side": "BUY",
      "orderType": "LIMIT",
      "price": "182350000",
      "quantity": "5000000",
      "filledQuantity": "1000000",
      "remainingQuantity": "4000000",
      "status": "CANCELLED",
      "cancelReason": "USER_CANCELLED",
      "updatedAt": "2025-06-15T12:06:00.000Z"
    }
  }
  ```
</ResponseExample>

## Error Codes

| Code                   | HTTP  | Cause                                                                     |
| ---------------------- | ----- | ------------------------------------------------------------------------- |
| `VALIDATION_ERROR`     | `400` | `customerRef` is missing or out of range                                  |
| `INVALID_PARAM`        | `400` | `orderId` is missing or longer than 100 characters                        |
| `ORDER_NOT_FOUND`      | `404` | No open order with that ID under this customer reference on your instance |
| `TOKEN_NOT_REGISTERED` | `400` | The token to unlock is not registered in your custody ledger              |
