# Close Position

Close an open position fully or partially by ticket, or close all positions on a symbol.

`POST https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition`

- API: Account API (v2)
- Authentication: Send the account token as `Authorization: Bearer <ACCOUNT_TOKEN>`. See [Authentication](/authentication/).

Square off open MetaTrader 5 positions. Close one position by ticket (optionally only part of its volume), or close every position on a symbol, optionally only the BUY or SELL side.

## Request body (JSON)

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `ticket` | integer | no |  | Ticket of the position to close. |
| `volume` | number | no |  | Lots to close for a partial close. Used with `ticket`. Omit to close the full position. |
| `symbol` | string | no |  | Close positions on this symbol. Use instead of `ticket`. |
| `side` | string | no |  | Only close `BUY` or `SELL` positions on `symbol`. Omit to close both sides. |

## Example: cURL

```bash
curl -X POST https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition \
  -H "Authorization: Bearer $ACCOUNT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "symbol": "EURUSD"
}'
```

## Example: Python

```python
import os
import requests

res = requests.post(
    "https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition",
    headers={"Authorization": f"Bearer {os.environ['ACCOUNT_TOKEN']}"},
    json={
        "symbol": "EURUSD"
    },
    timeout=30,
)
data = res.json()
print(data["status"], data.get("msg"), data.get("data"))
```

### Partial close by ticket

```json
{
  "ticket": 1093765759,
  "volume": 0.25
}
```

### Close all SELL positions on a symbol

```json
{
  "symbol": "EURUSD",
  "side": "SELL"
}
```

## Response

Standard envelope: `status` (boolean), `msg` (string), `data` (object or array).

## Notes

- Send either `ticket` (with optional `volume`), or `symbol` (with optional `side`).

## Related

- [Get Open Positions](https://docs.algodeltafx.com/api/get-open-positions.md): List every open position on the MT5 account.
- [Place Order](https://docs.algodeltafx.com/api/place-order.md): Open a market order or place a pending order (limit, stop, stop-limit) on an MT5 account.
- [Cancel Order](https://docs.algodeltafx.com/api/cancel-order.md): Cancel a pending order by ticket, or all pending orders for a symbol and side.


---
Source: https://docs.algodeltafx.com/api/close-position/
