POST Flatten Positions
Flatten positions by account and/or instrument
POST /v1/api/accounts/{account}/positions/flatten
Flatten allows for flattening all positions and orders in an account or for a specific instrument in an account. Differs from Flatten Everything, which flattens all positions and order in all accounts for all instruments.
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 | Optional | Optional name of instrument |
Code Examples
- Python
import requests
token = 'my-secret-token'
url = "https://app.crosstrade.io/v1/api/accounts/Sim101/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}")
Response
- 200
- 400
{
"closedPositions": [
{
"type": "NinjaTrader.Cbi.Position",
"account": "Sim101",
"instrument": "MES 12-25",
"instrumentType": "Future",
"marketPosition": "Short",
"quantity": 1,
"averagePrice": 5803.25,
"marketPrice": 5802.0,
"unrealizedProfitLoss": 6.25
}
],
"success": true
}
{
"error": "Invalid request"
}
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": "Flatten",
"args": {
"account": "Sim101",
"instrument": "ES 09-26"
}
}