Get Positions
API to retrieve the current positions for the user. These assets remain within the positions portfolio until they are either sold or reach their standard three-month expiration date in the case of derivatives. If any equity positions are carried overnight, they are automatically shifted to the holdings portfolio on the following trading day.
Request
curl --location 'https://api.upstox.com/v2/portfolio/short-term-positions' \
--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": "NFO",
"multiplier": 1.0,
"value": 39.75,
"pnl": 26.25,
"product": "D",
"instrument_token": "NSE_FO|52618",
"average_price": 2.65,
"buy_value": 0.0,
"overnight_quantity": 15,
"day_buy_value": 0.0,
"day_buy_price": 0.0,
"overnight_buy_amount": 39.75,
"overnight_buy_quantity": 15,
"day_buy_quantity": 0,
"day_sell_value": 0.0,
"day_sell_price": 0.0,
"overnight_sell_amount": 0.0,
"overnight_sell_quantity": 0,
"day_sell_quantity": 0,
"quantity": 15,
"last_price": 1.75,
"unrealised": -658304.25,
"realised": -0.0,
"sell_value": 0.0,
"trading_symbol": "BANKNIFTY23OCT38000PE",
"tradingsymbol": "BANKNIFTY23OCT38000PE",
"close_price": 1.95,
"buy_price": 2.65,
"sell_price": 0.0
},
{
"exchange": "BSE",
"multiplier": 1.0,
"value": 0.8,
"pnl": 0.01,
"product": "D",
"instrument_token": "BSE_EQ|INE220J01025",
"average_price": null,
"buy_value": 0.8,
"overnight_quantity": 0,
"day_buy_value": 0.8,
"day_buy_price": 0.8,
"overnight_buy_amount": 0.0,
"overnight_buy_quantity": 0,
"day_buy_quantity": 1,
"day_sell_value": 0.0,
"day_sell_price": 0.0,
"overnight_sell_amount": 0.0,
"overnight_sell_quantity": 0,
"day_sell_quantity": 0,
"quantity": 1,
"last_price": 0.81,
"unrealised": 0.01,
"realised": -0.0,
"sell_value": 0.0,
"trading_symbol": "FCONSUMER",
"tradingsymbol": "FCONSUMER",
"close_price": 0.8,
"buy_price": 0.8,
"sell_price": 0.0
},
{
"exchange": "MCX",
"multiplier": 1.0,
"value": 5867.0,
"pnl": 6005.0,
"product": "D",
"instrument_token": "MCX_FO|259711",
"average_price": 5867.0,
"buy_value": 0.0,
"overnight_quantity": 1,
"day_buy_value": 0.0,
"day_buy_price": 0.0,
"overnight_buy_amount": 5867.0,
"overnight_buy_quantity": 1,
"day_buy_quantity": 0,
"day_sell_value": 0.0,
"day_sell_price": 0.0,
"overnight_sell_amount": 0.0,
"overnight_sell_quantity": 0,
"day_sell_quantity": 0,
"quantity": 1,
"last_price": 6005.0,
"unrealised": 0.0,
"realised": -0.0,
"sell_value": 0.0,
"trading_symbol": "GOLDPETAL23DECFUT",
"tradingsymbol": "GOLDPETAL23DECFUT",
"close_price": 6005.0,
"buy_price": 5867.0,
"sell_price": 0.0
},
{
"exchange": "CDS",
"multiplier": 1000.0,
"value": 5.0,
"pnl": 2.5,
"product": "D",
"instrument_token": "NCD_FO|13177",
"average_price": 0.005,
"buy_value": 0.0,
"overnight_quantity": 1,
"day_buy_value": 0.0,
"day_buy_price": 0.0,
"overnight_buy_amount": 0.005,
"overnight_buy_quantity": 1,
"day_buy_quantity": 0,
"day_sell_value": 0.0,
"day_sell_price": 0.0,
"overnight_sell_amount": 0.0,
"overnight_sell_quantity": 0,
"day_sell_quantity": 0,
"quantity": 1,
"last_price": 0.0025,
"unrealised": -83265.0,
"realised": -0.0,
"sell_value": 0.0,
"trading_symbol": "USDINR23OCT85.5CE",
"tradingsymbol": "USDINR23OCT85.5CE",
"close_price": 0.0025,
"buy_price": 0.005,
"sell_price": 0.0
},
{
"exchange": "NSE",
"multiplier": 1.0,
"value": 0.0,
"pnl": 0.45,
"product": "D",
"instrument_token": "NSE_EQ|INE062A01020",
"average_price": null,
"buy_value": 570.95,
"overnight_quantity": 0,
"day_buy_value": 570.95,
"day_buy_price": 570.95,
"overnight_buy_amount": 0.0,
"overnight_buy_quantity": 0,
"day_buy_quantity": 1,
"day_sell_value": 571.4,
"day_sell_price": 571.4,
"overnight_sell_amount": 0.0,
"overnight_sell_quantity": 0,
"day_sell_quantity": 1,
"quantity": 0,
"last_price": 571.2,
"unrealised": 0.0,
"realised": 0.45,
"sell_value": 571.4,
"trading_symbol": "SBIN",
"tradingsymbol": "SBIN",
"close_price": 572.65,
"buy_price": 570.95,
"sell_price": 571.4
}
]
}
Name | Type | Description |
---|---|---|
status | string | A string indicating the outcome of the request. Typically success for successful operations. |
data | object[] | Response data for position details |
data[].exchange | string | Exchange to which the order is associated. Valid exchanges can be found in the Exchange Appendix |
data[].multiplier | float | The quantity/lot size multiplier used for calculating P&Ls |
data[].value | float | Net value of the position |
data[].pnl | float | Profit and loss - net returns on the position |
data[].product | string | Signifies if the order was either Intraday, Delivery or CO. Possible values: I , D , CO . |
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 position quantity was acquired |
data[].buy_value | float | Net value of the bought quantities |
data[].overnight_quantity | int32 | Quantity held previously and carried forward over night |
data[].day_buy_value | float | Amount at which the quantity is bought during the day |
data[].day_buy_price | float | Average price at which the day qty was bought. Default is empty string |
data[].overnight_buy_amount | float | Amount at which the quantity was bought in the previous session |
data[].overnight_buy_quantity | int32 | Quantity bought in the previous session |
data[].day_buy_quantity | int32 | Quantity bought during the day |
data[].day_sell_value | float | Amount at which the quantity is sold during the day |
data[].day_sell_price | float | Average price at which the day quantity was sold |
data[].overnight_sell_amount | float | Amount at which the quantity was sold in the previous session |
data[].overnight_sell_quantity | int32 | Quantity sold short in the previous session |
data[].day_sell_quantity | int32 | Quantity sold during the day |
data[].quantity | int32 | Quantity left after nullifying Day and CF buy quantity towards Day and CF sell quantity |
data[].last_price | float | Last traded market price of the instrument |
data[].unrealised | float | Day PnL generated against open positions |
data[].realised | float | Day PnL generated against closed positions |
data[].sell_value | float | Net value of the sold quantities |
data[].trading_symbol | string | Shows the trading symbol of the instrument |
data[].close_price | float | Closing price of the instrument from the last trading day |
data[].buy_price | float | Average price at which quantities were bought |
data[].sell_price | float | Average price at which quantities were sold |
Sample Code
Get user positions
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
import requests
url = 'https://api.upstox.com/v2/portfolio/short-term-positions'
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/short-term-positions';
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/short-term-positions";
String contentTypeHeader = "application/json";
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", contentTypeHeader)
.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/short-term-positions';
$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_positions(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.getPositions(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.GetPositionResponse;
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 {
GetPositionResponse result = apiInstance.getPositions(apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PortfolioApi#getPositions");
e.printStackTrace();
}
}
}
Loading...