Brokerage Details
API for calculating brokerage fees associated with stock. It accepts input parameters like the instrument, quantity, and other necessary details, and provides a comprehensive breakdown of the total charges.
Request
curl --location 'https://api.upstox.com/v2/charges/brokerage?instrument_token=NSE_EQ%7CINE669E01016&quantity=10&product=D&transaction_type=BUY&price=13.7' \
--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.
Query Parameters
| Name | Required | Type | Description |
|---|---|---|---|
| instrument_token | true | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| quantity | true | integer (int32) | Quantity with which the order is to be placed |
| product | true | string | Product with which the order is to be placed |
| transaction_type | true | string | Indicates whether its a BUY or SELL order |
| price | true | number (float) | Price with which the order is to be placed |
Responses
- 200
- 4XX
Response Body
{
"status": "success",
"data": {
"charges": {
"total": 208.27,
"brokerage": 0.0,
"taxes": {
"gst": 1.02,
"stt": 175.0,
"stamp_duty": 26.23
},
"other_charges": {
"transaction": 5.68,
"clearing": 0.0,
"ipft": 0.17,
"sebi_turnover": 0.17
},
"dp_plan": {
"name": "DP3A",
"min_expense": 18.5
}
"otherTaxes": {
"transaction": 5.68,
"clearing": 0.0,
"ipft": 0.17,
"sebi_turnover": 0.17
},
"dpPlan": {
"name": "DP3A",
"min_expense": 18.5
},
}
}
}
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Response data for brokerage |
| data.charges | object | Response data for charges details |
| data.charges.total | float | Total charges for the order |
| data.charges.brokerage | float | Brokerage charges for the order |
| data.charges.taxes | object | Taxes levied on order |
| data.charges.taxes.gst | float | GST charges |
| data.charges.taxes.stt | float | STT charges |
| data.charges.taxes.stamp_duty | float | Stamp duty charges |
| data.charges.other_charges | object | Other applicable charges |
| data.charges.other_charges.transaction | float | Transaction charges |
| data.charges.other_charges.clearing | float | Clearing charges |
| data.charges.other_charges.ipft | float | IPF charges |
| data.charges.other_charges.sebi_turnover | float | SEBI turnover charges |
| data.charges.dp_plan | object | dpPlan detail |
| data.charges.dp_plan.name | string | Name of the user's Depository Participant plan, indicating the specific DP service they are enrolled in. |
| data.charges.dp_plan.min_expense | float | Daily minimum charges per scrip on sales, not included in brokerage calculations, indicating extra costs under the user's DP plan. |
Error codes
| Error code | Description |
|---|---|
| UDAPI1059 | The instrument_token is of invalid format - The given instrument_token format isn't correct |
| UDAPI1060 | The quantity is required - The quantity field needs to be provided |
| UDAPI1064 | The quantity cannot be zero - You cannot provide zero as the quantity value |
| UDAPI1063 | The product is required - The product field is missing |
| UDAPI1054 | The 'product' is invalid - The provided value for product is not acceptable |
| UDAPI1062 | The transaction_type is required - You need to provide the transaction_type field |
| UDAPI1057 | The ''transaction_type'' is invalid - The given value for transaction_type is not valid |
| UDAPI1061 | The price is required - The price field is missing |
| UDAPI1065 | The price cannot be zero - Zero is not an acceptable value for price |
Sample Code
Equity delivery orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/charges/brokerage?instrument_token=NSE_EQ%7CINE669E01016&quantity=10&product=D&transaction_type=BUY&price=13.7' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/charges/brokerage'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
params = {
'instrument_token': 'NSE_EQ|INE669E01016',
'quantity': '10',
'product': 'D',
'transaction_type': 'BUY',
'price': '13.7'
}
response = requests.get(url, headers=headers, params=params)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/charges/brokerage';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
const params = {
instrument_token: 'NSE_EQ|INE669E01016',
quantity: '10',
product: 'D',
transaction_type: 'BUY',
price: '13.7'
};
axios.get(url, { headers, params })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error.message);
});
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class Main {
public static void main(String[] args) {
try {
String url = "https://api.upstox.com/v2/charges/brokerage";
String contentTypeHeader = "application/json";
String acceptHeader = "application/json";
String authorizationHeader = "Bearer {your_access_token}";
String instrumentToken = "NSE_EQ|INE669E01016";
String quantity = "10";
String product = "D";
String transactionType = "BUY";
String price = "13.7";
// Construct URL with parameters
StringBuilder urlBuilder = new StringBuilder(url);
urlBuilder.append("?instrument_token=").append(instrumentToken)
.append("&quantity=").append(quantity)
.append("&product=").append(product)
.append("&transaction_type=").append(transactionType)
.append("&price=").append(price);
URL obj = new URL(urlBuilder.toString());
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
// Set request method
connection.setRequestMethod("GET");
// Set request headers
connection.setRequestProperty("Content-Type", contentTypeHeader);
connection.setRequestProperty("Accept", acceptHeader);
connection.setRequestProperty("Authorization", authorizationHeader);
// Get response code
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
// Read the response
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());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/brokerage';
$contentTypeHeader = 'application/json';
$acceptHeader = 'application/json';
$authorizationHeader = 'Bearer {your_access_token}';
$instrumentToken = 'NSE_EQ|INE669E01016';
$quantity = '10';
$product = 'D';
$transactionType = 'BUY';
$price = '13.7';
// Construct URL with parameters
$url .= '?instrument_token=' . urlencode($instrumentToken)
. '&quantity=' . urlencode($quantity)
. '&product=' . urlencode($product)
. '&transaction_type=' . urlencode($transactionType)
. '&price=' . urlencode($price);
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: ' . $contentTypeHeader,
'Accept: ' . $acceptHeader,
'Authorization: ' . $authorizationHeader,
]);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
// Close cURL session
curl_close($ch);
// Print the response
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.ChargeApi(upstox_client.ApiClient(configuration))
instrument_token = 'NSE_EQ|INE669E01016'
quantity = 10
product = 'D'
transaction_type = 'BUY'
price = 13.4
try:
# Brokerage details
api_response = api_instance.get_brokerage(instrument_token, quantity, product, transaction_type, price, 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.ChargeApi();
let instrumentToken = "NSE_EQ|INE669E01016";
let quantity = 56;
let product = "D";
let transactionType = "BUY";
let price = 23.4;
let apiVersion = "2.0";
apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion, (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.GetBrokerageResponse;
import com.upstox.auth.*;
import io.swagger.client.api.ChargeApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
ChargeApi apiInstance = new ChargeApi();
String instrumentToken = "NSE_EQ|INE669E01016";
int quantity = 56;
String product = "D";
String transactionType = "BUY";
float price = 31.4F;
String apiVersion = "2.0";
try {
GetBrokerageResponse result = apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ChargeApi#getBrokerage");
e.printStackTrace();
}
}
}
Equity intraday orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/charges/brokerage?instrument_token=NSE_EQ%7CINE669E01016&quantity=10&product=I&transaction_type=BUY&price=13.7' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/charges/brokerage'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
params = {
'instrument_token': 'NSE_EQ|INE669E01016',
'quantity': '10',
'product': 'I',
'transaction_type': 'BUY',
'price': '13.7'
}
response = requests.get(url, headers=headers, params=params)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/charges/brokerage';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
const params = {
instrument_token: 'NSE_EQ|INE669E01016',
quantity: '10',
product: 'I',
transaction_type: 'BUY',
price: '13.7'
};
axios.get(url, { headers, params })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error.message);
});
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class Main {
public static void main(String[] args) {
try {
String url = "https://api.upstox.com/v2/charges/brokerage";
String contentTypeHeader = "application/json";
String acceptHeader = "application/json";
String authorizationHeader = "Bearer {your_access_token}";
String instrumentToken = "NSE_EQ|INE669E01016";
String quantity = "10";
String product = "I";
String transactionType = "BUY";
String price = "13.7";
// Construct URL with parameters
StringBuilder urlBuilder = new StringBuilder(url);
urlBuilder.append("?instrument_token=").append(instrumentToken)
.append("&quantity=").append(quantity)
.append("&product=").append(product)
.append("&transaction_type=").append(transactionType)
.append("&price=").append(price);
URL obj = new URL(urlBuilder.toString());
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
// Set request method
connection.setRequestMethod("GET");
// Set request headers
connection.setRequestProperty("Content-Type", contentTypeHeader);
connection.setRequestProperty("Accept", acceptHeader);
connection.setRequestProperty("Authorization", authorizationHeader);
// Get response code
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
// Read the response
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());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/brokerage';
$contentTypeHeader = 'application/json';
$acceptHeader = 'application/json';
$authorizationHeader = 'Bearer {your_access_token}';
$instrumentToken = 'NSE_EQ|INE669E01016';
$quantity = '10';
$product = 'I';
$transactionType = 'BUY';
$price = '13.7';
// Construct URL with parameters
$url .= '?instrument_token=' . urlencode($instrumentToken)
. '&quantity=' . urlencode($quantity)
. '&product=' . urlencode($product)
. '&transaction_type=' . urlencode($transactionType)
. '&price=' . urlencode($price);
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: ' . $contentTypeHeader,
'Accept: ' . $acceptHeader,
'Authorization: ' . $authorizationHeader,
]);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
// Close cURL session
curl_close($ch);
// Print the response
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.ChargeApi(upstox_client.ApiClient(configuration))
instrument_token = 'NSE_EQ|INE669E01016'
quantity = 10
product = 'I'
transaction_type = 'BUY'
price = 13.4
try:
# Brokerage details
api_response = api_instance.get_brokerage(instrument_token, quantity, product, transaction_type, price, 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.ChargeApi();
let instrumentToken = "NSE_EQ|INE669E01016";
let quantity = 10;
let product = "I";
let transactionType = "BUY";
let price = 20.4;
let apiVersion = "2.0";
apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion, (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.GetBrokerageResponse;
import com.upstox.auth.*;
import io.swagger.client.api.ChargeApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
ChargeApi apiInstance = new ChargeApi();
String instrumentToken = "NSE_EQ|INE669E01016";
int quantity = 56;
String product = "I";
String transactionType = "BUY";
float price = 31.4F;
String apiVersion = "2.0";
try {
GetBrokerageResponse result = apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ChargeApi#getBrokerage");
e.printStackTrace();
}
}
}
Equity futures and options delivery orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/charges/brokerage?instrument_token=NSE_FO%7C35271&quantity=10&product=D&transaction_type=BUY&price=1400' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/charges/brokerage'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
params = {
'instrument_token': 'NSE_FO|35271',
'quantity': '10',
'product': 'D',
'transaction_type': 'BUY',
'price': '1400'
}
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/charges/brokerage';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
const params = {
'instrument_token': 'NSE_FO|35271',
'quantity': '10',
'product': 'D',
'transaction_type': 'BUY',
'price': '1400'
};
axios.get(url, { headers, params })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error(error.response.status);
console.error(error.response.data);
});
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class Main {
public static void main(String[] args) {
try {
String url = "https://api.upstox.com/v2/charges/brokerage";
String accessToken = "{your_access_token}"; // Replace {your_access_token} with your actual access token
// Construct URL with parameters
String params = "instrument_token=NSE_FO%7C35271&quantity=10&product=D&transaction_type=BUY&price=1400";
URL apiUrl = new URL(url + "?" + params);
// Open connection
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
// Set request method
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Authorization", "Bearer " + accessToken);
// Get response code
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
// Read response
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 response
System.out.println("Response: " + response.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/brokerage';
$accessToken = '{your_access_token}'; // Replace {your_access_token} with your actual access token
// Construct URL with parameters
$params = http_build_query([
'instrument_token' => 'NSE_FO|35271',
'quantity' => '10',
'product' => 'D',
'transaction_type' => 'BUY',
'price' => '1400',
]);
$fullUrl = $url . '?' . $params;
// Set headers
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer ' . $accessToken,
];
// Initialize cURL session
$ch = curl_init($fullUrl);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Get HTTP response code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close cURL session
curl_close($ch);
// Print response code and body
echo "Response Code: $httpCode\n";
echo "Response: $response\n";
?>
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.ChargeApi(upstox_client.ApiClient(configuration))
instrument_token = 'NSE_FO|35271'
quantity = 10
product = 'D'
transaction_type = 'BUY'
price = 1333.4
try:
# Brokerage details
api_response = api_instance.get_brokerage(instrument_token, quantity, product, transaction_type, price, 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.ChargeApi();
let instrumentToken = "NSE_FO|35271";
let quantity = 10;
let product = "D";
let transactionType = "BUY";
let price = 2000.4;
let apiVersion = "2.0";
apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion, (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.GetBrokerageResponse;
import com.upstox.auth.*;
import io.swagger.client.api.ChargeApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
ChargeApi apiInstance = new ChargeApi();
String instrumentToken = "NSE_FO|35271";
int quantity = 5;
String product = "D";
String transactionType = "BUY";
float price = 1331.4F;
String apiVersion = "2.0";
try {
GetBrokerageResponse result = apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ChargeApi#getBrokerage");
e.printStackTrace();
}
}
}
Equity futures and options intraday orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v2/charges/brokerage?instrument_token=NSE_FO%7C35271&quantity=10&product=I&transaction_type=BUY&price=1400' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/charges/brokerage'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
params = {
'instrument_token': 'NSE_FO|35271',
'quantity': '10',
'product': 'I',
'transaction_type': 'BUY',
'price': '1400'
}
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/charges/brokerage';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
const params = {
'instrument_token': 'NSE_FO|35271',
'quantity': '10',
'product': 'I',
'transaction_type': 'BUY',
'price': '1400'
};
axios.get(url, { headers, params })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error(error.response.status);
console.error(error.response.data);
});
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class Main {
public static void main(String[] args) {
try {
String url = "https://api.upstox.com/v2/charges/brokerage";
String accessToken = "{your_access_token}"; // Replace {your_access_token} with your actual access token
// Construct URL with parameters
String params = "instrument_token=NSE_FO%7C35271&quantity=10&product=I&transaction_type=BUY&price=1400";
URL apiUrl = new URL(url + "?" + params);
// Open connection
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
// Set request method
connection.setRequestMethod("GET");
// Set headers
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Authorization", "Bearer " + accessToken);
// Get response code
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
// Read response
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 response
System.out.println("Response: " + response.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/brokerage';
$accessToken = '{your_access_token}'; // Replace {your_access_token} with your actual access token
// Construct URL with parameters
$params = http_build_query([
'instrument_token' => 'NSE_FO|35271',
'quantity' => '10',
'product' => 'I',
'transaction_type' => 'BUY',
'price' => '1400',
]);
$fullUrl = $url . '?' . $params;
// Set headers
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer ' . $accessToken,
];
// Initialize cURL session
$ch = curl_init($fullUrl);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Get HTTP response code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close cURL session
curl_close($ch);
// Print response code and body
echo "Response Code: $httpCode\n";
echo "Response: $response\n";
?>
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.ChargeApi(upstox_client.ApiClient(configuration))
instrument_token = 'NSE_FO|35271'
quantity = 10
product = 'I'
transaction_type = 'BUY'
price = 1333.4
try:
# Brokerage details
api_response = api_instance.get_brokerage(instrument_token, quantity, product, transaction_type, price, 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.ChargeApi();
let instrumentToken = "NSE_FO|35271";
let quantity = 10;
let product = "I";
let transactionType = "BUY";
let price = 2000.4;
let apiVersion = "2.0";
apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion, (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.GetBrokerageResponse;
import com.upstox.auth.*;
import io.swagger.client.api.ChargeApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
ChargeApi apiInstance = new ChargeApi();
String instrumentToken = "NSE_FO|35271";
int quantity = 5;
String product = "I";
String transactionType = "BUY";
float price = 1331.4F;
String apiVersion = "2.0";
try {
GetBrokerageResponse result = apiInstance.getBrokerage(instrumentToken, quantity, product, transactionType, price, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ChargeApi#getBrokerage");
e.printStackTrace();
}
}
}
Loading...