Cancel Order
Cancel an open order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location --request DELETE 'https://api-hft.upstox.com/v2/order/cancel?order_id=240108010445130' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api-hft.upstox.com/v2/order/cancel?order_id=240108010445130'
headers = {
'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/v2/order/cancel?order_id=240108010445130';
const headers = {
'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/v2/order/cancel?order_id=240108010913262";
// Replace with your actual values
String acceptHeader = "application/json";
String authorizationHeader = "Bearer {your_access_token}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.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/v2/order/cancel?order_id=240108010445130';
// Replace with your actual values
$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(
'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.OrderApi(upstox_client.ApiClient(configuration))
order_id = '231221011081579'
api_version = '2.0'
try:
# Cancel order
api_response = api_instance.cancel_order(order_id, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let orderId = "240111010403654";
let apiVersion = "2.0";
apiInstance.cancelOrder(orderId, apiVersion, (error, data, response) => {
if (error) {
console.error(error);
} 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.CancelOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
String orderId = "240125010599037";
String apiVersion = "2.0"; // String | API Version Header
try {
CancelOrderResponse result = apiInstance.cancelOrder(orderId,apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}