POST Reverse
Combined Close Position and Place Order
POST /v1/api/accounts/{account}/positions/reverse
Performs a true reversal of the position in the account specified. If no position exists, no action is taken. Returns the Order ID of the newly opened position.
Headers
| Name | Value |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Required | Name of account in NT8 |
Body
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Required | Name of underlying instrument (e.g., "ES 12-24") |
Code Examples
- Python
import requests
token = 'my-secret-token'
url = "https://app.crosstrade.io/v1/api/accounts/Sim101/positions/reverse"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
data = {
"instrument": "MES 12-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}")
Response
- 200
- 400
{
"orderId": "cb1fc8d4e1a84d29ae38fea964aaac8c",
"success": true
}
{
"error": "No position found for instrument 'ES 12-25' in account 'sim101'"
}
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.
{
"action": "rpc",
"id": "my-request-id",
"api": "Reverse",
"args": {
"account": "Sim101",
"instrument": "ES 09-26"
}
}