Get Trade Charges
Get trade charges 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/charges?from_date=05-11-2023%20&to_date=19-12-2023&segment=EQ&financial_year=2324' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/trade/profit-loss/charges'
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'
}
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/charges';
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'
};
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/charges";
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 encodedParams = String.format("from_date=%s&to_date=%s&segment=%s&financial_year=%s",
URLEncoder.encode(fromDate, "UTF-8"),
URLEncoder.encode(toDate, "UTF-8"),
URLEncoder.encode(segment, "UTF-8"),
URLEncoder.encode(financialYear, "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/charges';
$acceptHeader = 'application/json';
$authToken = 'Bearer {your_access_token}';
$fromDate = '05-11-2023';
$toDate = '19-12-2023';
$segment = 'EQ';
$financialYear = '2324';
$params = [
'from_date' => $fromDate,
'to_date' => $toDate,
'segment' => $segment,
'financial_year' => $financialYear
];
$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
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_profit_and_loss_charges(segment, financial_year, 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 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.getProfitAndLossCharges(segment, financialYear, 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.GetProfitAndLossChargesResponse;
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";
try {
GetProfitAndLossChargesResponse result = apiInstance.getProfitAndLossCharges(segment, financialYear, apiVersion, fromDate, toDate);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling TradeProfitAndLossApi#getProfitAndLossCharges");
e.printStackTrace();
}
}
}
Get trade charges 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/charges?from_date=05-11-2023%20&to_date=19-12-2023&segment=FO&financial_year=2324' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/trade/profit-loss/charges'
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'
}
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/charges';
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'
};
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/charges";
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 encodedParams = String.format("from_date=%s&to_date=%s&segment=%s&financial_year=%s",
URLEncoder.encode(fromDate, "UTF-8"),
URLEncoder.encode(toDate, "UTF-8"),
URLEncoder.encode(segment, "UTF-8"),
URLEncoder.encode(financialYear, "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/charges';
$acceptHeader = 'application/json';
$authToken = 'Bearer {your_access_token}';
$fromDate = '05-11-2023';
$toDate = '19-12-2023';
$segment = 'FO';
$financialYear = '2324';
$params = [
'from_date' => $fromDate,
'to_date' => $toDate,
'segment' => $segment,
'financial_year' => $financialYear
];
$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
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_profit_and_loss_charges(segment, financial_year, 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 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.getProfitAndLossCharges(segment, financialYear, 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.GetProfitAndLossChargesResponse;
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";
try {
GetProfitAndLossChargesResponse result = apiInstance.getProfitAndLossCharges(segment, financialYear, apiVersion, fromDate, toDate);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling TradeProfitAndLossApi#getProfitAndLossCharges");
e.printStackTrace();
}
}
}