Place GTT Order
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);
?>