CrossTrade Docs
Basic CommandsAdvanced Commands
  • Welcome!
    • Set Up Guide
  • Getting Started
    • Installation
    • User Dashboard
      • XT Control Panel
      • Manual Trader
      • Command Builder
    • Alert History
    • TradingView Alerts
      • Dynamic Variables
      • XT Alert Builder
      • Example Indicators
      • Example Strategies
    • VPS Connection Guide
  • Webhooks
    • Overview
    • Commands
      • Place Order
      • Flat Place Order
      • Close Position
      • Reverse
      • Reverse Position
      • Flatten Positions
      • Flatten Everything
      • Cancel Order
      • Cancel Orders
      • Cancel All Orders
      • Cancel Replace
      • Change Order
      • Close Strategy
    • Advanced Options
      • Multi-Account Placement
      • Flatten First
      • Require Market Position
      • Max Positions
      • Bracket Orders
      • Percentage and Tick Prices
      • Limit Order Timeouts
      • Trading Window
      • Bypass Trade Windows
      • Delay Timer
      • Rate-Limiting
      • Alert Commenting
      • Kill Switch
      • Notes
    • Examples & Use Cases
    • Troubleshooting
  • Account Manager
    • Overview
      • How It Works
      • Dashboard
      • Global Settings
      • Frequently Asked Questions (FAQ)
    • Monitors
      • Profit/Loss Thresholds
      • Minimum Profit Drawdown
      • Trailing Drawdown
      • Advanced Usage
    • Account Settings
      • Auto-Flattening
      • Trading Windows
    • Management Logs
  • NinjaTrader
    • ATM Strategies
      • Creating ATM Template
    • Optimizing NinjaTrader Performance
    • Enabling Multi-Provider Mode
  • CrossTrade API
    • Overview
    • Authentication
    • Rate Limiting
    • Webhook Trading
    • Accounts
      • GET Accounts Summary
      • GET Accounts
      • GET Account
    • Positions
      • GET Positions
      • GET Position
      • POST Close Position
      • POST Reverse
      • POST Reverse Position
      • POST Flatten Positions
      • POST Flatten Everything
    • Orders
      • GET Orders
      • GET Order
      • GET Order Status
      • POST Cancel Order
      • POST Cancel Orders
      • POST Cancel All Orders
      • POST Place Order
      • POST Flat Place Order
      • POST Replace Order
      • PUT Change Order
    • Strategies
      • GET Strategies
      • GET Strategy
      • POST Close Strategy
    • Executions
      • GET Executions
      • GET Execution
    • Quotes
      • GET Quote
  • Changelog
    • XT Versions
    • All Updates
  • Affiliate Program
    • Media Kit
  • Social Links
    • Discord
    • TradingView
    • YouTube
    • X (Twitter)
    • Instagram
    • Facebook
    • Reddit
    • Website
    • Blog
Powered by GitBook
On this page
  1. CrossTrade API
  2. Positions

POST Flatten Everything

Flattens all positions and orders in all accounts for all instruments.

Flatten all NT8 positions and orders

POST /v1/api/positions/flatten

Closes positions in all or one account that meet all of the specified criteria: account, instrument, market position.

WARNING: An empty JSON payload (i.e., no filters applied) to this endpoint will close all positions and all orders across all accounts.

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <token>

Body

Name
Type
Required
Description

account

string

Optional

Name of the account

instrument

string

Optional

Name of underlying instrument

marketPosition

string

Optional

"long" or "short"

Code Examples

import requests

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

Response

{
    "orderIds": [
        "adb3868865de4b59b0e147b8300e4a29",
        "2141df9fc0254ba9b34c8a5e38722249",
        "16f6774e302748ce962f2d60b58b2eb1"
    ],
    "closedPositions": [
        {
            "type": "NinjaTrader.Cbi.Position",
            "account": "Sim101",
            "instrument": "ES 12-24",
            "instrumentType": "Future",
            "marketPosition": "Short",
            "quantity": 2,
            "averagePrice": 5780.125,
            "marketPrice": 5774.0,
            "unrealizedProfitLoss": 612.5
        }
    ],
    "success": true
}
{
  "error": "Invalid request"
}
PreviousPOST Flatten PositionsNextOrders

Last updated 2 months ago