Place Order Sandbox Enabled Deprecated
API to place an order to the exchange. The instrument_token required for the stock or contracts should be obtained from the BOD instruments.
Upon successfully placing the order with the exchange, a unique order_id is provided in the success response, which can be utilized for order modification or cancellation. If you intend to place an order outside of market hours, the 'is_amo' (After Market Order) should be set to 'true'. You can assign a tag(unique identifier) to your order, allowing you to retrieve orders associated with that tag using the Order History API.
Request
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_EQ|INE669E01016",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false
}'
Additional samples in various languages are available in the Sample Code section on this page.
Request Body
| Name | Required | Type | Description |
|---|---|---|---|
| quantity | true | integer (int32) | Quantity with which the order is to be placed. For commodity - number of lots is accepted. For other Futures & Options and equities - number of units is accepted in multiples of the tick size. |
| product | true | string | Signifies if the order was either Intraday or Delivery. Possible values: I, D, MTF. |
| validity | true | string | It can be one of the following - DAY(default), IOC. Possible values: DAY, IOC. |
| price | true | number (float) | Price at which the order will be placed |
| tag | false | string | Tag for a particular order |
| instrument_token | true | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| order_type | true | string | Type of order. It can be one of the following MARKET refers to market order LIMIT refers to Limit Order SL refers to Stop Loss Limit SL-M refers to Stop Loss Market. Possible values: MARKET, LIMIT, SL, SL-M. |
| transaction_type | true | string | Indicates whether its a buy or sell order. Possible values: BUY, SELL. |
| disclosed_quantity | true | integer (int32) | The quantity that should be disclosed in the market depth |
| trigger_price | true | number (float) | If the order is a stop loss order then the trigger price to be set is mentioned here |
| is_amo | true | boolean | Signifies if the order is an After Market Order |
Responses
- 200
- 4XX
Response Body
{
"status": "success",
"data": {
"order_id": "1644490272000"
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Response data for place order request |
| data.order_id | string | An order ID for the order request placed |
Error codes
| Error code | Description |
|---|---|
| UDAPI1026 | Instrument key is required - You need to provide the instrument key for this operation. |
| UDAPI1004 | Valid order type is required - Please ensure to provide a recognized order type. |
| UDAPI1056 | The 'order_type' is invalid - The specified order type isn't acceptable. |
| UDAPI1057 | The 'transaction_type' is invalid - The given transaction type is not valid. |
| UDAPI1006 | Product is required - You must specify the product in your request. |
| UDAPI1054 | The 'product' is invalid - The provided product value doesn't match any accepted values. |
| UDAPI1007 | Validity is required - You need to provide the duration the order will remain in effect. |
| UDAPI1055 | The 'validity' is invalid - The specified order validity isn't recognized. |
| UDAPI1008 | Price is required - Please specify the price in your request. |
| UDAPI100049 | Access to this API has been restricted for your account. Please use 'Uplink Business' to place/modify/cancel the order. - Use 'Uplink Business' for order operations. |
| UDAPI1052 | The order 'quantity' cannot be zero - You cannot set the order quantity to zero. |
| UDAPI1040 | Price not required - You shouldn't specify a price for this type of order. |
| UDAPI1043 | The 'price' is required - A valid price value needs to be provided for this order type. |
| UDAPI1041 | The 'price' and 'trigger_price' both are required - Ensure to specify both price values in your request. |
| UDAPI1042 | Only 'trigger_price' is required - Only the trigger price needs to be provided, not the regular price. |
| UDAPI1037 | Trigger price should be less than limit price - Ensure your trigger price is set below the limit price. |
| UDAPI1038 | Trigger price should be greater than limit price - The trigger price should exceed the limit price value. |
| UDAPI100011 | Invalid Instrument key - The instrument key you provided doesn't match any recognized keys. |
| UDAPI100039 | AMO orders cannot be placed during the market hours - After Market Order (AMO) is not valid during active market sessions. |
| UDAPI100074 | The Place order API is accessible from 5:30 AM to 12:00 AM IST daily - Thrown when an Place Order API is called between midnight and 5:30 AM in the morning. |
Sample Code
Place a delivery market order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_EQ|INE669E01016",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'D',
'validity': 'DAY',
'price': 0,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE669E01016',
'order_type': 'MARKET',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 0,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'D',
validity: 'DAY',
price: 0,
tag: 'string',
instrument_token: 'NSE_EQ|INE669E01016',
order_type: 'MARKET',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 0,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'D',
'validity' => 'DAY',
'price' => 0,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE669E01016',
'order_type' => 'MARKET',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 0,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 0.0, "string", "NSE_EQ|INE528G01035", "MARKET", "BUY", 0, 0.0, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.D, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 0.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.MARKET,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 0.0, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.D);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(0F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE669E01016");
body.orderType(PlaceOrderRequest.OrderTypeEnum.MARKET);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(0F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place a delivery limit order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "D",
"validity": "DAY",
"price": 13,
"tag": "string",
"instrument_token": "NSE_EQ|INE669E01016",
"order_type": "LIMIT",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 13.2,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'D',
'validity': 'DAY',
'price': 13,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE669E01016',
'order_type': 'LIMIT',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 13.2,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'D',
validity: 'DAY',
price: 13,
tag: 'string',
instrument_token: 'NSE_EQ|INE669E01016',
order_type: 'LIMIT',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 13.2,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 13,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"order_type\": \"LIMIT\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 13.2,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'D',
'validity' => 'DAY',
'price' => 13,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE669E01016',
'order_type' => 'LIMIT',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 13.2,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 20.0, "string", "NSE_EQ|INE528G01035", "LIMIT", "BUY", 0, 20.1, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.D, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 20.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.LIMIT,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 20.1, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.D);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(14F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE669E01016");
body.orderType(PlaceOrderRequest.OrderTypeEnum.LIMIT);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(14.1F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place a delivery stop-loss order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "D",
"validity": "DAY",
"price": 14.05,
"tag": "string",
"instrument_token": "NSE_EQ|INE669E01016",
"order_type": "SL",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 13,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'D',
'validity': 'DAY',
'price': 14.05,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE669E01016',
'order_type': 'SL',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 13,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'D',
validity: 'DAY',
price: 14.05,
tag: 'string',
instrument_token: 'NSE_EQ|INE669E01016',
order_type: 'SL',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 13,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 14.05,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"order_type\": \"SL\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 13,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'D',
'validity' => 'DAY',
'price' => 14.05,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE669E01016',
'order_type' => 'SL',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 13,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 20, "string", "NSE_EQ|INE528G01035", "SL", "BUY", 0, 19.5, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.D, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 20.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.SL,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 19.5, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.D);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(14F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE669E01016");
body.orderType(PlaceOrderRequest.OrderTypeEnum.SL);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(13.1F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place a delivery stop-loss order market
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_EQ|INE669E01016",
"order_type": "SL-M",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 15,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'D',
'validity': 'DAY',
'price': 0,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE669E01016',
'order_type': 'SL-M',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 15,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'D',
validity: 'DAY',
price: 0.0,
tag: 'string',
instrument_token: 'NSE_EQ|INE669E01016',
order_type: 'SL-M',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 15,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0.0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"order_type\": \"SL-M\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 15,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'D',
'validity' => 'DAY',
'price' => 0.0,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE669E01016',
'order_type' => 'SL-M',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 15,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 0.0, "string", "NSE_EQ|INE528G01035", "SL-M", "BUY", 0, 21.5, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.D, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 0.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.SL_M,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 24.5, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.D);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(0F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE669E01016");
body.orderType(PlaceOrderRequest.OrderTypeEnum.SL_M);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(15.1F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place an intraday market order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "I",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_EQ|INE528G01035",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'I',
'validity': 'DAY',
'price': 0,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE528G01035',
'order_type': 'MARKET',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 0,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'I',
validity: 'DAY',
price: 0.0,
tag: 'string',
instrument_token: 'NSE_EQ|INE528G01035',
order_type: 'MARKET',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 0,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"I\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0.0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE528G01035\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'I',
'validity' => 'DAY',
'price' => 0.0,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE528G01035',
'order_type' => 'MARKET',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 0,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "I", "DAY", 0.0, "string", "NSE_EQ|INE528G01035", "MARKET", "BUY", 0, 0.0, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.I, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 0.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.MARKET,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 0.0, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.I);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(0F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE528G01035");
body.orderType(PlaceOrderRequest.OrderTypeEnum.MARKET);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(0F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place an intraday limit order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "I",
"validity": "DAY",
"price": 20.0,
"tag": "string",
"instrument_token": "NSE_EQ|INE528G01035",
"order_type": "LIMIT",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 20.1,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'I',
'validity': 'DAY',
'price': 20.0,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE528G01035',
'order_type': 'LIMIT',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 20.1,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'I',
validity: 'DAY',
price: 20.0,
tag: 'string',
instrument_token: 'NSE_EQ|INE528G01035',
order_type: 'LIMIT',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 20.1,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"I\","
+ "\"validity\": \"DAY\","
+ "\"price\": 20.0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE528G01035\","
+ "\"order_type\": \"LIMIT\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 20.1,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'I',
'validity' => 'DAY',
'price' => 20.0,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE528G01035',
'order_type' => 'LIMIT',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 20.1,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "I", "DAY", 20.0, "string", "NSE_EQ|INE528G01035", "LIMIT", "BUY", 0, 20.1, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.I, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 20.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.LIMIT,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 20.1, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.I);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(24F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE528G01035");
body.orderType(PlaceOrderRequest.OrderTypeEnum.LIMIT);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(24.1F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place an intraday stop-loss order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "I",
"validity": "DAY",
"price": 20.0,
"tag": "string",
"instrument_token": "NSE_EQ|INE528G01035",
"order_type": "SL",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 19.5,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'I',
'validity': 'DAY',
'price': 20.0,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE528G01035',
'order_type': 'SL',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 19.5,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'I',
validity: 'DAY',
price: 20.0,
tag: 'string',
instrument_token: 'NSE_EQ|INE528G01035',
order_type: 'SL',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 19.5,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"I\","
+ "\"validity\": \"DAY\","
+ "\"price\": 20.0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE528G01035\","
+ "\"order_type\": \"SL\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 19.5,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'I',
'validity' => 'DAY',
'price' => 20.0,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE528G01035',
'order_type' => 'SL',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 19.5,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "I", "DAY", 20, "string", "NSE_EQ|INE528G01035", "SL", "BUY", 0, 19.5, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.I, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 20.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.SL,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 19.5, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.I);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(24F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE528G01035");
body.orderType(PlaceOrderRequest.OrderTypeEnum.SL);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(23F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place an intraday stop-loss market order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "I",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_EQ|INE528G01035",
"order_type": "SL-M",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 21.5,
"is_amo": false
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'I',
'validity': 'DAY',
'price': 0.0,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE528G01035',
'order_type': 'SL-M',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 21.5,
'is_amo': False,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'I',
validity: 'DAY',
price: 0.0,
tag: 'string',
instrument_token: 'NSE_EQ|INE528G01035',
order_type: 'SL-M',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 21.5,
is_amo: false,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"I\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0.0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE528G01035\","
+ "\"order_type\": \"SL-M\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 21.5,"
+ "\"is_amo\": false"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'I',
'validity' => 'DAY',
'price' => 0.0,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE528G01035',
'order_type' => 'SL-M',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 21.5,
'is_amo' => false,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "I", "DAY", 0.0, "string", "NSE_EQ|INE528G01035", "SL-M", "BUY", 0, 21.5, False)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.I, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 0.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.SL_M,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 24.5, false);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.I);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(0F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE528G01035");
body.orderType(PlaceOrderRequest.OrderTypeEnum.SL_M);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(25F);
body.setIsAmo(false);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Place a delivery market amo (after market order)
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api-hft.upstox.com/v2/order/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"quantity": 1,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_EQ|INE669E01016",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": true
}'
import requests
url = 'https://api-hft.upstox.com/v2/order/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
'quantity': 1,
'product': 'D',
'validity': 'DAY',
'price': 0,
'tag': 'string',
'instrument_token': 'NSE_EQ|INE669E01016',
'order_type': 'MARKET',
'transaction_type': 'BUY',
'disclosed_quantity': 0,
'trigger_price': 0,
'is_amo': True,
}
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-hft.upstox.com/v2/order/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = {
quantity: 1,
product: 'D',
validity: 'DAY',
price: 0,
tag: 'string',
instrument_token: 'NSE_EQ|INE669E01016',
order_type: 'MARKET',
transaction_type: 'BUY',
disclosed_quantity: 0,
trigger_price: 0,
is_amo: true,
};
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-hft.upstox.com/v2/order/place";
String token = "Bearer {your_access_token}";
// Set up the request body
String requestBody = "{"
+ "\"quantity\": 1,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_EQ|INE669E01016\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": true"
+ "}";
// 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-hft.upstox.com/v2/order/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 1,
'product' => 'D',
'validity' => 'DAY',
'price' => 0,
'tag' => 'string',
'instrument_token' => 'NSE_EQ|INE669E01016',
'order_type' => 'MARKET',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 0,
'is_amo' => true,
];
$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.OrderApi(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 0.0, "string", "NSE_EQ|INE528G01035", "MARKET", "BUY", 0, 0.0, True)
api_version = '2.0'
try:
api_response = api_instance.place_order(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->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.OrderApi();
let body = new UpstoxClient.PlaceOrderRequest(1, UpstoxClient.PlaceOrderRequest.ProductEnum.D, UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY, 0.0, "NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderRequest.OrderTypeEnum.MARKET,UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY, 0, 0.0, true);
let apiVersion = "2.0";
apiInstance.placeOrder(body, apiVersion, (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.PlaceOrderRequest;
import com.upstox.api.PlaceOrderResponse;
import com.upstox.auth.*;
import io.swagger.client.api.OrderApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
OrderApi apiInstance = new OrderApi();
PlaceOrderRequest body = new PlaceOrderRequest();
body.setQuantity(1);
body.setProduct(PlaceOrderRequest.ProductEnum.D);
body.setValidity(PlaceOrderRequest.ValidityEnum.DAY);
body.setPrice(0F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE669E01016");
body.orderType(PlaceOrderRequest.OrderTypeEnum.MARKET);
body.setTransactionType(PlaceOrderRequest.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(0F);
body.setIsAmo(true);
String apiVersion = "2.0"; // String | API Version Header
try {
PlaceOrderResponse result = apiInstance.placeOrder(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Loading...