Get Profit Loss Report
Get profit loss report for equity segment
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/trade/profit-loss/data?from_date=05-11-2023%20&to_date=19-12-2023&segment=EQ&financial_year=2324&page_number=1&page_size=4' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/trade/profit-loss/data'
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
params = {
'from_date': '05-11-2023',
'to_date': '19-12-2023',
'segment': 'EQ',
'financial_year': '2324',
'page_number': '1',
'page_size': '4'
}
response = requests.get(url, headers=headers, params=params)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/trade/profit-loss/data';
const headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
const params = {
'from_date': '05-11-2023',
'to_date': '19-12-2023',
'segment': 'EQ',
'financial_year': '2324',
'page_number': '1',
'page_size': '4'
};
axios.get(url, { headers, params })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error('Error:', error.message || error);
});
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.upstox.com/v2/trade/profit-loss/data";
String acceptHeader = "application/json";
String authToken = "Bearer {your_access_token}";
String fromDate = "05-11-2023";
String toDate = "19-12-2023";
String segment = "EQ";
String financialYear = "2324";
String pageNumber = "1";
String pageSize = "4";
String encodedParams = String.format("from_date=%s&to_date=%s&segment=%s&financial_year=%s&page_number=%s&page_size=%s",
URLEncoder.encode(fromDate, "UTF-8"),
URLEncoder.encode(toDate, "UTF-8"),
URLEncoder.encode(segment, "UTF-8"),
URLEncoder.encode(financialYear, "UTF-8"),
URLEncoder.encode(pageNumber, "UTF-8"),
URLEncoder.encode(pageSize, "UTF-8"));
String fullUrl = url + "?" + encodedParams;
URL obj = new URL(fullUrl);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
// Set request method
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", acceptHeader);
connection.setRequestProperty("Authorization", authToken);
int responseCode = connection.getResponseCode();
System.out.println("Sending 'GET' request to URL: " + fullUrl);
System.out.println("Response Code: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// Print the response
System.out.println("Response: " + response.toString());
}
}
<?php
$url = 'https://api.upstox.com/v2/trade/profit-loss/data';
$acceptHeader = 'application/json';
$authToken = 'Bearer {your_access_token}';
$fromDate = '05-11-2023';
$toDate = '19-12-2023';
$segment = 'EQ';
$financialYear = '2324';
$pageNumber = '1';
$pageSize = '4';
$params = [
'from_date' => $fromDate,
'to_date' => $toDate,
'segment' => $segment,
'financial_year' => $financialYear,
'page_number' => $pageNumber,
'page_size' => $pageSize,
];
$encodedParams = http_build_query($params);
$fullUrl = $url . '?' . $encodedParams;
$headers = [
'Accept: ' . $acceptHeader,
'Authorization: ' . $authToken,
];
$ch = curl_init($fullUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo 'URL: ' . $fullUrl . PHP_EOL;
echo 'Response Code: ' . $httpCode . PHP_EOL;
echo 'Response: ' . $response . PHP_EOL;
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
api_instance = upstox_client.TradeProfitAndLossApi(upstox_client.ApiClient(configuration))
segment = 'EQ'
financial_year = '2324' # str | Financial year for which data has been requested. Concatenation of last 2 digits of from year and to year Sample:for 2021-2022, financial_year will be 2122
page_number = 1
page_size = 4
api_version = '2.0' # str | API Version Header
from_date = '02-04-2023' # str | Date from which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)
to_date = '20-03-2024' # str | Date till which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)
try:
# Get Trade-wise Profit and Loss Report Data
api_response = api_instance.get_trade_wise_profit_and_loss_data(segment, financial_year, page_number, page_size, api_version, from_date=from_date, to_date=to_date)
print(api_response)
except ApiException as e:
print("Exception when calling TradeProfitAndLossApi->get_trade_wise_profit_and_loss_data: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
// Configure OAuth2 access token for authorization: OAUTH2
let OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = '{your_access_token}';
let apiInstance = new UpstoxClient.TradeProfitAndLossApi();
let segment = "EQ"; // String | Segment for which data is requested can be from the following options EQ - Equity, FO - Futures and Options, COM - Commodity, CD - Currency Derivatives
let financialYear = "2324"; // String | Financial year for which data has been requested. Concatenation of last 2 digits of from year and to year Sample:for 2021-2022, financial_year will be 2122
let pageNumber = 1; // Number | Page Number, the pages are starting from 1
let pageSize = 40; // Number | Page size for pagination. The maximum page size value is obtained from P and L report metadata API.
let apiVersion = "2.0"; // String | API Version Header
let opts = {
'fromDate': "02-04-2023", // String | Date from which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format
'toDate': "20-03-2024" // String | Date till which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format
};
apiInstance.getTradeWiseProfitAndLossData(segment, financialYear, pageNumber, pageSize, apiVersion, opts, (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.GetTradeWiseProfitAndLossDataResponse;
import com.upstox.api.GetTradeWiseProfitAndLossMetaDataResponse;
import com.upstox.auth.*;
import io.swagger.client.api.TradeProfitAndLossApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
TradeProfitAndLossApi apiInstance = new TradeProfitAndLossApi();
String segment = "EQ";
String financialYear = "2324";
String apiVersion = "2.0";
String fromDate = "02-04-2023";
String toDate = "20-03-2024";
Integer pageNumber = 1;
Integer pageSize = 5;
try {
GetTradeWiseProfitAndLossDataResponse result = apiInstance.getTradeWiseProfitAndLossData(segment, financialYear, pageNumber, pageSize, apiVersion, fromDate, toDate);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling TradeProfitAndLossApi#getTradeWiseProfitAndLossData");
e.printStackTrace();
}
}
}
Get profit loss report for futures and options segment
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/trade/profit-loss/data?from_date=05-11-2023%20&to_date=19-12-2023&segment=FO&financial_year=2324&page_number=1&page_size=4' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/trade/profit-loss/data'
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
params = {
'from_date': '05-11-2023',
'to_date': '19-12-2023',
'segment': 'FO',
'financial_year': '2324',
'page_number': '1',
'page_size': '4'
}
response = requests.get(url, headers=headers, params=params)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/trade/profit-loss/data';
const headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
const params = {
'from_date': '05-11-2023',
'to_date': '19-12-2023',
'segment': 'FO',
'financial_year': '2324',
'page_number': '1',
'page_size': '4'
};
axios.get(url, { headers, params })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error('Error:', error.message || error);
});
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.upstox.com/v2/trade/profit-loss/data";
String acceptHeader = "application/json";
String authToken = "Bearer {your_access_token}";
String fromDate = "05-11-2023";
String toDate = "19-12-2023";
String segment = "FO";
String financialYear = "2324";
String pageNumber = "1";
String pageSize = "4";
String encodedParams = String.format("from_date=%s&to_date=%s&segment=%s&financial_year=%s&page_number=%s&page_size=%s",
URLEncoder.encode(fromDate, "UTF-8"),
URLEncoder.encode(toDate, "UTF-8"),
URLEncoder.encode(segment, "UTF-8"),
URLEncoder.encode(financialYear, "UTF-8"),
URLEncoder.encode(pageNumber, "UTF-8"),
URLEncoder.encode(pageSize, "UTF-8"));
String fullUrl = url + "?" + encodedParams;
URL obj = new URL(fullUrl);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
// Set request method
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", acceptHeader);
connection.setRequestProperty("Authorization", authToken);
int responseCode = connection.getResponseCode();
System.out.println("Sending 'GET' request to URL: " + fullUrl);
System.out.println("Response Code: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// Print the response
System.out.println("Response: " + response.toString());
}
}
<?php
$url = 'https://api.upstox.com/v2/trade/profit-loss/data';
$acceptHeader = 'application/json';
$authToken = 'Bearer {your_access_token}';
$fromDate = '05-11-2023';
$toDate = '19-12-2023';
$segment = 'FO';
$financialYear = '2324';
$pageNumber = '1';
$pageSize = '4';
$params = [
'from_date' => $fromDate,
'to_date' => $toDate,
'segment' => $segment,
'financial_year' => $financialYear,
'page_number' => $pageNumber,
'page_size' => $pageSize,
];
$encodedParams = http_build_query($params);
$fullUrl = $url . '?' . $encodedParams;
$headers = [
'Accept: ' . $acceptHeader,
'Authorization: ' . $authToken,
];
$ch = curl_init($fullUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo 'URL: ' . $fullUrl . PHP_EOL;
echo 'Response Code: ' . $httpCode . PHP_EOL;
echo 'Response: ' . $response . PHP_EOL;
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
api_instance = upstox_client.TradeProfitAndLossApi(upstox_client.ApiClient(configuration))
segment = 'FO'
financial_year = '2324' # str | Financial year for which data has been requested. Concatenation of last 2 digits of from year and to year Sample:for 2021-2022, financial_year will be 2122
page_number = 1
page_size = 4
api_version = '2.0' # str | API Version Header
from_date = '02-04-2023' # str | Date from which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)
to_date = '20-03-2024' # str | Date till which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)
try:
# Get Trade-wise Profit and Loss Report Data
api_response = api_instance.get_trade_wise_profit_and_loss_data(segment, financial_year, page_number, page_size, api_version, from_date=from_date, to_date=to_date)
print(api_response)
except ApiException as e:
print("Exception when calling TradeProfitAndLossApi->get_trade_wise_profit_and_loss_data: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
// Configure OAuth2 access token for authorization: OAUTH2
let OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = '{your_access_token}';
let apiInstance = new UpstoxClient.TradeProfitAndLossApi();
let segment = "FO"; // String | Segment for which data is requested can be from the following options EQ - Equity, FO - Futures and Options, COM - Commodity, CD - Currency Derivatives
let financialYear = "2324"; // String | Financial year for which data has been requested. Concatenation of last 2 digits of from year and to year Sample:for 2021-2022, financial_year will be 2122
let pageNumber = 1; // Number | Page Number, the pages are starting from 1
let pageSize = 40; // Number | Page size for pagination. The maximum page size value is obtained from P and L report metadata API.
let apiVersion = "2.0"; // String | API Version Header
let opts = {
'fromDate': "02-04-2023", // String | Date from which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format
'toDate': "20-03-2024" // String | Date till which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format
};
apiInstance.getTradeWiseProfitAndLossData(segment, financialYear, pageNumber, pageSize, apiVersion, opts, (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.GetTradeWiseProfitAndLossDataResponse;
import com.upstox.api.GetTradeWiseProfitAndLossMetaDataResponse;
import com.upstox.auth.*;
import io.swagger.client.api.TradeProfitAndLossApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
TradeProfitAndLossApi apiInstance = new TradeProfitAndLossApi();
String segment = "FO";
String financialYear = "2324";
String apiVersion = "2.0";
String fromDate = "02-04-2023";
String toDate = "20-03-2024";
Integer pageNumber = 1;
Integer pageSize = 5;
try {
GetTradeWiseProfitAndLossDataResponse result = apiInstance.getTradeWiseProfitAndLossData(segment, financialYear, pageNumber, pageSize, apiVersion, fromDate, toDate);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling TradeProfitAndLossApi#getTradeWiseProfitAndLossData");
e.printStackTrace();
}
}
}