Kill Switch
API to enable or disable one or more trading segments in a single request. The kill switch is a risk management tool that lets traders temporarily halt activity in specific segments to avoid emotionally-driven or compulsive trading decisions. When a segment is disabled, all pending orders in that segment are cancelled and new orders are blocked.
For more information on the kill switch and how it helps with trade risk management, click here.
- All open positions in a segment must be closed before you can disable it.
- After disabling a segment, a 12-hour cooling period applies before it can be re-enabled.
- All open orders in the segment are cancelled automatically when it is disabled.
- If your given segment is inactive or dormant kill switch cannot be enabled as trading is already blocked. You can only enable kill switch for segments that are currently active.
Request
curl --location 'https://api.upstox.com/v2/user/kill-switch' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '[
{
"segment": "NSE_FO",
"action": "DISABLE"
},
{
"segment": "NSE_EQ",
"action": "DISABLE"
},
{
"segment": "NCD_FO",
"action": "ENABLE"
}
]'
Additional samples in various languages are available in the Sample Code section on this page.
Request Body
The request body is an array of segment update objects. You can update multiple segments in a single call.
| Name | Type | Required | Description |
|---|---|---|---|
| segment | string | Yes | Trading segment to update. Possible values: BSE_EQ, NSE_EQ, NCD_FO, BCD_FO, NSE_FO, BSE_FO, MCX_FO, NSE_COM |
| action | string | Yes | Action to perform. Possible values: ENABLE, DISABLE |
If any segment in the request fails to update, none of the other segments in the same request will be updated.
- 200
- 4XX
Response Body
{
"status": "success",
"data": [
{
"segment": "MCX_FO",
"segment_status": "INACTIVE",
"kill_switch_enabled": false
},
{
"segment": "NCD_FO",
"segment_status": "ACTIVE",
"kill_switch_enabled": false
},
{
"segment": "NSE_EQ",
"segment_status": "ACTIVE",
"kill_switch_enabled": true
},
{
"segment": "BCD_FO",
"segment_status": "ACTIVE",
"kill_switch_enabled": false
},
{
"segment": "BSE_FO",
"segment_status": "ACTIVE",
"kill_switch_enabled": false
},
{
"segment": "NSE_FO",
"segment_status": "ACTIVE",
"kill_switch_enabled": true
},
{
"segment": "BSE_EQ",
"segment_status": "ACTIVE",
"kill_switch_enabled": true
},
{
"segment": "NSE_COM",
"segment_status": "INACTIVE",
"kill_switch_enabled": false
}
]
}
| Name | Type | Description |
|---|---|---|
| status | string | Outcome of the request. Possible values: success, error |
| data | array | Updated kill switch status for each requested segment |
| data[].segment | string | Exchange segment identifier (e.g. NSE_EQ, BSE_FO, MCX_FO) |
| data[].segment_status | string | This is an account-level segment status and it remains independent of the kill switch. Activating the kill switch will block trading, but it will not change the segment's status between ACTIVE and INACTIVE. |
| data[].kill_switch_enabled | boolean | true if the kill switch is now engaged for this segment |
Error codes
| Error code | Description |
|---|---|
| UDAPI1184 | Segment status cannot be changed until all open positions are closed. - Close all open positions in the segment before attempting to change its status. |
| UDAPI1185 | Cannot enable segment — cooling period is still in effect. - A mandatory waiting period applies after disabling a segment. Retry after the cooling period expires. |
| UDAPI1186 | The specified segment does not exist. - The segment value provided is not a valid trading segment. |
| UDAPI1187 | Failed to update segment status due to an error processing open orders. - An internal error occurred while processing open orders. Retry the request or contact support. |
| UDAPI1188 | Invalid action. Allowed values are ENABLE and DISABLE. - The action field must be exactly ENABLE or DISABLE. |
Sample Code
Disable a trading segment using the kill switch
- Python
- Node.js
- Java
- PHP
import requests
import json
url = 'https://api.upstox.com/v2/user/kill-switch'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
payload = [
{
"segment": "NSE_EQ",
"action": "DISABLE"
}
]
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/user/kill-switch';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
const payload = [
{
segment: 'NSE_EQ',
action: 'DISABLE'
}
];
axios.post(url, payload, { headers })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error(error);
});
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
try {
String url = "https://api.upstox.com/v2/user/kill-switch";
String requestBody = "[{\"segment\": \"NSE_EQ\", \"action\": \"DISABLE\"}]";
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer {your_access_token}")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/user/kill-switch';
$headers = array(
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}'
);
$payload = json_encode([
[
'segment' => 'NSE_EQ',
'action' => 'DISABLE'
]
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response Code: $httpCode\n";
echo "Response Body: $response\n";
?>