Cancel GTT Order
This API allows the cancellation of an existing Good Till Trigger (GTT) order that has not yet been triggered. Once canceled, all associated legs will be canceled and will no longer be monitored for execution, and all related trigger conditions will be discarded.
Request
curl --location --request DELETE 'https://api.upstox.com/v3/order/gtt/cancel' \
--header 'accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--header 'Content-Type: application/json' \
--data '{
"gtt_order_id": "GTT-C25280200137522"
}'
For additional samples in various languages, please refer to the Sample code section on this page.
Request Body
| Name | Required | Type | Description |
|---|---|---|---|
| gtt_order_id | true | string | The order ID for which the order must be cancelled. |
Responses
- 2XX
- 4XX
Response Body
{
"status": "success",
"data": {
"gtt_order_ids": ["GTT-CU25280200018007"]
},
"metadata": {
"latency": 65
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Possible values: success, error |
| data | object | Response data for cancel order request. |
| data.gtt_order_id | string | The Order ID submitted for cancellation. |
| metadata | object | Metadata information. |
| metadata.latency | integer | The overall time taken by API platform to process the request, measured in milliseconds. |
Error Codes
| Error Code | Description |
|---|---|
| UDAPI1134 | gtt_order_id is required - The request must include a valid GTT order ID. |
| UDAPI1135 | GTT order ID must start with 'GTT-' - The order ID should follow the required format. |
Sample Code
Cancel GTT Order
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
import requests
url = 'https://api.upstox.com/v3/order/gtt/cancel'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'gtt_order_id': 'GTT-C25280200137522'
}
try:
# Send the DELETE request
response = requests.delete(url, json=data, headers=headers)
# Print the response status code and body
print('Response Code:', response.status_code)
print('Response Body:', response.json())
except Exception as e:
# Handle exceptions
print('Error:', str(e))
const axios = require('axios');
const url = 'https://api.upstox.com/v3/order/gtt/cancel';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
gtt_order_id: 'GTT-C25280200137522'
};
axios.delete(url, { headers, data })
.then(response => {
console.log('Response:', response.data);
})
.catch(error => {
console.error('Error:', 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) {
String url = "https://api.upstox.com/v3/order/gtt/cancel";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"gtt_order_id\": \"GTT-C25280200137522\""
+ "}";
// Create the HttpClient
HttpClient httpClient = HttpClient.newHttpClient();
// Create the HttpRequest
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", token)
.method("DELETE", HttpRequest.BodyPublishers.ofString(requestBody))
.build();
try {
// Send the request and retrieve the response
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Print the response status code and body
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Body: " + response.body());
} catch (Exception e) {
// Handle exceptions
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v3/order/gtt/cancel';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: ' . 'Bearer {your_access_token}',
];
$data = [
'gtt_order_id' => 'GTT-C25280200137522'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
if ($response === false) {
echo 'Error: ' . curl_error($ch);
} else {
echo 'Response: ' . $response;
}
curl_close($ch);
?>
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))
body = upstox_client.GttCancelOrderRequest(gtt_order_id="GTT-C250303008840")
try:
api_response = api_instance.cancel_gtt_order(body=body)
print("GTT order canceled:", api_response)
except ApiException as e:
print("Exception when calling OrderApi->cancel_gtt_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();
let body = new UpstoxClient.GttCancelOrderRequest("GTT-C25050300168902");
apiInstance.cancelGTTOrder(body, (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.*;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setAccessToken("{your_access_token}");
OrderApiV3 apiInstance = new OrderApiV3();
GttCancelOrderRequest gttCancelOrderRequest = new GttCancelOrderRequest();
gttCancelOrderRequest.setGttOrderId("GTT-C25040144712");
try {
GttTriggerOrderResponse result = apiInstance.cancelGTTOrder(gttCancelOrderRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi->cancelGTTOrder: " + e.getMessage());
}
}
}
Loading...