POST Close Position

Closes a position in a specific account by instrument. Returns a list of positions closed in the account for the specific instrument.

Close a specific position by instrument

POST /v1/api/accounts/{account}/positions/close

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <token>

Query Parameters

Name
Type
Required
Description

account

string

Required

Name of account in NT8

Body

Name
Type
Required
Description

instrument

string

Required

Name of underlying instrument

quantity

integer

Optional

Quantity of contracts to close

percent

float

Optional

% of remaining contracts to close

Code Examples

import requests

url = "https://app.crosstrade.io/v1/api/accounts/Sim101/positions/close"
headers = {
    "Authorization": "Bearer frvO0lK6cXe9ML5ITNlEduwP5J1oNzLT0XTBRjR_OZ0",
    "Content-Type": "application/json"
}
data = {
    "instrument": "MES 03-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

{
    "closedPositions": [
        {
            "type": "NinjaTrader.Cbi.Position",
            "account": "Sim101",
            "instrument": "ES 12-24",
            "instrumentType": "Future",
            "marketPosition": "Long",
            "quantity": 4,
            "averagePrice": 5779.8125,
            "marketPrice": 5797.0,
            "unrealizedProfitLoss": 3437.5
        }
    ],
    "success": true
}

Last updated