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
- 401
- 403
- 408
- 429
- 500
// Pending closes are not proof that the account is flat.
{
"success": true,
"pending": true,
"verified": false,
"disposition": "pending",
"remainingQuantity": 4,
"closedPositions": [],
"closingPositions": [
{
"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,
"tag": null
}
]
}
{
"error": "No positions found for instrument 'ES 12-26'"
}
{
"error": "Invalid bearer token"
}
{
"error": "Endpoint not available"
}
{
"error": "Client not ready to receive requests, disconnected."
}
// retryAfter is integer seconds; also sent as Retry-After.
{
"error": "Rate limit exceeded",
"retryAfter": 1
}
{
"success": false,
"error": "internal_error"
}
Success field types
| Field | Type | Description |
|---|---|---|
success, pending, verified | boolean | Request outcome and close-verification state. |
disposition | string | Such as pending or flat. |
remainingQuantity | integer | Quantity remaining at the reply. |
closedPositions, closingPositions | array of objects | Confirmed-flat and still-closing positions. |
closedPositions[], closingPositions[] | object | NT8 position fields. |
closingPositions[].orderId | string | Closing order ID, when present. |
closingPositions[].requestedQuantity | integer | Requested partial-close quantity, when present. |
Platform nuances
A close is submitted first and confirmed second. closedPositions lists only positions the
add-on saw reach flat before it answered. Anything still working is listed in
closingPositions with pending: true and verified: false, and the response carries
remainingQuantity. Partial-close rows may also include a closing orderId. Poll
GET Positions to confirm the final state.
Overlapping close requests for the same account and instrument join the operation already
running instead of starting a second one, so a retry cannot leave two closing orders in the
market. When a close cannot be completed safely the response carries an error code, such
as close_in_progress or close_needs_reconciliation, with a detail message, and no
further order is sent.
When quantity or percent closes less than the full position, the add-on places a market
order for the specified size rather than closing the whole position. 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. A partial close always
answers with pending: true and lists its requestedQuantity under closingPositions.
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 12-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 12-26), or Tradovate (ESZ6) 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
- 200
- 400
- 401
- 403
- 429
- 500
- 502
- 503
{
"success": true,
"destination": "tradovate",
"api": "liquidate_position",
"account": "DEMO12345678",
"instrument": "ESZ6",
"durationMs": 2251,
"response": {
"ok": true,
"ack": "empty_body",
"flatAfterS": 0.6,
"copierResults": [
{
"follower": "DEMO87654321",
"success": true,
"closedQty": 1
}
]
}
}
{
"error": "Invalid request"
}
{
"success": false,
"error": "inactive_subscription"
}
{
"success": false,
"error": "tradovate_not_linked"
}
// retryAfter is integer seconds; also sent as Retry-After.
{
"success": false,
"error": "rate_limited",
"detail": "CrossTrade API rate limit exceeded (180 requests/min per user). Retry after 1s.",
"retryAfter": 1
}
{
"success": false,
"error": "internal_error"
}
{
"success": false,
"error": "tradovate_unavailable",
"detail": "Tradovate is temporarily unavailable. Please try again shortly."
}
{
"success": false,
"error": "temporarily_disabled"
}
Success field types
| Field | Type | Description |
|---|---|---|
success | boolean | Command outcome. |
destination, api, account, instrument | string | Dispatcher and target. |
durationMs | integer | Duration in milliseconds. |
response | object | Close result; fields vary by close path. |
response.ok | boolean | Broker acknowledgement flag in this response. |
response.ack | string | Acknowledgement type. |
response.flatAfterS | float | Seconds until flat verification. |
response.closedQty | integer | Closed quantity reported by the close path, when present. |
response.orderId | integer | Closing order ID, when present. |
response.positionWas | integer | Position quantity reported before the close, when present. |
response.copierResults | array of objects | Optional follower outcomes. |
response.copierResults[].follower, response.copierResults[].skipped | string | Follower and optional skip reason. |
response.copierResults[].success | boolean | Follower outcome. |
response.copierResults[].closedQty | integer | Follower closed quantity, when present. |
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.