Skip to main content

Get Profit Loss Report

Request

curl --location 'https://api.upstox.com/v2/trade/profit-loss/data?from_date=05-11-2023&to_date=19-12-2023&segment=EQ&financial_year=2324&page_number=1&page_size=4' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'

Additional samples in various languages are available in the Sample Code section on this page.

Query Parameters

NameRequiredTypeDescription
from_datefalsestringDate 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
to_datefalsestringDate 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
segmenttruestringSegment for which data is requested can be from the following options EQ - Equity, FO - Futures and Options, COM - Commodity, CD - Currency Derivatives
financial_yeartruestringFinancial 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. For the regex pattern applicable to this field, see the Field Pattern Appendix.
page_numbertrueinteger (int32)Page Number, the pages are starting from 1
page_sizetrueinteger (int32)Page size for pagination. The maximum page size value is obtained from P and L report metadata API.
Responses

Response Body

{
"status": "success",
"data": [
{
"quantity": 100,
"isin": "INE256A01028",
"scrip_name": "ZEE ENTER",
"trade_type": "EQ",
"buy_date": "14-09-2021",
"buy_average": 12345.67,
"sell_date": "14-09-2021",
"sell_average": 12345.67,
"buy_amount": 12345.67,
"sell_amount": 12345.67
}
],
"metadata": {
"page": {
"page_number": 1,
"page_size": 2
}
}
}
NameTypeDescription
statusstringA string indicating the outcome of the request. Typically success for successful operations.
dataobject[]Response data for trade wise data details
data[].quantityfloatThe quantity of stock traded
data[].isinstringISIN of the stock
data[].scrip_namestringName of the scrip traded
data[].trade_typestringFUT - Futures OPT - Options EQ - Equity
data[].buy_datestringThe date on which the stock was bought
data[].buy_averagefloatThe average rate at which each quantity of the stock was bought
data[].sell_datestringThe date on which the stock was sold
data[].sell_averagefloatThe average rate at which each quantity of the stock was sold
data[].buy_amountfloatTotal buy amount
data[].sell_amountfloatTotal sell amount
metadataobjectMeta data for trade wise data details
metadata.pageobjectMeta data for page.
metadata.page.page_numberint32pageNumber for pagination
metadata.page.page_sizeint32Page size

Sample Code

import requests

url = 'https://api.upstox.com/v2/trade/profit-loss/data'
headers = {
'Content-Type': 'application/json',
'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())

Get profit loss report for futures and options segment

import requests

url = 'https://api.upstox.com/v2/trade/profit-loss/data'
headers = {
'Content-Type': 'application/json',
'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())
Loading...