# POST Reverse Position

## Combined Close Position and Place Order

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

Effectively closes the position and then executes a Place Order instruction if and only if a position already exists. A position must be already open in the specific instrument for this command to work, otherwise an error will be returned and execution will cease. It is otherwise identical to calling Close Position and the Place Order. Returns the Order ID of the newly opened position.

**Headers**

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

**Path Parameters**

<table><thead><tr><th width="168">Name</th><th width="100">Type</th><th width="106">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="167">Name</th><th width="101">Type</th><th width="104">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 (e.g., "ES 12-24")</td></tr><tr><td><code>action</code></td><td>string</td><td><mark style="color:red;">Required</mark></td><td>BUY, SELL</td></tr><tr><td><code>quantity</code></td><td>integer</td><td><mark style="color:red;">Required</mark></td><td>Contract quantity of new order</td></tr><tr><td><code>orderType</code></td><td>string</td><td><mark style="color:red;">Required</mark></td><td>MARKET, LIMIT, STOPMARKET, STOPLIMIT</td></tr><tr><td><code>timeInForce</code></td><td>string</td><td><mark style="color:red;">Required</mark></td><td>DAY, GTC</td></tr><tr><td><code>limitPrice</code></td><td>float</td><td>Optional</td><td>Limit price when submitting limit order type</td></tr><tr><td><code>stopPrice</code></td><td>float</td><td>Optional</td><td>Stop price when submitting stop order type</td></tr><tr><td><code>ocoId</code></td><td>string</td><td>Optional</td><td>Create or append to OCO order by ID</td></tr><tr><td><code>strategy</code></td><td>string</td><td>Optional</td><td>ATM strategy name if opening with ATM template</td></tr></tbody></table>

**Code Examples**

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

```python
import requests

token = 'my-secret-token'

url = "https://app.crosstrade.io/v1/api/accounts/Sim101/positions/reverseposition"
headers = {
    "Authorization": f"Bearer {token}",
    "Content-Type": "application/json"
}
data = {
    "instrument": "MES 12-25",
    "action": "BUY",
    "orderType": "MARKET",
    "quantity": 1,
    "timeInForce": "DAY"
    # "limitPrice": 5500
    # "stopPrice": 0,
    # "ocoId": "abc123",
    # "strategy": "MyAtmStrategy"
}

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
{
    "orderId": "cb1fc8d4e1a84d29ae38fea964aaac8c",
    "success": true
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "error": "No position found for instrument 'ES 12-25' in account 'sim101'"
}
```

{% 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": "ReversePosition",
  "args": {
    "account": "Sim101",
    "instrument": "ES 09-26",
    "action": "Buy",
    "orderType": "Market",
    "quantity": 1,
    "timeInForce": "Gtc"
  }
}
```
