# Close all open positions (TRADE)

## API Description

Closes every open position on the account, optionally filtered to one symbol. Pending orders are
**not** cancelled — use [`DELETE /v1/order`](/trade/cancel-pending-order.md) for those.

## HTTP Request

```http
DELETE /v1/allOpenPositions
```

## Request Weight

5 (1 against `ORDERS`, regardless of how many positions close)

## Request Parameters

| Name | Type | Mandatory | Description |
| - | - | - | - |
| `login` | LONG | YES | |
| `symbol` | STRING | NO | Close only this symbol's positions. Exact, case-sensitive. |
| `newClientOrderId` | STRING | NO | Idempotency key for the whole sweep. |
| `recvWindow`, `timestamp`, `signature` | | | |

> **Omitting `symbol` closes every open position on the account, on every symbol.** There is no
> confirmation step. Send `symbol` unless you mean to flatten the account.

The sweep snapshots the open positions at the moment it runs and closes those. A position opened
after the snapshot is not closed. It is not a "keep the account flat" mode.

> **A retry replays the ORIGINAL snapshot.** Resending with the same `newClientOrderId` returns the
> legs of the first sweep and closes nothing that was opened afterwards — including when the first
> sweep found nothing and answered `requested: 0`, which stays `0` on every repeat. To sweep again,
> send a **fresh** `newClientOrderId`. Legs the service could not confirm as queued are re-queued
> under their own existing keys, so a retry is safe without being a second sweep.

## Response Example

**Response** — one entry per position it attempted to close.

```json
{
  "login": 100123,
  "clientOrderId": "bot-flatten-1",
  "requested": 2,
  "status": "ACCEPTED",
  "transactTime": 1789012700100,
  "positions": [
    {"positionId": 44412345, "symbol": "XAUUSD", "volume": "0.10", "status": "ACCEPTED"},
    {"positionId": 44412360, "symbol": "BTCUSD", "volume": "0.05", "status": "ACCEPTED"}
  ]
}
```

| Field | Type | Description |
| - | - | - |
| `requested` | INT | Positions found in the snapshot. `0` with an empty `positions` array when the account is already flat — this is a success, not an error. |
| `status` | ENUM | `ACCEPTED` once every close is queued. Per-position outcomes arrive on the user data stream. |
| `positions[].status` | ENUM | Per-position status, same values as a single close. |
