# POST Close Position

## Close a specific position by instrument

<mark style="color:orange;">`POST`</mark> `/v1/api/accounts/{account}/positions/close`

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Path Parameters**

<table><thead><tr><th width="180">Name</th><th width="133">Type</th><th width="130">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>account</code></td><td>string</td><td><mark style="color:red;">Required</mark></td><td>Name of account in NT8</td></tr></tbody></table>

**Body**

<table><thead><tr><th width="179">Name</th><th width="135">Type</th><th width="128">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>instrument</code></td><td>string</td><td><mark style="color:red;">Required</mark></td><td>Name of underlying instrument</td></tr><tr><td><code>quantity</code></td><td>integer</td><td>Optional</td><td>Quantity of contracts to close</td></tr><tr><td><code>percent</code></td><td>float</td><td>Optional</td><td>% of remaining contracts to close</td></tr></tbody></table>

**Code Examples**

{% tabs %}
{% tab title="Python" %}

```python
import requests

url = "https://app.crosstrade.io/v1/api/accounts/Sim101/positions/close"
headers = {
    "Authorization": "Bearer frvO0lK6cXe9ML5ITNlEduwP5J1oNzLT0XTBRjR_OZ0",
    "Content-Type": "application/json"
}
data = {
    "instrument": "MES 12-25",
    "quantity": 4,
    # "percent": 0.25
}
try:
    response = requests.post(url, headers=headers, json=data)
    print(f"Response Code: {response.status_code}, Response Text: {response.text}")
except Exception as e:
    print(f"An error occurred: {e}")
```

{% endtab %}
{% endtabs %}

***

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "closedPositions": [
        {
            "type": "NinjaTrader.Cbi.Position",
            "account": "Sim101",
            "instrument": "ES 12-25",
            "instrumentType": "Future",
            "marketPosition": "Long",
            "quantity": 4,
            "averagePrice": 5779.8125,
            "marketPrice": 5797.0,
            "unrealizedProfitLoss": 3437.5
        }
    ],
    "success": true
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "error": "No positions found for instrument 'ES 12-24'"
}
```

{% endtab %}
{% endtabs %}

#### WebSocket API

This request can also be made over the WebSocket API. The `account` path parameter and request body fields are all passed inside `args`.

```json
{
  "action": "rpc",
  "id": "my-request-id",
  "api": "ClosePosition",
  "args": {
    "account": "Sim101",
    "instrument": "ES 09-26"
  }
}
```
