Get Order Book
API to retrieve the list of a orders placed for the current day. Orders initiated by the user remain active for a single day and are automatically cleared at the conclusion of the trading session. The reply indicates the most current status of the order. For a comprehensive list of all possible order statuses, please refer to the appendix on order status.
Request
curl --location 'https://api.upstox.com/v2/order/retrieve-all' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
For additional samples in various languages, please refer to the Sample code section on this page.
Responses
- 200
Response Body
[
{
"exchange": "BSE",
"product": "D",
"price": 0.8,
"quantity": 1,
"status": "complete",
"guid": null,
"tag": null,
"instrument_token": "BSE_EQ|INE220J01025",
"placed_by": "*****",
"trading_symbol": "FCONSUMER",
"tradingsymbol": "FCONSUMER",
"order_type": "LIMIT",
"validity": "DAY",
"trigger_price": 0,
"disclosed_quantity": 0,
"transaction_type": "BUY",
"average_price": 0.8,
"filled_quantity": 1,
"pending_quantity": 0,
"status_message": null,
"status_message_raw": null,
"exchange_order_id": "1697686200000169148",
"parent_order_id": null,
"order_id": "231019025057849",
"variety": "SIMPLE",
"order_timestamp": "2023-10-19 09:23:23",
"exchange_timestamp": "2023-10-19 09:23:23",
"is_amo": false,
"order_request_id": "2",
"order_ref_id": "57744821658411"
},
{
"exchange": "NFO",
"product": "I",
"price": 0,
"quantity": 1500,
"status": "rejected",
"guid": null,
"tag": null,
"instrument_token": "NSE_FO|52567",
"placed_by": "******",
"trading_symbol": "SBIN23OCTFUT",
"tradingsymbol": "SBIN23OCTFUT",
"order_type": "SL-M",
"validity": "DAY",
"trigger_price": 570,
"disclosed_quantity": 0,
"transaction_type": "SELL",
"average_price": 0,
"filled_quantity": 0,
"pending_quantity": 0,
"status_message": "You need to add Rs. 138385.27 in your account to place this trade.",
"status_message_raw": "RMS:Margin Exceeds,Required:153892.45, Available:15507.18 for entity account-****** across exchange across segment across product ",
"exchange_order_id": "",
"parent_order_id": null,
"order_id": "231019025000398",
"variety": "SIMPLE",
"order_timestamp": "2023-10-19 09:15:00",
"exchange_timestamp": null,
"is_amo": false,
"order_request_id": "1",
"order_ref_id": "33832759664502"
},
{
"exchange": "BFO",
"product": "D",
"price": 0.05,
"quantity": 10,
"status": "cancelled",
"guid": null,
"tag": null,
"instrument_token": "BSE_FO|822663",
"placed_by": "******",
"trading_symbol": "SENSEX23O2066000PE",
"tradingsymbol": "SENSEX23O2066000PE",
"order_type": "LIMIT",
"validity": "DAY",
"trigger_price": 0,
"disclosed_quantity": 0,
"transaction_type": "BUY",
"average_price": 0,
"filled_quantity": 0,
"pending_quantity": 10,
"status_message": null,
"status_message_raw": null,
"exchange_order_id": "1697687100012002451",
"parent_order_id": null,
"order_id": "231019025000428",
"variety": "SIMPLE",
"order_timestamp": "2023-10-19 09:30:53",
"exchange_timestamp": "2023-10-19 09:30:53",
"is_amo": false,
"order_request_id": "1",
"order_ref_id": "1168356875930923"
}
]
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Response data for order Book |
| data[].exchange | string | Exchange to which the order is associated. Valid exchanges can be found in the Exchange Appendix |
| data[].product | string | Signifies if the order was either Intraday, Delivery or CO. Possible values: I, D, CO, MTF. |
| data[].price | float | Price at which the order was placed |
| data[].quantity | int32 | Quantity with which the order was placed |
| data[].status | string | Indicates the current status of the order. Valid order statuses can be found in the Order Status Appendix |
| data[].tag | string | Tag to uniquely identify an order |
| data[].instrument_token | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| data[].placed_by | string | Uniquely identifies the user (commonly referred as UCC) |
| data[].trading_symbol | string | Shows the trading symbol of the instrument |
| data[].order_type | 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. |
| data[].validity | string | It can be one of the following - DAY(default), IOC. Possible values: DAY, IOC. |
| data[].trigger_price | float | If the order was a stop loss order then the trigger price set is mentioned here |
| data[].disclosed_quantity | int32 | The quantity that should be disclosed in the market depth |
| data[].transaction_type | string | Indicates whether its a buy or sell order. Possible values: BUY, SELL. |
| data[].average_price | float | Average price at which the qty got traded |
| data[].filled_quantity | int32 | The total quantity traded from this particular order |
| data[].pending_quantity | int32 | Pending quantity to be filled |
| data[].status_message | string | Indicates the reason when any order is rejected, not modified or cancelled |
| data[].status_message_raw | string | Description of the order's status as received from RMS |
| data[].exchange_order_id | string | Unique order ID assigned by the exchange for the order placed |
| data[].parent_order_id | string | In case the order is part of the second of a CO, the parent order ID is indicated here |
| data[].order_id | string | Unique order ID assigned internally for the order placed |
| data[].variety | string | Order complexity |
| data[].order_timestamp | string | User readable timestamp at which the order was placed |
| data[].exchange_timestamp | string | User readable time at which the order was placed or updated |
| data[].is_amo | boolean | Signifies if the order is an After Market Order |
| data[].order_request_id | string | Apart from 1st order it shows the count of how many requests were sent |
| data[].order_ref_id | string | Uniquely identifies an order for internal usage. |
Sample Code
Get all orders for the day
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
import requests
url = 'https://api.upstox.com/v2/order/retrieve-all'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
print(response.text)
const axios = require('axios');
const url = 'https://api.upstox.com/v2/order/retrieve-all';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
axios.get(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error.response.data));
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.upstox.com/v2/order/retrieve-all";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// Set request headers
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Authorization", "Bearer {your_access_token}");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}
}
<?php
$url = 'https://api.upstox.com/v2/order/retrieve-all';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
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))
api_version = '2.0'
try:
# Get order book
api_response = api_instance.get_order_book(api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->get_order_book: %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 apiVersion = "2.0";
apiInstance.getOrderBook(apiVersion, (error, data, response) => {
if (error) {
console.error(error);
} 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.GetOrderBookResponse;
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();
String apiVersion = "2.0"; // String | API Version Header
try {
GetOrderBookResponse result = apiInstance.getOrderBook(apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
Loading...