POST Close Position
- NT8
- Tradovate
Close a specific position by instrument NT8
Fully or partially closes one NinjaTrader instrument position by quantity or percentage.
Endpoint
POST /v1/api/accounts/{account}/positions/close
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 parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Required | Name of underlying instrument |
quantity | int | Optional | Number of contracts to close. If omitted, the full position is closed. Capped at the current open quantity. |
percent | float | Optional | Fraction of the position to close, between 0 and 1 (e.g., 0.5 for 50%). Rounds up — closing 10% of a 1-contract position closes 1 contract. Takes effect only if quantity is not provided. |
Code examples
- Python
- JavaScript
- cURL
import requests
url = "https://app.crosstrade.io/v1/api/accounts/Sim101/positions/close"
headers = {
"Authorization": "Bearer my-secret-token",
"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}")
const url = "https://app.crosstrade.io/v1/api/accounts/Sim101/positions/close";
const data = {
instrument: "MES 12-25",
quantity: 4,
// percent: 0.25
};
fetch(url, {
method: "POST",
headers: {
"Authorization": "Bearer my-secret-token",
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));
curl -X POST "https://app.crosstrade.io/v1/api/accounts/Sim101/positions/close" \
-H "Authorization: Bearer my-secret-token" \
-H "Content-Type: application/json" \
-d '{
"instrument": "MES 12-25",
"quantity": 4
}'
Response
- 200
- 400
{
"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
}
{
"error": "No positions found for instrument 'ES 12-24'"
}
Platform nuances
Partial close behavior — When quantity or percent closes less than the full position, the add-on places a market order for the specified size rather than calling NT8's flatten. Working orders (stops, targets) are not automatically cancelled on a partial close. Use POST /cancel-orders with the instrument filter if you need to clean those up separately.
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": "ClosePosition",
"args": {
"account": "Sim101",
"instrument": "ES 09-26"
}
}
Close a specific position by instrument Tradovate
Fully or partially closes one position on a linked Tradovate account. The request executes server-side through the same validation and controls as a Tradovate webhook signal, including field validation, Account Manager locks, and Trade Copier fan-out.
Endpoint
POST /v1/api/tv/accounts/{account}/positions/close
Headers
| Name | Value |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Required | Tradovate account name, such as DEMO12345678 |
Body parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Required | Continuous (ES1!), NT8 (ES 09-26), or Tradovate (ESU6) instrument form |
qty | int | Optional | Number of contracts to close; takes precedence over percent |
percent | float | Optional | Fraction from 0 to 1 to close when qty is omitted |
Omit both qty and percent to close the full position.
Code examples
- Python
- JavaScript
- cURL
import requests
token = 'my-secret-token'
url = "https://app.crosstrade.io/v1/api/tv/accounts/DEMO12345678/positions/close"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
data = {
"instrument": "ES1!",
"percent": 0.5
}
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}")
const token = 'my-secret-token';
const url = "https://app.crosstrade.io/v1/api/tv/accounts/DEMO12345678/positions/close";
const data = {
instrument: "ES1!",
percent: 0.5
};
fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));
TOKEN="my-secret-token"
curl -X POST "https://app.crosstrade.io/v1/api/tv/accounts/DEMO12345678/positions/close" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"instrument": "ES1!", "percent": 0.5}'
Response
This abbreviated response envelope identifies the operation. The full response also includes
dispatcher context and the close result inside response.
{
"success": true,
"api": "liquidate_position",
"response": {}
}
Platform nuances
- Tradovate uses
qty; NT8 usesquantity. - Tradovate accepts three instrument naming forms.
- The operation does not require the NinjaTrader add-on to be connected.
- Account Manager and Trade Copier behavior is applied by the shared dispatcher.
See the Tradovate API overview for the full field grammar, mutation safety guarantees, and error table.