Get Holdings
API to retrieve the long term holdings of the user. A Holding within a holdings portfolio remains in place without a predetermined time limit. It can only be withdrawn when it is divested, delisted, or subject to modifications dictated by the stock exchanges. In essence, the instruments housed in the portfolio are securely located within the user's DEMAT account, in strict compliance with the regulations.
Request
curl --location 'https://api.upstox.com/v2/portfolio/long-term-holdings' \
--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": [
{
"isin": "INE528G01035",
"cnc_used_quantity": 0,
"collateral_type": "WC",
"company_name": "YES BANK LTD.",
"haircut": 0.2,
"product": "D",
"quantity": 36,
"trading_symbol": "YESBANK",
"tradingsymbol": "YESBANK",
"last_price": 17.05,
"close_price": 17.05,
"pnl": -61.2,
"day_change": 0,
"day_change_percentage": 0,
"instrument_token": "NSE_EQ|INE528G01035",
"average_price": 18.75,
"collateral_quantity": 0,
"collateral_update_quantity": 0,
"t1_quantity": 0,
"exchange": "NSE"
},
{
"isin": "INE036A01016",
"cnc_used_quantity": 0,
"collateral_type": "WC",
"company_name": "RELIANCE INFRASTRUCTURE LTD.",
"haircut": 1,
"product": "D",
"quantity": 1,
"trading_symbol": "RELINFRA",
"tradingsymbol": "RELINFRA",
"last_price": 174.85,
"close_price": 169.2,
"pnl": -17.7,
"day_change": 0,
"day_change_percentage": 0,
"instrument_token": "NSE_EQ|INE036A01016",
"average_price": 192.55,
"collateral_quantity": 0,
"collateral_update_quantity": 0,
"t1_quantity": 0,
"exchange": "NSE"
}
]
}
Name | Type | Description |
---|---|---|
status | string | A string indicating the outcome of the request. Typically success for successful operations. |
data | object[] | Response data for holdings |
data[].isin | string | The standard ISIN representing stocks listed on multiple exchanges |
data[].cnc_used_quantity | int32 | Quantity either blocked towards open or completed order |
data[].collateral_type | string | Category of collateral assigned by RMS |
data[].company_name | string | Name of the company |
data[].haircut | float | This is the haircut percentage applied from RMS (applicable incase of collateral) |
data[].product | string | Signifies if the order was either Intraday, Delivery or CO. Possible values: I , D , CO , MTF . |
data[].quantity | int32 | The total holding qty |
data[].trading_symbol | string | Shows the trading symbol of the instrument |
data[].last_price | float | The last traded price of the instrument |
data[].close_price | float | Closing price of the instrument from the last trading day |
data[].pnl | float | Profit and Loss |
data[].day_change | float | Day's change in absolute value for the stock |
data[].day_change_percentage | float | Day's change in percentage for the stock |
data[].instrument_token | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
data[].average_price | float | Average price at which the net holding quantity was acquired |
data[].collateral_quantity | int32 | Quantity marked as collateral by RMS on users request |
data[].collateral_update_quantity | int32 | Updated collateral quantity |
data[].t1_quantity | int32 | Quantity on T+1 day after order execution |
data[].exchange | string | Exchange to which the order is associated. Valid exchanges can be found in the Exchange Appendix |
Sample Code
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
import requests
url = 'https://api.upstox.com/v2/portfolio/long-term-holdings'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/portfolio/long-term-holdings';
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);
});
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/portfolio/long-term-holdings";
String acceptHeader = "application/json";
String authorizationHeader = "Bearer {your_access_token}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", acceptHeader)
.header("Authorization", authorizationHeader)
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/portfolio/long-term-holdings';
$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);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($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_version = '2.0'
api_instance = upstox_client.PortfolioApi(upstox_client.ApiClient(configuration))
try:
api_response = api_instance.get_holdings(api_version)
print(api_response)
except ApiException as e:
print("Exception when calling ChargeApi->get_brokerage: %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.PortfolioApi();
let apiVersion = "2.0";
apiInstance.getHoldings(apiVersion,(error,data,response)=>{
if(error) {
console.log(error);
}
else{
console.log("API called= " + JSON.stringify(data))
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.ConvertPositionRequest;
import com.upstox.api.ConvertPositionResponse;
import com.upstox.api.GetHoldingsResponse;
import com.upstox.auth.*;
import io.swagger.client.api.PortfolioApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
PortfolioApi apiInstance = new PortfolioApi();
String apiVersion = "2.0"; // String | API Version Header
try {
GetHoldingsResponse result = apiInstance.getHoldings(apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PortfolioApi#getHoldings");
e.printStackTrace();
}
}
}
Loading...