Skip to main content

POST Close Position

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​

NameValue
Content-Typeapplication/json
AuthorizationBearer <token>

Path parameters​

NameTypeRequiredDescription
accountstringRequiredName of account in NT8

Body parameters​

NameTypeRequiredDescription
instrumentstringRequiredName of underlying instrument
quantityintOptionalNumber of contracts to close. If omitted, the full position is closed. Capped at the current open quantity.
percentfloatOptionalFraction 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​

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}")

Response​

// 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
}
]
}

Success field types​

FieldTypeDescription
success, pending, verifiedbooleanRequest outcome and close-verification state.
dispositionstringSuch as pending or flat.
remainingQuantityintegerQuantity remaining at the reply.
closedPositions, closingPositionsarray of objectsConfirmed-flat and still-closing positions.
closedPositions[], closingPositions[]objectNT8 position fields.
closingPositions[].orderIdstringClosing order ID, when present.
closingPositions[].requestedQuantityintegerRequested partial-close quantity, when present.

Platform nuances​

Confirmed vs. still closing

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.

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 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"
}
}