Get Trades
API to retrieve the list of all trades executed for the day. An order, initially submitted as one entity, can be executed in smaller segments based on market situation. Each of these partial executions constitutes a trade, and a single order may consist of several such trades.
Request
curl --location 'https://api.upstox.com/v2/order/trades/get-trades-for-day' \
--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
{
"status": "success",
"data": [
{
"exchange": "NSE",
"product": "D",
"trading_symbol": "GMRINFRA-EQ",
"tradingsymbol": "GMRINFRA-EQ",
"instrument_token": "151064324",
"order_type": "MARKET",
"transaction_type": "BUY",
"quantity": 1,
"exchange_order_id": "221013001021540",
"order_id": "221013001021539",
"exchange_timestamp": "03-Aug-2017 15:03:42",
"average_price": 299.4,
"trade_id": "50091502",
"order_ref_id": "udapi-aqwsed14356",
"order_timestamp": "23-Apr-2021 14:22:06"
}
]
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object[] | Response data for trades |
| 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[].trading_symbol | string | Shows the trading symbol which could be a combination of symbol name, instrument, expiry date etc |
| data[].instrument_token | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| 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[].transaction_type | string | Indicates whether its a buy or sell order. Possible values: BUY, SELL. |
| data[].quantity | int32 | The total quantity traded from this particular order |
| data[].exchange_order_id | string | Unique order ID assigned by the exchange for the order placed |
| data[].order_id | string | Unique order ID assigned internally for the order placed |
| data[].exchange_timestamp | string | User readable time at when the trade occurred |
| data[].average_price | float | Price at which the traded quantity is traded |
| data[].trade_id | string | Trade ID generated from exchange towards traded transaction |
| data[].order_ref_id | string | Uniquely identifies an order for internal usage. |
| data[].order_timestamp | string | User readable timestamp at which the order was placed |
Sample Code
Get all trades for the day
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
import requests
url = 'https://api.upstox.com/v2/order/trades/get-trades-for-day'
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/trades/get-trades-for-day';
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/trades/get-trades-for-day";
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/trades/get-trades-for-day';
$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 trades
api_response = api_instance.get_trade_history(api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->get_trade_history: %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.getTradeHistory(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.GetTradeResponse;
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 {
GetTradeResponse result = apiInstance.getTradeHistory(apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#getTradeHistory");
e.printStackTrace();
}
}
}
Loading...