Modify GTT Orderโ
This API allows to modify an existing Good Till Trigger (GTT) order by modifying its parameters, such as quantity, trigger price, or strategy rules. This ensures flexibility in adjusting trade conditions without canceling and re-creating the order.
Requestโ
curl --location --request PUT 'https://api.upstox.com/v3/order/gtt/modify' \
--header 'accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--header 'Content-Type: application/json' \
--data '{
"type": "SINGLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
}
],
"gtt_order_id": "GTT-C25270200137952"
}'
For additional samples in various languages, please refer to the Sample code section on this page.
Request Bodyโ
- Single-Leg
- Multi-Leg
- Trailing Stop Loss
{
"type": "SINGLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "BELOW",
"trigger_price": 30
}
],
"gtt_order_id": "GTT-CU25090600027002"
}
{
"type": "MULTIPLE",
"quantity": 1,
"gtt_order_id": "GTT-221130000253265",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "BELOW",
"trigger_price": 2.57
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 2.6
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 2.55
}
]
}
{
"type": "MULTIPLE",
"quantity": 1,
"gtt_order_id": "GTT-221130000253265",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "BELOW",
"trigger_price": 2.57
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 2.6,
"trailing_gap": 0.1
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 2.55
}
]
}
| Name | Required | Type | Description |
|---|---|---|---|
| type | true | string | Specifies the GTT order type. Indicates if it's a single or multi-leg order. Possible values: SINGLE, MULTIPLE. |
| quantity | true | integer | The quantity for which the order is to be placed. Note that once an order has reached OPEN status, its quantity cannot be modified. |
| gtt_order_id | true | string | The order ID for which the order must be modified. |
| rules | true | array | Contains the conditions under which the order should be triggered. |
| rules[].strategy | true | string | Defines the role of the rule. Possible values: ENTRY, TARGET, STOPLOSSENTRY - The initial condition to place a BUY or SELL order when the trigger price is met. Having an ENTRY rule is mandatory. TARGET - A condition to exit the position once the desired price level is reached after the ENTRY order is executed. STOPLOSS - A condition to exit the position when the price moves unfavorably beyond a set threshold. |
| rules[].trigger_type | true | string | Specifies the condition for triggering the order. The ENTRY strategy can have ABOVE, BELOW, or IMMEDIATE, whereas TARGET and STOPLOSS strategies can only have IMMEDIATE. Note: In case of ENTRY strategy and order status as OPEN only IMMEDIATE trigger_type is allowed.Possible values: BELOW - The order is triggered when the market price drops below the defined trigger price. ABOVE - The order is triggered when the market price rises above the defined trigger price. IMMEDIATE - Limit order at user-specified price is sent immediately to the exchange irrespective of the LTP. This order is valid for a day. If the primary leg gets completed then SL and Target legs are valid for 365 days. |
| rules[].trigger_price | true | float | The price at which the order should be triggered based on the defined condition. |
| rules[].trailing_gap | false | float | Only applicable for STOPLOSS strategy for TSL orders. This defines the consistent gap between your stop-loss and the market price, letting your stop-loss trail automatically. |
Responses
- 2XX
- 4XX
Response Bodyโ
{
"status": "success",
"data": {
"gtt_order_ids": ["GTT-CU25280200021013"]
},
"metadata": {
"latency": 74
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Possible values: success, error |
| data | object | Response data for modify order request. |
| data.gtt_order_ids[] | string | An array holding the GTT Order ID for the request placed |
| 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 |
|---|---|
| UDAPI1126 | Valid GTT type is required - The request must specify a valid GTT type. |
| UDAPI1127 | The 'type' is invalid - The provided GTT type is not recognized. |
| UDAPI1128 | GTT rules are required - At least one valid rule must be specified. |
| UDAPI1129 | GTT strategy is required - A strategy must be defined for the GTT order. |
| UDAPI1130 | Invalid GTT strategy specified - The provided strategy is not supported. |
| UDAPI1131 | GTT trigger_type is required - A trigger type must be specified. |
| UDAPI1132 | Invalid GTT trigger_type specified - The provided trigger type is not recognized. |
| UDAPI1133 | GTT trigger_price is required - A trigger price must be provided. |
| 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. |
| UDAPI1136 | For SINGLE type, rules list must contain exactly one rule - A SINGLE type GTT can have only one rule. |
| UDAPI1137 | For MULTIPLE type, the rules list must have at least 2 rules but no more than 3 - MULTIPLE type GTT orders must adhere to this rule limit. |
| UDAPI1138 | Rules contain an invalid strategy - One or more rules have an unsupported strategy. |
| UDAPI1139 | A strategy can only be used once in the rules - Duplicate strategies are not allowed in the rules list. |
| UDAPI1140 | Trigger price must be a positive value - Negative or zero trigger prices are not valid. |
| UDAPI1141 | One ENTRY strategy is required - At least one ENTRY strategy must be included in the rules. |
| UDAPI1142 | Rules contain an invalid trigger_type - One or more rules have an unsupported trigger type. |
| UDAPI1143 | Non-ENTRY strategies must have only IMMEDIATE trigger type - Only the IMMEDIATE trigger type is allowed for non-ENTRY strategies. |
| UDAPI1150 | Only IMMEDIATE trigger type is allowed when modifying open GTT orders - Once a GTT order is in open status, modifications can only use the IMMEDIATE trigger type. |
Sample Codeโ
Modify Single Leg GTT Orderโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location --request PUT 'https://api.upstox.com/v3/order/gtt/modify' \
--header 'accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--header 'Content-Type: application/json' \
--data '{
"type": "SINGLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
}
],
"gtt_order_id": "GTT-C25270200137952"
}'
import requests
url = 'https://api.upstox.com/v3/order/gtt/modify'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"type": "SINGLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
}
],
"gtt_order_id": "GTT-C25270200137952"
}
try:
# Send the PUT request
response = requests.put(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/modify';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
type: 'SINGLE',
quantity: 1,
rules: [
{
strategy: 'ENTRY',
trigger_type: 'ABOVE',
trigger_price: 7.3
}
],
gtt_order_id: 'GTT-C25270200137952'
};
axios.put(url, data, { headers })
.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/modify";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"type\": \"SINGLE\","
+ "\"quantity\": 1,"
+ "\"rules\": ["
+ "{"
+ "\"strategy\": \"ENTRY\","
+ "\"trigger_type\": \"ABOVE\","
+ "\"trigger_price\": 7.3"
+ "}"
+ "],"
+ "\"gtt_order_id\": \"GTT-C25270200137952\""
+ "}";
// 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)
.PUT(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/modify';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'type' => 'SINGLE',
'quantity' => 1,
'rules' => [
[
'strategy' => 'ENTRY',
'trigger_type' => 'ABOVE',
'trigger_price' => 7.3
]
],
'gtt_order_id' => 'GTT-C25270200137952'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
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))
entry_rule = upstox_client.GttRule(strategy="ENTRY", trigger_type="ABOVE", trigger_price=7.3)
rules = [entry_rule]
body = upstox_client.GttModifyOrderRequest(
type="SINGLE",
gtt_order_id="GTT-C25270200137952",
rules=rules,
quantity=1
)
try:
api_response = api_instance.modify_gtt_order(body=body)
print("GTT order response:", api_response)
except ApiException as e:
print("Exception when calling OrderApi->modify_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 entryRule = new UpstoxClient.GttRule(
UpstoxClient.GttRule.StrategyEnum.ENTRY,
UpstoxClient.GttRule.TriggerTypeEnum.ABOVE,
100
);
let body = new UpstoxClient.GttModifyOrderRequest(
UpstoxClient.GttModifyOrderRequest.TypeEnum.SINGLE,
1,
[entryRule],
"GTT-C25270200137952"
);
apiInstance.modifyGTTOrder(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.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setAccessToken("{your_access_token}");
OrderApiV3 apiInstance = new OrderApiV3();
List<GttRule> gttRules = new ArrayList<>();
GttRule entryRule = new GttRule();
entryRule.setStrategy(GttRule.StrategyEnum.ENTRY);
entryRule.setTriggerType(GttRule.TriggerTypeEnum.ABOVE);
entryRule.setTriggerPrice(7.3D);
gttRules.add(entryRule);
GttModifyOrderRequest modifyOrderRequest = new GttModifyOrderRequest();
modifyOrderRequest.setQuantity(1);
modifyOrderRequest.setGttOrderId("GTT-C25270200137952");
modifyOrderRequest.setType(GttModifyOrderRequest.TypeEnum.SINGLE);
modifyOrderRequest.setRules(gttRules);
try {
GttTriggerOrderResponse result = apiInstance.modifyGTTOrder(modifyOrderRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi->modifyGTTOrder: " + e.getMessage());
}
}
}
Modify Multiple Leg GTT Orderโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location --request PUT 'https://api.upstox.com/v3/order/gtt/modify' \
--header 'accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--header 'Content-Type: application/json' \
--data '{
"type": "MULTIPLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.64
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.1
}
],
"gtt_order_id": "GTT-C25280200137522"
}'
import requests
url = 'https://api.upstox.com/v3/order/gtt/modify'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"type": "MULTIPLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.64
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.1
}
],
"gtt_order_id": "GTT-C25280200137522"
}
try:
# Send the PUT request
response = requests.put(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/modify';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
type: 'MULTIPLE',
quantity: 1,
rules: [
{
strategy: 'ENTRY',
trigger_type: 'ABOVE',
trigger_price: 7.3
},
{
strategy: 'TARGET',
trigger_type: 'IMMEDIATE',
trigger_price: 7.64
},
{
strategy: 'STOPLOSS',
trigger_type: 'IMMEDIATE',
trigger_price: 7.1
}
],
gtt_order_id: 'GTT-C25280200137522'
};
axios.put(url, data, { headers })
.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/modify";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"type\": \"MULTIPLE\","
+ "\"quantity\": 1,"
+ "\"rules\": ["
+ "{"
+ "\"strategy\": \"ENTRY\","
+ "\"trigger_type\": \"ABOVE\","
+ "\"trigger_price\": 7.3"
+ "},"
+ "{"
+ "\"strategy\": \"TARGET\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 7.64"
+ "},"
+ "{"
+ "\"strategy\": \"STOPLOSS\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 7.1"
+ "}"
+ "],"
+ "\"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)
.PUT(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/modify';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'type' => 'MULTIPLE',
'quantity' => 1,
'rules' => [
[
'strategy' => 'ENTRY',
'trigger_type' => 'ABOVE',
'trigger_price' => 7.3
],
[
'strategy' => 'TARGET',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 7.64
],
[
'strategy' => 'STOPLOSS',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 7.1
]
],
'gtt_order_id' => 'GTT-C25280200137522'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
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))
entry_rule = upstox_client.GttRule(strategy="ENTRY", trigger_type="ABOVE", trigger_price=7.3)
target_rule = upstox_client.GttRule(strategy="TARGET", trigger_type="IMMEDIATE", trigger_price=7.64)
stoploss_rule = upstox_client.GttRule(strategy="STOPLOSS", trigger_type="IMMEDIATE", trigger_price=7.1)
rules = [entry_rule, target_rule, stoploss_rule]
body = upstox_client.GttModifyOrderRequest(
type="MULTIPLE",
gtt_order_id="GTT-C25280200137522",
rules=rules,
quantity=1
)
try:
api_response = api_instance.modify_gtt_order(body=body)
print("GTT order response:", api_response)
except ApiException as e:
print("Exception when calling OrderApi->modify_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 entryRule = new UpstoxClient.GttRule(
UpstoxClient.GttRule.StrategyEnum.ENTRY,
UpstoxClient.GttRule.TriggerTypeEnum.ABOVE,
7.3
);
let targetRule = new UpstoxClient.GttRule(
UpstoxClient.GttRule.StrategyEnum.TARGET,
UpstoxClient.GttRule.TriggerTypeEnum.IMMEDIATE,
7.64
);
let stopLossRule = new UpstoxClient.GttRule(
UpstoxClient.GttRule.StrategyEnum.STOPLOSS,
UpstoxClient.GttRule.TriggerTypeEnum.IMMEDIATE,
7.1
);
let body = new UpstoxClient.GttModifyOrderRequest(
UpstoxClient.GttModifyOrderRequest.TypeEnum.MULTIPLE,
1,
[entryRule, targetRule, stopLossRule],
"GTT-C25280200137522"
);
apiInstance.modifyGTTOrder(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.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setAccessToken("{your_access_token}");
OrderApiV3 apiInstance = new OrderApiV3();
List<GttRule> gttRules = new ArrayList<>();
GttRule entryRule = new GttRule();
entryRule.setStrategy(GttRule.StrategyEnum.ENTRY);
entryRule.setTriggerType(GttRule.TriggerTypeEnum.ABOVE);
entryRule.setTriggerPrice(7.3D);
gttRules.add(entryRule);
GttRule targetRule = new GttRule();
targetRule.setStrategy(GttRule.StrategyEnum.TARGET);
targetRule.setTriggerType(GttRule.TriggerTypeEnum.IMMEDIATE);
targetRule.setTriggerPrice(7.64D);
gttRules.add(targetRule);
GttRule stopLossRule = new GttRule();
stopLossRule.setStrategy(GttRule.StrategyEnum.STOPLOSS);
stopLossRule.setTriggerType(GttRule.TriggerTypeEnum.IMMEDIATE);
stopLossRule.setTriggerPrice(7.1D);
gttRules.add(stopLossRule);
GttModifyOrderRequest modifyOrderRequest = new GttModifyOrderRequest();
modifyOrderRequest.setQuantity(1);
modifyOrderRequest.setGttOrderId("GTT-C25280200137522");
modifyOrderRequest.setType(GttModifyOrderRequest.TypeEnum.MULTIPLE);
modifyOrderRequest.setRules(gttRules);
try {
GttTriggerOrderResponse result = apiInstance.modifyGTTOrder(modifyOrderRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi->modifyGTTOrder: " + e.getMessage());
}
}
}
Modify Trailing Stop Loss GTT Orderโ
- Curl
- Python
- Node.js
- Java
- PHP
curl --location --request PUT 'https://api.upstox.com/v3/order/gtt/modify' \
--header 'accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--header 'Content-Type: application/json' \
--data '{
"type": "MULTIPLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.64
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.1,
"trailing_gap": 0.1
}
],
"gtt_order_id": "GTT-C25280200137522"
}'
import requests
url = 'https://api.upstox.com/v3/order/gtt/modify'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"type": "MULTIPLE",
"quantity": 1,
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.64
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 7.1,
"trailing_gap": 0.1
}
],
"gtt_order_id": "GTT-C25280200137522"
}
try:
# Send the PUT request
response = requests.put(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/modify';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
type: 'MULTIPLE',
quantity: 1,
rules: [
{
strategy: 'ENTRY',
trigger_type: 'ABOVE',
trigger_price: 7.3
},
{
strategy: 'TARGET',
trigger_type: 'IMMEDIATE',
trigger_price: 7.64
},
{
strategy: 'STOPLOSS',
trigger_type: 'IMMEDIATE',
trigger_price: 7.1,
trailing_gap: 0.1
}
],
gtt_order_id: 'GTT-C25280200137522'
};
axios.put(url, data, { headers })
.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/modify";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"type\": \"MULTIPLE\","
+ "\"quantity\": 1,"
+ "\"rules\": ["
+ "{"
+ "\"strategy\": \"ENTRY\","
+ "\"trigger_type\": \"ABOVE\","
+ "\"trigger_price\": 7.3"
+ "},"
+ "{"
+ "\"strategy\": \"TARGET\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 7.64"
+ "},"
+ "{"
+ "\"strategy\": \"STOPLOSS\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 7.1,"
+ "\"trailing_gap\": 0.1"
+ "}"
+ "],"
+ "\"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)
.PUT(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/modify';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'type' => 'MULTIPLE',
'quantity' => 1,
'rules' => [
[
'strategy' => 'ENTRY',
'trigger_type' => 'ABOVE',
'trigger_price' => 7.3
],
[
'strategy' => 'TARGET',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 7.64
],
[
'strategy' => 'STOPLOSS',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 7.1,
'trailing_gap' => 0.1
]
],
'gtt_order_id' => 'GTT-C25280200137522'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
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);
?>
Loading...