Cancel Order V3 Sandbox Enabled
API to cancel an open or pending order which can be applied to both After Market Orders (AMO) and regular orders.
Additionally this API includes latency information in the meta data object of the response, providing insight into the time Upstox took to process your request.
Request
curl --location --request DELETE 'https://api-hft.upstox.com/v3/order/cancel?order_id=240108010445130' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
For additional samples in various languages, please refer to the Sample code section on this page.
Query Parameters
| Name | Required | Type | Description |
|---|---|---|---|
| order_id | true | string | The order ID for which the order must be cancelled. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
Responses
- 200
- 4XX
Response Body
{
"status": "success",
"data": {
"order_id": "1644490272000"
},
"metadata": {
"latency": 30
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Response data for Cancel order request |
| data.order_id | string | Reference order ID |
| metadata | object | Order metadata associated with successful cancelled order. |
| metadata.latency | integer | The overall time taken by API platform to process the order cancellation request, measured in milliseconds. |
Error codes
| Error code | Description |
|---|---|
| UDAPI1023 | Order id is required - Please ensure you provide an order id. |
| UDAPI1010 | Order id accepts only alphanumeric characters and '-'. - The order id you've provided isn't accepted. |
| UDAPI100049 | Access to this API has been restricted for your account. Please use 'Uplink Business' to place/modify/cancel the order. - Use 'Uplink Business' for order operations. |
| UDAPI100010 | Order not found - The system couldn't locate the order you're referring to. |
| UDAPI100040 | Cancel of already cancelled/rejected/completed order is not allowed - You cannot cancel orders that are already finalized in some manner. |
Sample Code
Cancel an open order
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
import requests
url = 'https://api-hft.upstox.com/v3/order/cancel?order_id=240108010445130'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.delete(url, headers=headers)
print(response.text)
const axios = require('axios');
const url = 'https://api-hft.upstox.com/v3/order/cancel?order_id=240108010445130';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}', // Replace {your_access_token} with the actual access token
};
axios.delete(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error.response ? error.response.data : error.message);
});
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) throws Exception {
String url = "https://api-hft.upstox.com/v3/order/cancel?order_id=240108010913262";
// Replace with your actual values
String contentTypeHeader = "application/json";
String acceptHeader = "application/json";
String authorizationHeader = "Bearer {your_access_token}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", contentTypeHeader)
.header("Accept", acceptHeader)
.header("Authorization", authorizationHeader)
.DELETE()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Body: " + response.body());
}
}
<?php
$url = 'https://api-hft.upstox.com/v3/order/cancel?order_id=240108010445130';
// Replace with your actual values
$contentTypeHeader = 'application/json';
$acceptHeader = 'application/json';
$authorizationHeader = 'Bearer {your_access_token}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: ' . $contentTypeHeader,
'Accept: ' . $acceptHeader,
'Authorization: ' . $authorizationHeader
));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo 'Response Code: ' . $httpCode . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration))
try:
api_response = api_instance.cancel_order("2501211050101")
print(api_response)
except ApiException as e:
print("Exception when calling OrderApiV3->cancel_order: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let apiInstance = new UpstoxClient.OrderApiV3();
apiInstance.cancelOrder("2503050177418", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + data);
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.OrderApiV3;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setAccessToken("{your_access_token}");
OrderApiV3 apiInstance = new OrderApiV3();
try {
System.out.println(apiInstance.cancelOrder("250128010534339"));
} catch (ApiException e) {
System.err.println("Exception when calling OrderApiV3->cancelOrder: " + e.getMessage());
}
}
}
Loading...