# Cancel an order

`POST /dex/orders/{boxId}/cancel` · Lithos client API · Lithos Dex · requires the `api_key` header

Source: https://lithosprotocol.org/docs/api/cancel-ld-order

Return an outstanding order's ERG and tokens to this wallet, on any pool of either kind. Accepted while the order is `PENDING` or `OPEN`. A fill sent before the cancel can still confirm first, and the cancel is then dropped. No body.

## Parameters

| Name | In | Type | Required | Description |

|---|---|---|---|---|

| `boxId` | path | string | yes | Order box id, as listed by `GET /dex/orders` |

## Responses

### 200: Result of the cancel transaction

`LDOrderCancelResult`

- `outcome` (string, required, one of accepted, rejected, uncertain): Node submission outcome; uncertain retains the known transaction ID and input ownership.
- `txId` (string, required)
- `returnedNanoErgs` (string, required): nanoERG the order box held, returned to this wallet. Decimal string.
- `returnedTokens` (LDTokenAmount[], required): Tokens the order box held, returned to this wallet
  - `tokenId` (string, required)
  - `amount` (string, required): Raw token units. Decimal string.
- `networkFee` (string, required): nanoERG paid for the cancel, taken from the order box when it holds enough and from the wallet otherwise. Decimal string. 

### 404: No outstanding order owned by this wallet with that id.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 409: An unconfirmed transaction is already filling or cancelling the order. Re-read `GET /dex/orders`.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 422: Neither the order nor the wallet can cover the network fee.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 503: Node or wallet unavailable. Retry.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### default: Error

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

## Example request

```bash
curl -X POST "http://localhost:9000/dex/orders/{boxId}/cancel" \
  -H "api_key: $LITHOS_API_KEY"
```

## Example response

```json
{
  "outcome": "accepted",
  "txId": "40b7d045a858d537cdbf072e46ffbb86c0c9f6b0e93c369c1ffcba76797636d7",
  "returnedNanoErgs": "5604000000",
  "returnedTokens": [
    {
      "tokenId": "86e272f770aa4ef48ad7e6d6dbe98b5069edd8383a403a8edb3ceed8a3d5cea3",
      "amount": "152000000"
    }
  ],
  "networkFee": "2000000"
}
```
