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.
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.
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
}
],
"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 | true | string | Specifies the GTT order type. Indicates if it's a single or multi-leg order. Possible values: SINGLE, MULTIPLE. |
| quantity | true | integer | Quantity with which the order is to be placed. |
| product | true | string | Signifies if the order was either Intraday, Delivery or MTF. Possible values: I, D, MTF. |
| instrument_token | true | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| transaction_type | true | string | Indicates whether its a buy or sell order. Possible values: BUY, SELL. |
| 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. 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 | 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. Note: The minimum value for trailing gap is 10% of difference between LTP and stop loss trigger price. |
- 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. |
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);
?>