Skip to main content

Exit All Positions Betaโ€‹

Use this API to exit all open positions in one go. You can filter by segment or tag to exit specific positions, or exit all open positions with a single request. The order_ids of the new orders created to square off will be returned in the response.

Important
  • This API does not support exiting positions for Delivery orders in the EQ segment.
  • This API will place a opposite leg MARKET order for each position.
  • This API will be applicable during the market segment's trading hours.
  • Auto slicing is enabled by default for this API. Click here for more details.
Exit Positions Limits and Rate Limits
  • A maximum of 200 positions can be exit in a single request. Any request exceeding this limit will be rejected.
  • The Exit Positions API is subject to a different rate limit compared to the standard limits applied across the system. For more information on the rate limits for this API, please check here.

Header Parametersโ€‹

NameRequiredTypeDescription
AuthorizationtruestringRequires the format Bearer access_token where access_token is obtained from the Token API.
AccepttruestringDefines the content format the client expects, which should be set to application/json.

Query Parametersโ€‹

NameRequiredTypeDescription
segmentfalsestringThe segment associated with the positions.
Possible values: NSE_EQ, BSE_EQ, NSE_FO, BSE_FO, MCX_FO, NCD_FO, BCD_FO.
tagfalsestringThe tag associated with the positions. Check the Understanding How the Order Tag Filter Works section for a detailed explanation on how filtering by order tag works.

Order Execution Sequenceโ€‹

The system will execute all BUY positions first, followed by the execution of all SELL orders. This ensures a consistent and orderly processing of multiple order types within the same request.


Maximum Position Limitโ€‹

When slicing is applied, we calculate the total number of resulting orders. The total number of orders in a request, including those generated by the slice, must not exceed the maximum position count specified here.


Responses

Response Bodyโ€‹

{
"status": "success",
"data": {
"order_ids": [
"1644490272000",
"1644490272001",
"1644490272003"
]
},
"errors": null,
"summary": {
"total": 3,
"success": 3,
"error": 0
}
}
NameTypeDescription
statusstringA string indicating the outcome of the request. Possible values: success, partial_success, error.

success - when all positions were exit successfully.
partial_success - when some positions encountered errors.
error - when all the positions encountered errors.
dataobjectSuccessful response data for exit all positions request.
data.order_idsarrayList of reference order IDs associated with successful exit positions.
errorsarrayAn array containing the main content of the error response for partial_success and error scenarios.
errors[].error_codestringA specific error code.
errors[].messagestringDescriptive error message.
errors[].property_pathstringIndicates which part of the request triggered the error. It can be null.
errors[].invalid_valuestringShows the value causing the error. It can be null.
errors[].instrument_keystringA Key of instrument for a specific position.
errors[].order_idstringOrder ID associated to specific position. It can be null.
summaryobjectA summary of the outcomes for the batch of orders processed, detailing total orders, successful completions, and errors.
summary.totalintegerThe total number of order present in the payload for exit positions.
summary.successintegerIndicates the successful orders placed for exit positions.
summary.errorintegerIndicates the unsuccessful orders placed for exit positions.

Auto Slicingโ€‹

Exchanges enforce a limitation on the maximum quantity that can be placed for any scrip, known as the freeze quantity. If an order exceeds this freeze quantity, it will be rejected by the exchange. To simplify the process and prevent such rejections, we automatically slice the order into smaller parts based on the freeze quantity defined by the exchange when necessary.

For example:โ€‹

If you want to exit position for SCRIP1 with a total quantity of 10,100, and the freeze quantity defined by the exchange is 1,000, then the system will automatically split the position into 11 smaller for execution: 10 positions of 1,000 quantity each, and 1 position of 100 quantity. This ensures that all quantities are accepted and processed by the exchange.


Understanding How the Order Tag Filter Worksโ€‹

How Positions workโ€‹

When you place multiple orders for the same instrument_key, your positions are aggregated based on the total quantity, not by individual orders. This means positions are not identifiable by specific order numbers.

What happens when you filter by Tag?โ€‹

When you use the Exit Position API with a tag filter, the system identifies orders associated with that tag and calculates the total quantity for each instrument_key. It then creates a square-off order for that quantity to exit the position. Note that the square-off is performed based on quantity, not on individual orders.

Let's illustrate how this will work with an example:

  1. Order 1: You buy 100 shares of ABC_CORP with the tag Strategy_A.
  2. Order 2: You buy 50 shares of ABC_CORP with the tag Strategy_B.

Your position for ABC_CORP now shows a total of 150 shares.

Now, you decide to exit positions associated with Strategy_A:

  • You call the Exit All API with tag=Strategy_A.
  • The system identifies that Strategy_A is associated with ABC_CORP for 100 shares.
  • A square-off order is created to sell 100 shares of ABC_CORP.

Key Takeawayโ€‹

When exiting positions using a tag filter, the system squares off based on total quantities per instrument, not individual orders or tags. Therefore, if you have multiple positions in the same instrument with different tags, exiting positions with a specific tag may impact your overall position in that instrument beyond the intended tag.


Examplesโ€‹

A comprehensive set of examples is provided to illustrate various use cases and implementation scenarios for this API. To view detailed examples and access sample code, please refer to: API Examples.

Loading...