Place Multi Order Sandbox Enabled
This API extends the functionality of the Place Order API, allowing multiple orders to be placed simultaneously on the exchange. Each order in the request must include a unique correlation_id for individual tracking. Each successful order will return a unique order_id for further management such as modifications or cancellations.
A maximum of 25 orders can be placed in a single request. Any request exceeding this limit will be rejected.
The Multi Order API is subject to a different rate limit compared to the standard limits applied across the system. For more information on the rate limits for this API, please check here.
Request
curl --location 'https://api.upstox.com/v2/order/multi/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '[
{
"correlation_id": "1",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
},
{
"correlation_id": "2",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
}
]'
For additional samples in various languages, please refer to the Sample code section on this page.
Request Body
| Name | Required | Type | Description |
|---|---|---|---|
| correlation_id | true | string | Uniquely identifies each order line within the request. It must be unique per line and is echoed in responses for easy tracking of related errors or feedback. The correlation_id must not exceed 20 characters in length.Note: The correlation_id is scoped only to this request and cannot be used in another API to refer to this order line. |
| slice | false | boolean | When true, the number of orders is calculated based on the freeze quantity assigned for the instrument by the exchange. This helps automatically split the order into smaller parts in accordance with exchange rules, preventing rejection due to exceeding the allowed quantity. The default value is false. For a detailed explanation, please check the Auto Slicing section. |
| tag | false | string | This field functions the same as in the Place Order API, but with a size restriction of 40 characters. |
For all other fields, please refer to the Place Order API documentation as all fields are the same as those used when placing an order using the Place Order API.
Order Execution Sequence
In a multi-order request, the system will execute all BUY orders first, followed by the execution of all SELL orders. This ensures a consistent and orderly processing of multiple order types within the same request.
Maximum Order Limit
When slicing is applied, we calculate the total number of resulting orders. The total number of orders in a request, including those generated by the slice, must not exceed the maximum order count specified here.
- 2XX
- 4XX
Response Body
- Success (200)
- Partial Success (207)
{
"status": "success",
"data": [
{
"correlation_id": "1",
"order_id": "1644490272000"
},
{
"correlation_id": "2",
"order_id": "2134134141414"
}
],
"summary": {
"total": 2,
"payload_error": 0,
"success": 2,
"error": 0
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Possible values: success, partial_success, error.success - when all order lines were placed partial_success - when some order lines encountered errors error - when all order lines encountered errors or there were issues with one or more of the payloads. |
| data | object | Response data for place order request |
| data.correlation_id | string | Mirrors the unique identifier provided for each order line in the request, facilitating easy tracking and correlation of responses with their respective orders. |
| data.order_id | string | An order ID for the order request placed |
| summary | object | A summary of the outcomes for the batch of orders processed, detailing total orders, valid submissions, successful completions, and errors. |
| summary.total | integer | The total number of order lines present in the payload. |
| summary.payload_error | integer | The number of order lines with payload errors, indicating formatting or data validity issues. Note: Orders are processed only if the entire batch is free of payload_error, ensuring error-free transactions. |
| summary.success | integer | The number of order lines that were successfully placed without any errors. |
| summary.error | integer | The number of order lines that encountered errors during processing, despite their payloads being valid. |
{
"status": "partial_success",
"data": [
{
"correlation_id": "1",
"order_id": "1644490272000"
}
],
"errors": [
{
"correlation_id": "2",
"error_code": "UDAPI100500",
"message": "Something went wrong... please contact us",
"property_path": null,
"invalid_value": null
}
],
"summary": {
"total": 2,
"payload_error": 0,
"success": 1,
"error": 1
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Possible values: success, partial_success, error. success when all order lines were placed, partial_success when some order lines encountered errors, and error when all order lines encountered errors or there were issues with one or more of the payloads. |
| data | object | Response data for place order request |
| data.correlation_id | string | Mirrors the unique identifier provided for each order line in the request, facilitating easy tracking and correlation of responses with their respective orders. |
| data.order_id | string | An order ID for the order request placed |
| errors | object | Array of errors including every order line that encountered an issue. For more details, refer to the Error Response documentation. |
| errors.correlation_id | string | Reflects the unique identifier provided for each order line in the request, aiding in tracking errors associated with specific orders. |
| summary | object | A summary of the outcomes for the batch of orders processed, detailing total orders, valid submissions, successful completions, and errors. |
| summary.total | integer | The total number of order lines present in the payload. |
| summary.payload_error | integer | The number of order lines with payload errors, indicating formatting or data validity issues. Note: Orders are processed only if the entire batch is free of payload_error, ensuring error-free transactions. |
| summary.success | integer | The number of order lines that were successfully placed without any errors. |
| summary.error | integer | The number of order lines that encountered errors during processing, despite their payloads being valid. |
{
"status": "error",
"errors": [
{
"correlation_id": "1",
"error_code": "UDAPI1054",
"message": "The 'product' is invalid",
"property_path": null,
"invalid_value": null
},
{
"correlation_id": "2",
"error_code": "UDAPI1040",
"message": "Price not required",
"property_path": null,
"invalid_value": null
}
],
"summary": {
"total": 5,
"payload_error": 2,
"success": 0,
"error": 0
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Possible values: success, partial_success, error. success when all order lines were placed, partial_success when some order lines encountered errors, and error when all order lines encountered errors or there were issues with one or more of the payloads. |
| data | object | Response data for place order request |
| data.correlation_id | string | Mirrors the unique identifier provided for each order line in the request, facilitating easy tracking and correlation of responses with their respective orders. |
| data.order_id | string | An order ID for the order request placed |
| errors | object | Array of errors including every order line that encountered an issue. For more details, refer to the Error Response documentation. |
| errors.correlation_id | string | Reflects the unique identifier provided for each order line in the request, aiding in tracking errors associated with specific orders. |
| summary | object | A summary of the outcomes for the batch of orders processed, detailing total orders, valid submissions, successful completions, and errors. |
| summary.total | integer | The total number of order lines present in the payload. |
| summary.payload_error | integer | The number of order lines with payload errors, indicating formatting or data validity issues. Note: Orders are processed only if the entire batch is free of payload_error, ensuring error-free transactions. |
| summary.success | integer | The number of order lines that were successfully placed without any errors. |
| summary.error | integer | The number of order lines that encountered errors during processing, despite their payloads being valid. |
Error Codes
| Error Code | Description |
|---|---|
| UDAPI1114 | Request payload should have at least one order line - The request must include at least one valid order line. An empty request is not allowed and will result in a rejection. |
| UDAPI1115 | Missing correlation_id - One or more order lines in the payload are missing the required correlation_id. This field is necessary for tracking and identifying individual order lines. |
| UDAPI1116 | Invalid correlation_id: Length must be between 1 and 20 characters. - The length of the correlation_id exceeds the permitted limit of 20 characters. Ensure each correlation_id is within the defined limit. |
| UDAPI1117 | Duplicate correlation_id found - Each order line must have a unique correlation_id. Duplicate correlation IDs will cause the entire request to be rejected. |
| UDAPI1118 | Maximum order limit exceeded - The number of orders in this request exceeds the maximum allowed count. Requests with more than the permissible limit of orders will be rejected immediately. |
| UDAPI1119 | tag length exceeds limit - The length of the tag exceeds the permitted limit of 40 characters. Ensure each tag is within the defined limit. |
Please refer to the error codes listed in the Place Order API as they are also applicable here.
Auto Slicing
Exchanges enforce a limitation on the maximum quantity that can be placed for any scrip, known as the freeze quantity. If an order exceeds this freeze quantity, it will be rejected by the exchange. To simplify the process and prevent such rejections, we automatically slice the order into smaller parts based on the freeze quantity defined by the exchange when necessary.
How to Enable Slicing
To enable this feature, include the slice field in your request payload with the value set to true. Let's walk through a practical example:
Suppose you want to place an order for SCRIP1 with a total quantity of 10,100, and the freeze quantity defined by the exchange is 1,000. If you send the slice field as false, the entire order is submitted to the exchange, which will reject it due to exceeding the allowed quantity. However, if you pass true as the value for the slice field, we automatically split the order into 11 smaller orders: 10 orders of 1,000 units each, and 1 order of 100 units. This ensures that all orders are accepted and processed by the exchange.
Correlation ID for Split Orders
In the case of a sliced order, the correlation_id will be returned with a suffix to uniquely identify each split order. For the use case defined above, if the correlation_id in the request was orderline25, the split orders will be returned with correlation_id values as orderline25_1, orderline25_2, and so on, up to orderline25_11. This allows for easy tracking and management of the split orders in subsequent operations or error handling.
Sample Code
Place a multi order
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/order/multi/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '[
{
"correlation_id": "1",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
},
{
"correlation_id": "2",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
}
]'
'
import requests
url = 'https://api.upstox.com/v2/order/multi/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = [
{
"correlation_id": "1",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": False,
"slice": False
},
{
"correlation_id": "2",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": False,
"slice": 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.upstox.com/v2/order/multi/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = [
{
"correlation_id": "1",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
},
{
"correlation_id": "2",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
}
];
axios.post(url, data, { headers })
.then(response => {
console.log('Response Code:', response.status);
console.log('Response Body:', 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/v2/order/multi/place";
String token = "Bearer {your_access_token}";
// Set up the request body with multiple orders
String requestBody = "["
+ "{"
+ "\"correlation_id\": \"1\","
+ "\"quantity\": 25,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_FO|62864\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false,"
+ "\"slice\": false"
+ "},"
+ "{"
+ "\"correlation_id\": \"2\","
+ "\"quantity\": 25,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_FO|62867\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false,"
+ "\"slice\": 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.upstox.com/v2/order/multi/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
// Set up the request body with multiple orders
$data = [
[
"correlation_id" => "1",
"quantity" => 25,
"product" => "D",
"validity" => "DAY",
"price" => 0,
"tag" => "string",
"instrument_token" => "NSE_FO|62864",
"order_type" => "MARKET",
"transaction_type" => "BUY",
"disclosed_quantity" => 0,
"trigger_price" => 0,
"is_amo" => false,
"slice" => false
],
[
"correlation_id" => "2",
"quantity" => 25,
"product" => "D",
"validity" => "DAY",
"price" => 0,
"tag" => "string",
"instrument_token" => "NSE_FO|62867",
"order_type" => "MARKET",
"transaction_type" => "BUY",
"disclosed_quantity" => 0,
"trigger_price" => 0,
"is_amo" => false,
"slice" => 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.MultiOrderRequest(25, "D", "DAY", 0, "string", False, "NSE_FO|44166", "MARKET", "BUY",
0, 0, True, "1")
]
try:
api_response = api_instance.place_multi_order(body)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->place_order: %s\n" % e.body)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
apiInstance = new UpstoxClient.OrderApi();
body = []
order = new UpstoxClient.MultiOrderRequest(25,"D","DAY",0,false,"NSE_FO|44166","MARKET","BUY",0,0,true,"1");
order.tag = "string"; //optional parameter tag
body = body.concat(order);
apiInstance.placeMultiOrder(body, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.MultiOrderRequest;
import com.upstox.api.MultiOrderResponse;
import com.upstox.auth.OAuth;
import io.swagger.client.api.OrderApi;
import java.util.ArrayList;
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();
MultiOrderRequest orderRequest = new MultiOrderRequest();
orderRequest.setQuantity(25);
orderRequest.setProduct(MultiOrderRequest.ProductEnum.D);
orderRequest.setValidity(MultiOrderRequest.ValidityEnum.DAY);
orderRequest.setPrice(0F);
orderRequest.setTag("string");
orderRequest.setInstrumentToken("NSE_FO|44166");
orderRequest.orderType(MultiOrderRequest.OrderTypeEnum.MARKET);
orderRequest.setTransactionType(MultiOrderRequest.TransactionTypeEnum.BUY);
orderRequest.setDisclosedQuantity(0);
orderRequest.setTriggerPrice(0F);
orderRequest.setIsAmo(true);
orderRequest.setCorrelationId("1");
orderRequest.setSlice(false);
try {
ArrayList<MultiOrderRequest> list = new ArrayList<>();
list.add(orderRequest);
MultiOrderResponse result = apiInstance.placeMultiOrder(list);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#MultiOrder= " + e.getResponseBody());
e.printStackTrace();
}
}
}
Place Multiple BUY and SELL Orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/order/multi/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '[
{
"correlation_id": "1",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
},
{
"correlation_id": "2",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "SELL",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
}
]'
'
import requests
url = 'https://api.upstox.com/v2/order/multi/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = [
{
"correlation_id": "1",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": False,
"slice": False
},
{
"correlation_id": "2",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "SELL",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": False,
"slice": 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.upstox.com/v2/order/multi/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = [
{
"correlation_id": "1",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
},
{
"correlation_id": "2",
"quantity": 25,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "SELL",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": false
}
];
axios.post(url, data, { headers })
.then(response => {
console.log('Response Code:', response.status);
console.log('Response Body:', 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/v2/order/multi/place";
String token = "Bearer {your_access_token}";
// Set up the request body with multiple orders
String requestBody = "["
+ "{"
+ "\"correlation_id\": \"1\","
+ "\"quantity\": 25,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_FO|62864\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false,"
+ "\"slice\": false"
+ "},"
+ "{"
+ "\"correlation_id\": \"2\","
+ "\"quantity\": 25,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_FO|62867\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"SELL\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false,"
+ "\"slice\": 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.upstox.com/v2/order/multi/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
// Set up the request body with multiple orders
$data = [
[
"correlation_id" => "1",
"quantity" => 25,
"product" => "D",
"validity" => "DAY",
"price" => 0,
"tag" => "string",
"instrument_token" => "NSE_FO|62864",
"order_type" => "MARKET",
"transaction_type" => "BUY",
"disclosed_quantity" => 0,
"trigger_price" => 0,
"is_amo" => false,
"slice" => false
],
[
"correlation_id" => "2",
"quantity" => 25,
"product" => "D",
"validity" => "DAY",
"price" => 0,
"tag" => "string",
"instrument_token" => "NSE_FO|62867",
"order_type" => "MARKET",
"transaction_type" => "SELL",
"disclosed_quantity" => 0,
"trigger_price" => 0,
"is_amo" => false,
"slice" => 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.MultiOrderRequest(25, "D", "DAY", 0, "string", False, "NSE_FO|44166", "MARKET", "BUY",
0, 0, True, "1"),
upstox_client.MultiOrderRequest(25, "D", "DAY", 0, "string", False, "NSE_FO|44122", "MARKET", "SELL",
0, 0, True, "2")
]
try:
api_response = api_instance.place_multi_order(body)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->place_order: %s\n" % e.body)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
apiInstance = new UpstoxClient.OrderApi();
body = []
buyRequest = new UpstoxClient.MultiOrderRequest(25,"D","DAY",0,false,"NSE_FO|44166","MARKET","BUY",0,0,true,"1");
buyRequest.tag = "string";
sellRequest = new UpstoxClient.MultiOrderRequest(25,"D","DAY",0,false,"NSE_FO|44122","MARKET","SELL",0,0,true,"2");
sellRequest.tag = "string";
body = body.concat(buyRequest, sellRequest);
apiInstance.placeMultiOrder(body, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.MultiOrderRequest;
import com.upstox.api.MultiOrderResponse;
import com.upstox.auth.OAuth;
import io.swagger.client.api.OrderApi;
import java.util.List;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
MultiOrderRequest buyOrderRequest = new MultiOrderRequest();
buyOrderRequest.setQuantity(25);
buyOrderRequest.setProduct(MultiOrderRequest.ProductEnum.D);
buyOrderRequest.setValidity(MultiOrderRequest.ValidityEnum.DAY);
buyOrderRequest.setPrice(0F);
buyOrderRequest.setTag("string");
buyOrderRequest.setInstrumentToken("NSE_FO|44166");
buyOrderRequest.orderType(MultiOrderRequest.OrderTypeEnum.MARKET);
buyOrderRequest.setTransactionType(MultiOrderRequest.TransactionTypeEnum.BUY);
buyOrderRequest.setDisclosedQuantity(0);
buyOrderRequest.setTriggerPrice(0F);
buyOrderRequest.setIsAmo(true);
buyOrderRequest.setCorrelationId("1");
buyOrderRequest.setSlice(false);
MultiOrderRequest sellOrderRequest = new MultiOrderRequest();
sellOrderRequest.setQuantity(25);
sellOrderRequest.setProduct(MultiOrderRequest.ProductEnum.D);
sellOrderRequest.setValidity(MultiOrderRequest.ValidityEnum.DAY);
sellOrderRequest.setPrice(0F);
sellOrderRequest.setTag("string");
sellOrderRequest.setInstrumentToken("NSE_FO|44122");
sellOrderRequest.orderType(MultiOrderRequest.OrderTypeEnum.MARKET);
sellOrderRequest.setTransactionType(MultiOrderRequest.TransactionTypeEnum.SELL);
sellOrderRequest.setDisclosedQuantity(0);
sellOrderRequest.setTriggerPrice(0F);
sellOrderRequest.setIsAmo(true);
sellOrderRequest.setCorrelationId("2");
sellOrderRequest.setSlice(false);
try {
List<MultiOrderRequest> list = List.of(buyOrderRequest, sellOrderRequest);
MultiOrderResponse result = apiInstance.placeMultiOrder(list);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#MultiOrder= " + e.getResponseBody());
e.printStackTrace();
}
}
}
Place Multiple Orders with Auto Slicing enabled
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/order/multi/place' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '[
{
"correlation_id": "1",
"quantity": 2500000,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": true
},
{
"correlation_id": "2",
"quantity": 2500000,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "SELL",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": true
}
]'
'
import requests
url = 'https://api.upstox.com/v2/order/multi/place'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = [
{
"correlation_id": "1",
"quantity": 2500000,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": False,
"slice": True
},
{
"correlation_id": "2",
"quantity": 2500000,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "SELL",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": False,
"slice": 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.upstox.com/v2/order/multi/place';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const data = [
{
"correlation_id": "1",
"quantity": 2500000,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62864",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": true
},
{
"correlation_id": "2",
"quantity": 2500000,
"product": "D",
"validity": "DAY",
"price": 0,
"tag": "string",
"instrument_token": "NSE_FO|62867",
"order_type": "MARKET",
"transaction_type": "SELL",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": false,
"slice": true
}
];
axios.post(url, data, { headers })
.then(response => {
console.log('Response Code:', response.status);
console.log('Response Body:', 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/v2/order/multi/place";
String token = "Bearer {your_access_token}";
// Set up the request body with multiple orders
String requestBody = "["
+ "{"
+ "\"correlation_id\": \"1\","
+ "\"quantity\": 2500000,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_FO|62864\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"BUY\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false,"
+ "\"slice\": true"
+ "},"
+ "{"
+ "\"correlation_id\": \"2\","
+ "\"quantity\": 2500000,"
+ "\"product\": \"D\","
+ "\"validity\": \"DAY\","
+ "\"price\": 0,"
+ "\"tag\": \"string\","
+ "\"instrument_token\": \"NSE_FO|62867\","
+ "\"order_type\": \"MARKET\","
+ "\"transaction_type\": \"SELL\","
+ "\"disclosed_quantity\": 0,"
+ "\"trigger_price\": 0,"
+ "\"is_amo\": false,"
+ "\"slice\": 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.upstox.com/v2/order/multi/place';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
// Set up the request body with multiple orders
$data = [
[
"correlation_id" => "1",
"quantity" => 2500000,
"product" => "D",
"validity" => "DAY",
"price" => 0,
"tag" => "string",
"instrument_token" => "NSE_FO|62864",
"order_type" => "MARKET",
"transaction_type" => "BUY",
"disclosed_quantity" => 0,
"trigger_price" => 0,
"is_amo" => false,
"slice" => true
],
[
"correlation_id" => "2",
"quantity" => 2500000,
"product" => "D",
"validity" => "DAY",
"price" => 0,
"tag" => "string",
"instrument_token" => "NSE_FO|62867",
"order_type" => "MARKET",
"transaction_type" => "SELL",
"disclosed_quantity" => 0,
"trigger_price" => 0,
"is_amo" => false,
"slice" => 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.MultiOrderRequest(25, "D", "DAY", 0, "string", True, "NSE_FO|44166", "MARKET", "BUY",
0, 0, True, "1")
]
try:
api_response = api_instance.place_multi_order(body)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->place_order: %s\n" % e.body)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
apiInstance = new UpstoxClient.OrderApi();
body = []
order = new UpstoxClient.MultiOrderRequest(25,"D","DAY",0,true,"NSE_FO|44166","MARKET","BUY",0,0,true,"1");
order.tag = "string"; //optional parameter tag
body = body.concat(order);
apiInstance.placeMultiOrder(body, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.MultiOrderRequest;
import com.upstox.api.MultiOrderResponse;
import com.upstox.auth.OAuth;
import io.swagger.client.api.OrderApi;
import java.util.ArrayList;
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();
MultiOrderRequest orderRequest = new MultiOrderRequest();
orderRequest.setQuantity(25);
orderRequest.setProduct(MultiOrderRequest.ProductEnum.D);
orderRequest.setValidity(MultiOrderRequest.ValidityEnum.DAY);
orderRequest.setPrice(0F);
orderRequest.setTag("string");
orderRequest.setInstrumentToken("NSE_FO|44166");
orderRequest.orderType(MultiOrderRequest.OrderTypeEnum.MARKET);
orderRequest.setTransactionType(MultiOrderRequest.TransactionTypeEnum.BUY);
orderRequest.setDisclosedQuantity(0);
orderRequest.setTriggerPrice(0F);
orderRequest.setIsAmo(true);
orderRequest.setCorrelationId("1");
orderRequest.setSlice(true);
try {
ArrayList<MultiOrderRequest> list = new ArrayList<>();
list.add(orderRequest);
MultiOrderResponse result = apiInstance.placeMultiOrder(list);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#MultiOrder= " + e.getResponseBody());
e.printStackTrace();
}
}
}