POST Flatten Everything
- NT8
- Tradovate
Flatten all NT8 positions and orders NT8
Closes positions in all or one account that meet all of the specified criteria: account, instrument, market position.
Endpoint
POST /v1/api/positions/flatten
Headers
| Name | Value |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Body parameters
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Optional | Name of the account |
instrument | string | Optional | Name of underlying instrument |
marketPosition | string | Optional | "long" or "short" |
cancelOrders | bool | Optional | For a filtered flatten, run an explicit working-order cancellation pass after flattening. |
Code examples
- Python
- JavaScript
- cURL
import requests
url = "https://app.crosstrade.io/v1/api/positions/flatten"
headers = {
"Authorization": "Bearer my-secret-token",
"Content-Type": "application/json"
}
data = {
"account": "Sim101",
"instrument": "MES 12-25",
"marketPosition": "short"
}
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/positions/flatten";
const data = {
account: "Sim101",
instrument: "MES 12-25",
marketPosition: "short"
};
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/positions/flatten" \
-H "Authorization: Bearer my-secret-token" \
-H "Content-Type: application/json" \
-d '{
"account": "Sim101",
"instrument": "MES 12-25",
"marketPosition": "short"
}'
Response
- 200
- 400
{
"orderIds": [
"adb3868865de4b59b0e147b8300e4a29",
"2141df9fc0254ba9b34c8a5e38722249",
"16f6774e302748ce962f2d60b58b2eb1"
],
"closedPositions": [
{
"type": "NinjaTrader.Cbi.Position",
"account": "Sim101",
"instrument": "ES 12-25",
"instrumentType": "Future",
"marketPosition": "Short",
"quantity": 2,
"averagePrice": 5780.125,
"marketPrice": 5774.0,
"unrealizedProfitLoss": 612.5
}
],
"success": true
}
{
"error": "Invalid request"
}
Platform nuances
WARNING: An empty JSON payload (i.e., no filters applied) to this endpoint will close all positions and all orders across all accounts.
When using any filter, the request runs the filtered Flatten operation. Set cancelOrders: true
when broker-held working stops or targets must be explicitly cancelled after the position closes.
When providing filters (account, instrument, marketPosition), use "api": "Flatten". Use "api": "FlattenEverything" only for a complete flatten with no filters.
The REST endpoint (/v1/api/positions/flatten) handles this implicitly. The WebSocket function must be called explicitly.
WebSocket API
This request can also be made over the WebSocket API.
Flatten everything (no filters)
{
"action": "rpc",
"id": "my-request-id",
"api": "FlattenEverything",
"args": {}
}
Flatten with filters
{
"action": "rpc",
"id": "my-request-id",
"api": "Flatten",
"args": {
"account": "Sim101",
"instrument": "MES 12-25",
"marketPosition": "short"
}
}
Flatten all positions and orders Tradovate
Liquidates open positions and cancels working orders across linked Tradovate identities. An optional account body field scopes the operation to one linked account; without it, the command affects all linked accounts. The request executes server-side through the shared webhook parser and dispatcher, including field validation, Account Manager locks, and Trade Copier fan-out.
Endpoint
POST /v1/api/tv/positions/flatten
Headers
| Name | Value |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Body parameters
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Optional | Tradovate account name to flatten; omit to flatten all linked Tradovate accounts |
Send an empty JSON object to flatten all linked accounts.
Code examples
- Python
- JavaScript
- cURL
import requests
token = 'my-secret-token'
url = "https://app.crosstrade.io/v1/api/tv/positions/flatten"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
data = {}
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/positions/flatten";
fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({})
})
.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/positions/flatten" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}'
Response
This abbreviated response envelope identifies the operation. The full response also includes
dispatcher context and the flatten results inside response.
{
"success": true,
"api": "flatten_everything",
"response": {}
}
Platform nuances
- Without
account, this command affects all linked Tradovate identities. - Supplying
accountscopes the command to that linked Tradovate account. - For a filtered flatten, use
POST /v1/api/tv/accounts/{account}/positions/flatten. - 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.