Skip to content

ClosePosition

Close all open positions across all exchanges in a single request. This is a square-off operation that places counter orders for all open positions.

Endpoint URL

http
Local Host   :  POST http://127.0.0.1:5000/api/v1/closeposition
Ngrok Domain :  POST https://<your-ngrok-domain>.ngrok-free.app/api/v1/closeposition
Custom Domain:  POST https://<your-custom-domain>/api/v1/closeposition

Sample API Request

json
{
  "apikey": "<your_app_apikey>",
  "strategy": "Python"
}

Sample cURL Request

bash
curl -X POST http://127.0.0.1:5000/api/v1/closeposition \
  -H 'Content-Type: application/json' \
  -d '{
  "apikey": "<your_app_apikey>",
  "strategy": "Python"
}'

Sample API Response

json
{
  "message": "All Open Positions Squared Off",
  "status": "success"
}

Sample API Response (No Positions)

json
{
  "message": "No open positions to close",
  "status": "success"
}

Request Body

ParameterDescriptionMandatory/OptionalDefault Value
apikeyYour Tradeboard API keyMandatory-
strategyStrategy identifierMandatory-

ClosePositionSchema declares exactly these two fields and both are required. Omitting strategy returns HTTP 400. There is no per-symbol variant of this request: sending symbol, exchange, or product returns HTTP 400 because the schema does not declare them.

Response Fields

FieldTypeDescription
statusstring"success" or "error"
messagestringResult message
modestring"analyze" in analyzer mode. The key is absent in live mode; there is no "mode": "live"

How It Works

  1. Fetches all open positions from position book
  2. For each position with non-zero quantity:
    • Long position (+ve quantity) → Places SELL order
    • Short position (-ve quantity) → Places BUY order
  3. All closing orders are placed as MARKET orders
  4. Uses the same product type as the original position (MIS/NRML)

Positions Closed

ExchangeProduct Types Closed
NSEMIS, CNC
BSEMIS, CNC
NFOMIS, NRML
BFOMIS, NRML
CDSMIS, NRML
BCDMIS, NRML
MCXMIS, NRML
NCDEXMIS, NRML
NCOMIS, NRML
CRYPTOMIS, NRML

Notes

  • This is a destructive operation - all positions will be squared off
  • Closing orders are placed as MARKET orders for immediate execution
  • CNC (delivery) positions are also closed if they have intraday quantity
  • Use with caution - there is no confirmation prompt
  • The operation affects all positions across all exchanges
  • For selective closing, use individual orders instead
  • Rate limit: API_RATE_LIMIT, not ORDER_RATE_LIMIT

Use Cases

  • Emergency exit: Square off all positions during market crash
  • End of day: Close all intraday positions before market close
  • Risk management: Flatten all positions when risk limits are breached

Back to: API Documentation