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

# Cancel Order

> Cancel an open order

## Overview

Cancel an open or partially filled order. Only orders with status `open` or `partially_filled` can be cancelled.

## Authentication

<ParamField header="X-Api-Key" type="string" required>
  Your API key with Trade scope

  ```
  X-Api-Key: daya_sk_YOUR_API_KEY
  ```
</ParamField>

## Path Parameters

<ParamField path="order_id" type="string" required>
  The unique order identifier (UUID) to cancel

  **Example:** `550e8400-e29b-41d4-a716-446655440000`
</ParamField>

## Request Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl --request DELETE \
    --url https://api.pro.daya.co/public/v1/orders/550e8400-e29b-41d4-a716-446655440000 \
    --header 'X-Api-Key: daya_sk_YOUR_API_KEY'
  ```

  ```javascript JavaScript theme={null}
  const orderId = '550e8400-e29b-41d4-a716-446655440000';

  const response = await fetch(
    `https://api.pro.daya.co/public/v1/orders/${orderId}`,
    {
      method: 'DELETE',
      headers: { 'X-Api-Key': 'daya_sk_YOUR_API_KEY' }
    }
  );

  const result = await response.json();
  console.log('Order cancelled:', result.success);
  ```

  ```python Python theme={null}
  import requests

  order_id = '550e8400-e29b-41d4-a716-446655440000'
  headers = {'X-Api-Key': 'daya_sk_YOUR_API_KEY'}

  response = requests.delete(
      f'https://api.pro.daya.co/public/v1/orders/{order_id}',
      headers=headers
  )

  result = response.json()
  print(f"Order cancelled: {result['success']}")
  ```

  ```go Go theme={null}
  package main

  import (
      "encoding/json"
      "fmt"
      "net/http"
  )

  func main() {
      orderID := "550e8400-e29b-41d4-a716-446655440000"
      url := fmt.Sprintf("https://api.pro.daya.co/public/v1/orders/%s", orderID)

      req, _ := http.NewRequest("DELETE", url, nil)
      req.Header.Set("X-Api-Key", "daya_sk_YOUR_API_KEY")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      var result map[string]interface{}
      json.NewDecoder(resp.Body).Decode(&result)
      fmt.Println("Order cancelled:", result["success"])
  }
  ```
</CodeGroup>

## Response

<ResponseField name="success" type="boolean" required>
  Indicates if the request was successful
</ResponseField>

<ResponseField name="message" type="string" required>
  Human-readable response message
</ResponseField>

<ResponseField name="data" type="null">
  Returns `null` on successful cancellation
</ResponseField>

<ResponseField name="timestamp" type="string">
  ISO 8601 timestamp of the response
</ResponseField>

### Success Response

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "success": true,
    "message": "Order cancelled successfully",
    "data": null,
    "timestamp": "2024-01-15T10:40:00Z"
  }
  ```
</ResponseExample>

## Error Responses

<ResponseExample>
  ```json 401 Unauthorized theme={null}
  {
    "success": false,
    "message": "Unauthorized",
    "error": {
      "code": "API_KEY_INVALID",
      "message": "The provided API key is invalid"
    },
    "timestamp": "2024-01-15T10:40:00Z"
  }
  ```

  ```json 403 Forbidden - Insufficient scope theme={null}
  {
    "success": false,
    "message": "Forbidden",
    "error": {
      "code": "API_KEY_INVALID_SCOPE",
      "message": "API key does not have the required Trade scope"
    },
    "timestamp": "2024-01-15T10:40:00Z"
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "success": false,
    "message": "Order not found",
    "error": {
      "code": "ORDER_NOT_FOUND",
      "message": "The specified order does not exist"
    },
    "timestamp": "2024-01-15T10:40:00Z"
  }
  ```

  ```json 400 Bad Request - Order not cancellable theme={null}
  {
    "success": false,
    "message": "Order cannot be cancelled",
    "error": {
      "code": "ORDER_NOT_CANCELLABLE",
      "message": "Order is already filled and cannot be cancelled"
    },
    "timestamp": "2024-01-15T10:40:00Z"
  }
  ```
</ResponseExample>

## Cancellable Order Statuses

| Status               | Can Cancel? |
| -------------------- | ----------- |
| `pending_settlement` | No          |
| `new`                | Yes         |
| `open`               | Yes         |
| `partially_filled`   | Yes         |
| `filled`             | No          |
| `cancelled`          | No          |
| `rejected`           | No          |
| `failed`             | No          |

<Warning>
  When cancelling a partially filled order, the filled portion remains executed. Only the remaining unfilled quantity is cancelled.
</Warning>

## Rate Limits

* **100 requests per minute** per API key

## Next Steps

<CardGroup cols={2}>
  <Card title="Place Order" icon="arrow-right-arrow-left" href="/pro/api-reference/place-order">
    Place a new order
  </Card>

  <Card title="List Orders" icon="list" href="/pro/api-reference/list-orders">
    View your orders
  </Card>
</CardGroup>
