POST/order/gtt/place
Place GTT Order
Good Till Triggered (GTT) order is a condition-based order that remains active until the defined condition (rule) is met. A rule is a precise condition that determines when the system should execute an order. This order can be executed as a single-leg or multi-leg operation, with each leg scheduled to place an order based on a specific rule. Once the condition is met, the order is placed automatically.
Order APIs share one limit of 10 requests per second, 500 per minute and 2,000 per 30 minutes. SEBI-registered algos get 50 requests per second. See Rate Limits.
Single-Leg Trigger
This order uses one rule to place an order when the condition is satisfied. The opening strategy is called ENTRY, where you define a condition to BUY or SELL a stock when the price is above, below, or equal to the trigger price. Once the order is placed, the GTT is complete.
Multi-Leg Trigger
This order involves more than one rule and includes follow-up actions. The ENTRY strategy remains the same as in the Single-Leg Trigger, but additional actions can be set.
You can follow the ENTRY strategy with:
- TARGET: A condition to exit the position once the desired price level is reached.
- STOPLOSS: A condition to exit the position when the price moves unfavorably beyond a set threshold.
For example, if your ENTRY is a BUY, the TARGET and STOPLOSS will be SELL orders, and vice versa.
Trailing Stop Loss Order Beta
A trailing stop loss order is a dynamic order that automatically adjusts with market price movements, maintaining a consistent distance from the current market price as it moves.
Trailing Stop Loss (TSL) orders are implemented as Multi-leg GTT orders and in the STOPLOSS leg an additional parameter trailing_gap is required. This defines the consistent gap between your stop-loss and the market price, letting your stop-loss trail automatically. For more details on TSL orders, refer to our Trailing Stop Loss Order article.
- While order placement requests are made through a Registered app, the X-Algo-Name header is optional and only required if you have an exchange-approved algo strategy. When applicable, the value of this header should match one of the Algo names configured in the app settings.
Request
curl --location 'https://api.upstox.com/v3/order/gtt/place' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"type": "SINGLE",
"quantity": 1,
"product": "D",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 6,
"market_protection": 0
}
],
"instrument_token": "NSE_EQ|INE669E01016",
"transaction_type": "BUY"
}'
For additional samples in various languages, please refer to the Sample code section on this page.
Request Body
| Name | Required | Type | Description |
|---|---|---|---|
| type | Required | string | Specifies the GTT order type. Indicates if it's a single or multi-leg order. Possible values: SINGLE, MULTIPLE. |
| quantity | Required | integer | Quantity with which the order is to be placed. |
| product | Required | string | Signifies if the order was either Intraday, Delivery or MTF. Possible values: I, D, MTF. |
| instrument_token | Required | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| transaction_type | Required | string | Indicates whether its a buy or sell order. Possible values: BUY, SELL. |
| rules | Required | array | Contains the conditions under which the order should be triggered. |
| rules[].strategy | Required | 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 | Required | 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. Possible values: BELOW, ABOVE, IMMEDIATEBELOW - 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 | Required | float | The price at which the order should be triggered based on the defined condition. |
| rules[].trailing_gap | Optional | 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. Note: The minimum value for trailing gap is 10% of difference between LTP and stop loss trigger price. |
| rules[].market_protection | Optional | integer (int32) | Applicable for all three ENTRY, TARGET, and STOPLOSS strategies, for Market and Stoploss Market (SL-M) orders. This will be ignored if used with Limit or Stoploss Limit (SL) orders. Default: -1.-1 = Automatic market protection as per guidelines. For more details, see Market Protection details.1 – 25 = Custom market protection percentage (e.g. 2 for 2%).0 = No market protection (Order will be rejected due to exchange restrictions on MARKET orders from API). |
Responses
- 2XX
- 4XX
Response Body
{
"status": "success",
"data": {
"gtt_order_ids": ["GTT-CU25280200021013"]
},
"metadata": {
"latency": 88
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Possible values: success, error |
| data | object | Response data for place 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. |
| 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. |
| UDAPI1151 | Trailing gap cannot be less than minimum value - The minimum value for trailing gap is 10% of difference between LTP and stop loss trigger price. |
| UDAPI1154 | Access to this API is blocked due to static IP restrictions. - Thrown when the request is made from a static IP that is not whitelisted. |
| UDAPI1156 | Invalid Algo name passed in headers - Thrown when the X-Algo-Name in the request headers is invalid. |
| UDAPI1158 | Market orders are not allowed. Try placing a limit order. - Market orders are currently blocked due to exchange restrictions. You may try placing orders using the Market Protection feature instead. |
| UDAPI1176 | Market Protection cannot be greater than 25%. - The market protection percentage cannot be greater than 25%. Please try again with a value between -1 and 25. |
| UDAPI1177 | Invalid market protection. - The market protection percentage is not valid. |
| UDAPI1250 | This instrument's segment cannot be traded through this API. - The instrument belongs to a segment this API cannot route. |
| UDAPI1251 | US stocks cannot be ordered through this API. Use the US order API instead. - Use the US Stocks Place Order API for US_EQ instruments. |
Sample Code
Place Single Leg GTT Order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/order/gtt/place' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"type": "SINGLE",
"quantity": 1,
"product": "D",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 6
}
],
"instrument_token": "NSE_EQ|INE669E01016",
"transaction_type": "BUY"
}'
import requests
url = 'https://api.upstox.com/v3/order/gtt/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"type": "SINGLE",
"quantity": 1,
"product": "D",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 6
}
],
"instrument_token": "NSE_EQ|INE669E01016",
"transaction_type": "BUY"
}
try:
# Send the POST request
response = requests.post(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/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
type: 'SINGLE',
quantity: 1,
product: 'D',
rules: [
{
strategy: 'ENTRY',
trigger_type: 'ABOVE',
trigger_price: 6
}
],
instrument_token: 'NSE_EQ|INE669E01016',
transaction_type: 'BUY'
};
axios.post(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/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"type\": \"SINGLE\","
+ "\"quantity\": 1,"
+ "\"product\": \"D\","
+ "\"rules\": [{"
+ "\"strategy\": \"ENTRY\","
+ "\"trigger_type\": \"ABOVE\","
+ "\"trigger_price\": 6"
+ "}],"
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"transaction_type\": \"BUY\""
+ "}";
// 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)
.POST(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/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'type' => 'SINGLE',
'quantity' => 1,
'product' => 'D',
'rules' => [
[
'strategy' => 'ENTRY',
'trigger_type' => 'ABOVE',
'trigger_price' => 6
]
],
'instrument_token' => 'NSE_EQ|INE669E01016',
'transaction_type' => 'BUY',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
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)
rules = [entry_rule]
body = upstox_client.GttPlaceOrderRequest(
type="SINGLE",
instrument_token="NSE_EQ|INE669E01016",
product="D",
quantity=1,
rules=rules,
transaction_type="BUY"
)
try:
api_response = api_instance.place_gtt_order(body=body)
print("GTT order response:", api_response)
except ApiException as e:
print("Exception when calling OrderApi->gtt_place_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.GttPlaceOrderRequest(
UpstoxClient.GttPlaceOrderRequest.TypeEnum.SINGLE,
1,
UpstoxClient.GttPlaceOrderRequest.ProductEnum.D,
[entryRule],
"NSE_EQ|INE669E01016",
UpstoxClient.GttPlaceOrderRequest.TransactionTypeEnum.BUY
);
apiInstance.placeGTTOrder(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();
GttPlaceOrderRequest gttPlaceOrderRequest = new GttPlaceOrderRequest();
gttPlaceOrderRequest.setQuantity(1);
gttPlaceOrderRequest.setProduct(GttPlaceOrderRequest.ProductEnum.D);
gttPlaceOrderRequest.setInstrumentToken("NSE_EQ|INE669E01016");
gttPlaceOrderRequest.setType(GttPlaceOrderRequest.TypeEnum.SINGLE);
gttPlaceOrderRequest.setTransactionType(GttPlaceOrderRequest.TransactionTypeEnum.BUY);
List<GttRule> gttRules = new ArrayList<>();
GttRule entryRule = new GttRule();
entryRule.setStrategy(GttRule.StrategyEnum.ENTRY);
entryRule.setTriggerType(GttRule.TriggerTypeEnum.ABOVE);
entryRule.setTriggerPrice(7D);
gttRules.add(entryRule);
gttPlaceOrderRequest.setRules(gttRules);
try {
GttTriggerOrderResponse result = apiInstance.placeGTTOrder(gttPlaceOrderRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi->placeGTTOrder: " + e.getMessage());
}
}
}
Place Multiple Leg GTT Order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/order/gtt/place' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"type": "MULTIPLE",
"quantity": 1,
"product": "I",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 9
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 6
}
],
"instrument_token": "NSE_EQ|INE669E01016",
"transaction_type": "BUY"
}'
import requests
url = 'https://api.upstox.com/v3/order/gtt/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"type": "MULTIPLE",
"quantity": 1,
"product": "I",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 9
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 6
}
],
"instrument_token": "NSE_EQ|INE669E01016",
"transaction_type": "BUY"
}
try:
# Send the POST request
response = requests.post(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/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
type: 'MULTIPLE',
quantity: 1,
product: 'I',
rules: [
{
strategy: 'ENTRY',
trigger_type: 'ABOVE',
trigger_price: 7.3
},
{
strategy: 'TARGET',
trigger_type: 'IMMEDIATE',
trigger_price: 9
},
{
strategy: 'STOPLOSS',
trigger_type: 'IMMEDIATE',
trigger_price: 6
}
],
instrument_token: 'NSE_EQ|INE669E01016',
transaction_type: 'BUY'
};
axios.post(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/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"type\": \"MULTIPLE\","
+ "\"quantity\": 1,"
+ "\"product\": \"I\","
+ "\"rules\": ["
+ "{"
+ "\"strategy\": \"ENTRY\","
+ "\"trigger_type\": \"ABOVE\","
+ "\"trigger_price\": 7.3"
+ "},"
+ "{"
+ "\"strategy\": \"TARGET\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 9"
+ "},"
+ "{"
+ "\"strategy\": \"STOPLOSS\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 6"
+ "}"
+ "],"
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"transaction_type\": \"BUY\""
+ "}";
// 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)
.POST(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/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'type' => 'MULTIPLE',
'quantity' => 1,
'product' => 'I',
'rules' => [
[
'strategy' => 'ENTRY',
'trigger_type' => 'ABOVE',
'trigger_price' => 7.3
],
[
'strategy' => 'TARGET',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 9
],
[
'strategy' => 'STOPLOSS',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 6
]
],
'instrument_token' => 'NSE_EQ|INE669E01016',
'transaction_type' => 'BUY',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
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)
target_rule = upstox_client.GttRule(strategy="TARGET", trigger_type="IMMEDIATE", trigger_price=9)
stoploss_rule = upstox_client.GttRule(strategy="STOPLOSS", trigger_type="IMMEDIATE", trigger_price=5)
rules = [entry_rule, target_rule, stoploss_rule]
body = upstox_client.GttPlaceOrderRequest(
type="MULTIPLE",
instrument_token="NSE_EQ|INE669E01016",
product="D",
quantity=1,
rules=rules,
transaction_type="BUY"
)
try:
api_response = api_instance.place_gtt_order(body=body)
print("GTT order response:", api_response)
except ApiException as e:
print("Exception when calling OrderApi->gtt_place_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 stopLossRule = new UpstoxClient.GttRule(
UpstoxClient.GttRule.StrategyEnum.STOPLOSS,
UpstoxClient.GttRule.TriggerTypeEnum.IMMEDIATE,
80
);
let targetRule = new UpstoxClient.GttRule(
UpstoxClient.GttRule.StrategyEnum.TARGET,
UpstoxClient.GttRule.TriggerTypeEnum.IMMEDIATE,
120
);
let body = new UpstoxClient.GttPlaceOrderRequest(
UpstoxClient.GttPlaceOrderRequest.TypeEnum.MULTIPLE,
1,
UpstoxClient.GttPlaceOrderRequest.ProductEnum.D,
[entryRule,stopLossRule,targetRule],
"NSE_EQ|INE669E01016",
UpstoxClient.GttPlaceOrderRequest.TransactionTypeEnum.BUY
);
apiInstance.placeGTTOrder(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();
GttPlaceOrderRequest gttPlaceOrderRequest = new GttPlaceOrderRequest();
gttPlaceOrderRequest.setQuantity(1);
gttPlaceOrderRequest.setProduct(GttPlaceOrderRequest.ProductEnum.D);
gttPlaceOrderRequest.setInstrumentToken("NSE_EQ|INE669E01016");
gttPlaceOrderRequest.setType(GttPlaceOrderRequest.TypeEnum.MULTIPLE);
gttPlaceOrderRequest.setTransactionType(GttPlaceOrderRequest.TransactionTypeEnum.BUY);
List<GttRule> gttRules = new ArrayList<>();
GttRule entryRule = new GttRule();
entryRule.setStrategy(GttRule.StrategyEnum.ENTRY);
entryRule.setTriggerType(GttRule.TriggerTypeEnum.ABOVE);
entryRule.setTriggerPrice(7D);
gttRules.add(entryRule);
GttRule stopLossRule = new GttRule();
stopLossRule.setStrategy(GttRule.StrategyEnum.STOPLOSS);
stopLossRule.setTriggerType(GttRule.TriggerTypeEnum.IMMEDIATE);
stopLossRule.setTriggerPrice(6D);
gttRules.add(stopLossRule);
GttRule targetRule = new GttRule();
targetRule.setStrategy(GttRule.StrategyEnum.TARGET);
targetRule.setTriggerType(GttRule.TriggerTypeEnum.IMMEDIATE);
targetRule.setTriggerPrice(60D);
gttRules.add(targetRule);
gttPlaceOrderRequest.setRules(gttRules);
try {
GttTriggerOrderResponse result = apiInstance.placeGTTOrder(gttPlaceOrderRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi->placeGTTOrder: " + e.getMessage());
}
}
}
Place Trailing Stop Loss GTT Order
- Curl
- Python
- Node.js
- Java
- PHP
curl --location 'https://api.upstox.com/v3/order/gtt/place' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"type": "MULTIPLE",
"quantity": 1,
"product": "I",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 9
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 6,
"trailing_gap": 0.1
}
],
"instrument_token": "NSE_EQ|INE669E01016",
"transaction_type": "BUY"
}'
import requests
url = 'https://api.upstox.com/v3/order/gtt/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"type": "MULTIPLE",
"quantity": 1,
"product": "I",
"rules": [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": 7.3
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": 9
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": 6,
"trailing_gap": 0.1
}
],
"instrument_token": "NSE_EQ|INE669E01016",
"transaction_type": "BUY"
}
try:
# Send the POST request
response = requests.post(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/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
type: 'MULTIPLE',
quantity: 1,
product: 'I',
rules: [
{
strategy: 'ENTRY',
trigger_type: 'ABOVE',
trigger_price: 7.3
},
{
strategy: 'TARGET',
trigger_type: 'IMMEDIATE',
trigger_price: 9
},
{
strategy: 'STOPLOSS',
trigger_type: 'IMMEDIATE',
trigger_price: 6,
trailing_gap: 0.1
}
],
instrument_token: 'NSE_EQ|INE669E01016',
transaction_type: 'BUY'
};
axios.post(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/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"type\": \"MULTIPLE\","
+ "\"quantity\": 1,"
+ "\"product\": \"I\","
+ "\"rules\": ["
+ "{"
+ "\"strategy\": \"ENTRY\","
+ "\"trigger_type\": \"ABOVE\","
+ "\"trigger_price\": 7.3"
+ "},"
+ "{"
+ "\"strategy\": \"TARGET\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 9"
+ "},"
+ "{"
+ "\"strategy\": \"STOPLOSS\","
+ "\"trigger_type\": \"IMMEDIATE\","
+ "\"trigger_price\": 6,"
+ "\"trailing_gap\": 0.1"
+ "}"
+ "],"
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"transaction_type\": \"BUY\""
+ "}";
// 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)
.POST(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/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'type' => 'MULTIPLE',
'quantity' => 1,
'product' => 'I',
'rules' => [
[
'strategy' => 'ENTRY',
'trigger_type' => 'ABOVE',
'trigger_price' => 7.3
],
[
'strategy' => 'TARGET',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 9
],
[
'strategy' => 'STOPLOSS',
'trigger_type' => 'IMMEDIATE',
'trigger_price' => 6,
'trailing_gap' => 0.1
]
],
'instrument_token' => 'NSE_EQ|INE669E01016',
'transaction_type' => 'BUY',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
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);
?>
- A GTT order is always placed as a LIMIT order upon execution.
- To place GTT orders with a SELL leg, EDIS authorization is required. You can authorize EDIS from any of our platforms—Web, iOS, or Android by placing a GTT order. Once authorized on any one platform, it will also be valid for API-based orders. You don't need to complete the order; simply going through the authorization flow is sufficient.
- We currently support a maximum of three rules with no duplicate strategies.
- A GTT order remains valid for up to one year from the date of creation if the defined condition is not met.
- Receiving GTT order updates via Webhook requires additional setup, detailed here.
- Receiving GTT order updates via WebSocket requires additional setup, detailed here.