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_id
s of the new orders created to square off will be returned in the response.
- This API does not support exiting positions for
Delivery
orders in theEQ
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.
- 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โ
Name | Required | Type | Description |
---|---|---|---|
Authorization | true | string | Requires the format Bearer access_token where access_token is obtained from the Token API. |
Accept | true | string | Defines the content format the client expects, which should be set to application/json . |
Query Parametersโ
Name | Required | Type | Description |
---|---|---|---|
segment | false | string | The segment associated with the positions. Possible values: NSE_EQ , BSE_EQ , NSE_FO , BSE_FO , MCX_FO , NCD_FO , BCD_FO . |
tag | false | string | The 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 Tag Scenarioโ
An order tag is a feature that allows traders to categorize or label their orders for better tracking and management. However, it is important to note that order tags are only valid for intraday positions. They are specifically designed for trades that are opened and closed within the same trading session.
When a position is carried forward to the next trading day, the order tag associated with it becomes invalid or irrelevant. This is because carry-forwarded positions are no longer tied to the context of the original trading session where the tag was applied.
For carry-forward positions, use a general exit approach without filtering by tags.
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.
- 2XX
- 4XX
Response Bodyโ
- Success (200)
- Partial Success (207)
{
"status": "success",
"data": {
"order_ids": [
"1644490272000",
"1644490272001",
"1644490272003"
]
},
"errors": null,
"summary": {
"total": 3,
"success": 3,
"error": 0
}
}
Name | Type | Description |
---|---|---|
status | string | A 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. |
data | object | Successful response data for exit all positions request. |
data.order_ids | array | List of reference order IDs associated with successful exit positions. |
errors | array | An array containing the main content of the error response for partial_success and error scenarios. |
errors[].error_code | string | A specific error code. |
errors[].message | string | Descriptive error message. |
errors[].property_path | string | Indicates which part of the request triggered the error. It can be null. |
errors[].invalid_value | string | Shows the value causing the error. It can be null. |
errors[].instrument_key | string | A Key of instrument for a specific position. |
errors[].order_id | string | Order ID associated to specific position. It can be null. |
summary | object | A summary of the outcomes for the batch of orders processed, detailing total orders, successful completions, and errors. |
summary.total | integer | The total number of order present in the payload for exit positions. |
summary.success | integer | Indicates the successful orders placed for exit positions. |
summary.error | integer | Indicates the unsuccessful orders placed for exit positions. |
{
"status": "partial_success",
"data": {
"order_ids": [
"1644490272000",
"1644490272001",
"1644490272003"
]
},
"errors": [
{
"error_code": "UDAPI1113",
"message": "The Exit Positions API is accessible during the market hours only.",
"property_path": null,
"invalid_value": null,
"order_id": null,
"instrument_key": "NSE_EQ|INE002A01018"
},
{
"error_code": "UDAPI100500",
"message": "Something went wrong... please contact us",
"property_path": null,
"invalid_value": null,
"order_id": null,
"instrument_key": "MCX_FO|436245"
}
],
"summary": {
"total": 5,
"success": 3,
"error": 2
}
}
Name | Type | Description |
---|---|---|
status | string | A 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. |
data | object | Successful response data for exit all positions request. |
data.order_ids | array | List of reference order IDs associated with successful exit positions. |
errors | array | An array containing the main content of the error response for partial_success and error scenarios. |
errors[].error_code | string | A specific error code. |
errors[].message | string | Descriptive error message. |
errors[].property_path | string | Indicates which part of the request triggered the error. It can be null. |
errors[].invalid_value | string | Shows the value causing the error. It can be null. |
errors[].instrument_key | string | A Key of instrument for a specific position. |
errors[].order_id | string | Order ID associated to specific position. It can be null. |
summary | object | A summary of the outcomes for the batch of orders processed, detailing total orders, successful completions, and errors. |
summary.total | integer | The total number of order present in the payload for exit positions. |
summary.success | integer | Indicates the successful orders placed for exit positions. |
summary.error | integer | Indicates the unsuccessful orders placed for exit positions. |
{
"status": "error",
"data": null,
"errors": [
{
"errorCode": "UDAPI1111",
"message": "No open position available to exit",
"propertyPath": null,
"invalidValue": null,
"error_code": "UDAPI1111",
"property_path": null,
"invalid_value": null
}
]
}
{
"status": "error",
"data": null,
"errors": [
{
"error_code": "UDAPI1113",
"message": "The Exit Positions API is accessible during the market hours only.",
"property_path": null,
"invalid_value": null,
"order_id": null,
"instrument_key": "NSE_EQ|INE002A01018"
},
{
"error_code": "UDAPI100500",
"message": "Something went wrong... please contact us",
"property_path": null,
"invalid_value": null,
"order_id": null,
"instrument_key": "MCX_FO|436245"
}
],
"summary": {
"total": 2,
"success": 0,
"error": 2
}
}
Name | Type | Description |
---|---|---|
status | string | A 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. |
data | object | Successful response data for exit all positions request. |
data.order_ids | array | List of reference order IDs associated with successful exit positions. |
errors | array | An array containing the main content of the error response for partial_success and error scenarios. |
errors[].error_code | string | A specific error code. |
errors[].message | string | Descriptive error message. |
errors[].property_path | string | Indicates which part of the request triggered the error. It can be null. |
errors[].invalid_value | string | Shows the value causing the error. It can be null. |
errors[].instrument_key | string | A Key of instrument for a specific position. |
errors[].order_id | string | Order ID associated to specific position. It can be null. |
summary | object | A summary of the outcomes for the batch of orders processed, detailing total orders, successful completions, and errors. |
summary.total | integer | The total number of order present in the payload for exit positions. |
summary.success | integer | Indicates the successful orders placed for exit positions. |
summary.error | integer | Indicates the unsuccessful orders placed for exit positions. |
Error Codesโ
Error code | Description |
---|---|
UDAPI1108 | Invalid segment. - Please ensure that segment provided in query param is correct. |
UDAPI1111 | No open position available to exit. - Please ensure that there are open positions available. |
UDAPI1112 | Available open positions should not be more than limit. - Please ensure that available positions should be within the limit. |
UDAPI1113 | The Exit Positions API is accessible during the market hours only. - Please ensure that the market is open for trading in the specified segment. |
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:
- Order 1: You buy 100 shares of
ABC_CORP
with the tagStrategy_A
. - Order 2: You buy 50 shares of
ABC_CORP
with the tagStrategy_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 withABC_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.