Margin Details
Get margin details for equity delivery orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl -X 'POST' \
'https://api.upstox.com/v2/charges/margin' \
-H 'accept: application/json' \
-H 'Authorization: Bearer {your_access_token}' \
-H 'Content-Type: application/json' \
-d '{
"instruments": [
{
"instrument_key": "NSE_EQ|INE669E01016",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}'
import requests
url = "https://api.upstox.com/v2/charges/margin"
headers = {
"accept": "application/json",
"Authorization": "Bearer {your_access_token}",
"Content-Type": "application/json"
}
data = {
"instruments": [
{
"instrument_key": "NSE_EQ|INE669E01016",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/charges/margin';
const headers = {
'accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
'Content-Type': 'application/json'
};
const data = {
instruments: [
{
instrument_key: 'NSE_EQ|INE669E01016',
quantity: 1,
transaction_type: 'BUY',
product: 'D'
}
]
};
axios.post(url, data, { headers })
.then(response => {
console.log(response.status);
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;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class Main {
public static void main(String[] args) {
String url = "https://api.upstox.com/v2/charges/margin";
String token = "Bearer {your_access_token}";
String json = """
{
"instruments": [
{
"instrument_key": "NSE_EQ|INE669E01016",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("accept", "application/json")
.header("Authorization", token)
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json))
.build();
try {
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("Status code: " + response.statusCode());
System.out.println("Response body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/margin';
$token = 'Bearer {your_access_token}';
$data = [
"instruments" => [
[
"instrument_key" => "NSE_EQ|INE669E01016",
"quantity" => 1,
"transaction_type" => "BUY",
"product" => "D"
]
]
];
$headers = [
'Accept: application/json',
'Authorization: ' . $token,
'Content-Type: application/json'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status code: " . $httpStatusCode . PHP_EOL;
echo "Response body: " . $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.ChargeApi(upstox_client.ApiClient(configuration))
instruments = [upstox_client.Instrument(instrument_key="NSE_EQ|INE528G01035",quantity=5,product="D",transaction_type="BUY")]
margin_body = upstox_client.MarginRequest(instruments)
try:
api_response = api_instance.post_margin(margin_body)
print(api_response)
except ApiException as e:
print("Exception when calling Margin API: %s\n" % e.body)
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 instruments =[new UpstoxClient.Instrument("NSE_EQ|INE669E01016",1,"D","BUY")];
let postMarginRequest = new UpstoxClient.MarginRequest(instruments)
apiInstance.postMargin(postMarginRequest, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log(data);
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.*;
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 api = new ChargeApi();
MarginRequest marginRequest = new MarginRequest();
Instrument instrument = new Instrument();
instrument.setInstrumentKey("NSE_EQ|INE669E01016");
instrument.setQuantity(1);
instrument.setProduct("D");
instrument.setTransactionType("BUY");
marginRequest.addInstrumentsItem(instrument);
try {
PostMarginResponse response = api.postMargin(marginRequest);
System.out.println(response);
} catch (ApiException e) {
System.err.println("Exception when calling Margin API " + e.getResponseBody());
e.printStackTrace();
}
}
}
Get margin details for future delivery orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl -X 'POST' \
'https://api.upstox.com/v2/charges/margin' \
-H 'accept: application/json' \
-H 'Authorization: Bearer {your_access_token}' \
-H 'Content-Type: application/json' \
-d '{
"instruments": [
{
"instrument_key": "NSE_FO|35000",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}'
import requests
url = "https://api.upstox.com/v2/charges/margin"
headers = {
"accept": "application/json",
"Authorization": "Bearer {your_access_token}",
"Content-Type": "application/json"
}
data = {
"instruments": [
{
"instrument_key": "NSE_FO|35000",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/charges/margin';
const headers = {
'accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
'Content-Type': 'application/json'
};
const data = {
instruments: [
{
instrument_key: 'NSE_FO|35000',
quantity: 1,
transaction_type: 'BUY',
product: 'D'
}
]
};
axios.post(url, data, { headers })
.then(response => {
console.log(response.status);
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;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class Main {
public static void main(String[] args) {
String url = "https://api.upstox.com/v2/charges/margin";
String token = "Bearer {your_access_token}";
String json = """
{
"instruments": [
{
"instrument_key": "NSE_FO|35000",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("accept", "application/json")
.header("Authorization", token)
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json))
.build();
try {
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("Status code: " + response.statusCode());
System.out.println("Response body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/margin';
$token = 'Bearer {your_access_token}';
$data = [
"instruments" => [
[
"instrument_key" => "NSE_FO|35000",
"quantity" => 1,
"transaction_type" => "BUY",
"product" => "D"
]
]
];
$headers = [
'Accept: application/json',
'Authorization: ' . $token,
'Content-Type: application/json'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status code: " . $httpStatusCode . PHP_EOL;
echo "Response body: " . $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.ChargeApi(upstox_client.ApiClient(configuration))
instruments = [upstox_client.Instrument(instrument_key="NSE_FO|35000",quantity=5,product="D",transaction_type="BUY")]
margin_body = upstox_client.MarginRequest(instruments)
try:
api_response = api_instance.post_margin(margin_body)
print(api_response)
except ApiException as e:
print("Exception when calling Margin API: %s\n" % e.body)
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 instruments =[new UpstoxClient.Instrument("NSE_FO|35000",1,"D","BUY")];
let postMarginRequest = new UpstoxClient.MarginRequest(instruments)
apiInstance.postMargin(postMarginRequest, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log(data);
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.*;
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 api = new ChargeApi();
MarginRequest marginRequest = new MarginRequest();
Instrument instrument = new Instrument();
instrument.setInstrumentKey("NSE_FO|35000");
instrument.setQuantity(1);
instrument.setProduct("D");
instrument.setTransactionType("BUY");
marginRequest.addInstrumentsItem(instrument);
try {
PostMarginResponse response = api.postMargin(marginRequest);
System.out.println(response);
} catch (ApiException e) {
System.err.println("Exception when calling Margin API " + e.getResponseBody());
e.printStackTrace();
}
}
}
Get margin details for option delivery orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl -X 'POST' \
'https://api.upstox.com/v2/charges/margin' \
-H 'accept: application/json' \
-H 'Authorization: Bearer {your_access_token}' \
-H 'Content-Type: application/json' \
-d '{
"instruments": [
{
"instrument_key": "NSE_FO|54524",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}'
import requests
url = "https://api.upstox.com/v2/charges/margin"
headers = {
"accept": "application/json",
"Authorization": "Bearer {your_access_token}",
"Content-Type": "application/json"
}
data = {
"instruments": [
{
"instrument_key": "NSE_FO|54524",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/charges/margin';
const headers = {
'accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
'Content-Type': 'application/json'
};
const data = {
instruments: [
{
instrument_key: 'NSE_FO|54524',
quantity: 1,
transaction_type: 'BUY',
product: 'D'
}
]
};
axios.post(url, data, { headers })
.then(response => {
console.log(response.status);
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;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class Main {
public static void main(String[] args) {
String url = "https://api.upstox.com/v2/charges/margin";
String token = "Bearer {your_access_token}";
String json = """
{
"instruments": [
{
"instrument_key": "NSE_FO|54524",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("accept", "application/json")
.header("Authorization", token)
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json))
.build();
try {
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("Status code: " + response.statusCode());
System.out.println("Response body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/margin';
$token = 'Bearer {your_access_token}';
$data = [
"instruments" => [
[
"instrument_key" => "NSE_FO|54524",
"quantity" => 1,
"transaction_type" => "BUY",
"product" => "D"
]
]
];
$headers = [
'Accept: application/json',
'Authorization: ' . $token,
'Content-Type: application/json'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status code: " . $httpStatusCode . PHP_EOL;
echo "Response body: " . $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.ChargeApi(upstox_client.ApiClient(configuration))
instruments = [upstox_client.Instrument(instrument_key="NSE_FO|54524",quantity=5,product="D",transaction_type="BUY")]
margin_body = upstox_client.MarginRequest(instruments)
try:
api_response = api_instance.post_margin(margin_body)
print(api_response)
except ApiException as e:
print("Exception when calling Margin API: %s\n" % e.body)
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 instruments =[new UpstoxClient.Instrument("NSE_FO|54524",1,"D","BUY")];
let postMarginRequest = new UpstoxClient.MarginRequest(instruments)
apiInstance.postMargin(postMarginRequest, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log(data);
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.*;
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 api = new ChargeApi();
MarginRequest marginRequest = new MarginRequest();
Instrument instrument = new Instrument();
instrument.setInstrumentKey("NSE_FO|54524");
instrument.setQuantity(1);
instrument.setProduct("D");
instrument.setTransactionType("BUY");
marginRequest.addInstrumentsItem(instrument);
try {
PostMarginResponse response = api.postMargin(marginRequest);
System.out.println(response);
} catch (ApiException e) {
System.err.println("Exception when calling Margin API " + e.getResponseBody());
e.printStackTrace();
}
}
}
Get margin details for MCX delivery orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl -X 'POST' \
'https://api.upstox.com/v2/charges/margin' \
-H 'accept: application/json' \
-H 'Authorization: Bearer {your_access_token}' \
-H 'Content-Type: application/json' \
-d '{
"instruments": [
{
"instrument_key": "MCX_FO|435356",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}'
import requests
url = "https://api.upstox.com/v2/charges/margin"
headers = {
"accept": "application/json",
"Authorization": "Bearer {your_access_token}",
"Content-Type": "application/json"
}
data = {
"instruments": [
{
"instrument_key": "MCX_FO|435356",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/charges/margin';
const headers = {
'accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
'Content-Type': 'application/json'
};
const data = {
instruments: [
{
instrument_key: 'MCX_FO|435356',
quantity: 1,
transaction_type: 'BUY',
product: 'D'
}
]
};
axios.post(url, data, { headers })
.then(response => {
console.log(response.status);
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;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class Main {
public static void main(String[] args) {
String url = "https://api.upstox.com/v2/charges/margin";
String token = "Bearer {your_access_token}";
String json = """
{
"instruments": [
{
"instrument_key": "MCX_FO|435356",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("accept", "application/json")
.header("Authorization", token)
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json))
.build();
try {
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("Status code: " + response.statusCode());
System.out.println("Response body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/margin';
$token = 'Bearer {your_access_token}';
$data = [
"instruments" => [
[
"instrument_key" => "MCX_FO|435356",
"quantity" => 1,
"transaction_type" => "BUY",
"product" => "D"
]
]
];
$headers = [
'Accept: application/json',
'Authorization: ' . $token,
'Content-Type: application/json'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status code: " . $httpStatusCode . PHP_EOL;
echo "Response body: " . $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.ChargeApi(upstox_client.ApiClient(configuration))
instruments = [upstox_client.Instrument(instrument_key="MCX_FO|435356",quantity=5,product="D",transaction_type="BUY")]
margin_body = upstox_client.MarginRequest(instruments)
try:
api_response = api_instance.post_margin(margin_body)
print(api_response)
except ApiException as e:
print("Exception when calling Margin API: %s\n" % e.body)
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 instruments =[new UpstoxClient.Instrument("MCX_FO|435356",1,"D","BUY")];
let postMarginRequest = new UpstoxClient.MarginRequest(instruments)
apiInstance.postMargin(postMarginRequest, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log(data);
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.*;
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 api = new ChargeApi();
MarginRequest marginRequest = new MarginRequest();
Instrument instrument = new Instrument();
instrument.setInstrumentKey("MCX_FO|435356");
instrument.setQuantity(1);
instrument.setProduct("D");
instrument.setTransactionType("BUY");
marginRequest.addInstrumentsItem(instrument);
try {
PostMarginResponse response = api.postMargin(marginRequest);
System.out.println(response);
} catch (ApiException e) {
System.err.println("Exception when calling Margin API " + e.getResponseBody());
e.printStackTrace();
}
}
}
Get margin details for currency delivery orders
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl -X 'POST' \
'https://api.upstox.com/v2/charges/margin' \
-H 'accept: application/json' \
-H 'Authorization: Bearer {your_access_token}' \
-H 'Content-Type: application/json' \
-d '{
"instruments": [
{
"instrument_key": "NCD_FO|15758",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}'
import requests
url = "https://api.upstox.com/v2/charges/margin"
headers = {
"accept": "application/json",
"Authorization": "Bearer {your_access_token}",
"Content-Type": "application/json"
}
data = {
"instruments": [
{
"instrument_key": "NCD_FO|15758",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/charges/margin';
const headers = {
'accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
'Content-Type': 'application/json'
};
const data = {
instruments: [
{
instrument_key: 'NCD_FO|15758',
quantity: 1,
transaction_type: 'BUY',
product: 'D'
}
]
};
axios.post(url, data, { headers })
.then(response => {
console.log(response.status);
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;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class Main {
public static void main(String[] args) {
String url = "https://api.upstox.com/v2/charges/margin";
String token = "Bearer {your_access_token}";
String json = """
{
"instruments": [
{
"instrument_key": "NCD_FO|15758",
"quantity": 1,
"transaction_type": "BUY",
"product": "D"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("accept", "application/json")
.header("Authorization", token)
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json))
.build();
try {
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("Status code: " + response.statusCode());
System.out.println("Response body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/charges/margin';
$token = 'Bearer {your_access_token}';
$data = [
"instruments" => [
[
"instrument_key" => "NCD_FO|15758",
"quantity" => 1,
"transaction_type" => "BUY",
"product" => "D"
]
]
];
$headers = [
'Accept: application/json',
'Authorization: ' . $token,
'Content-Type: application/json'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status code: " . $httpStatusCode . PHP_EOL;
echo "Response body: " . $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.ChargeApi(upstox_client.ApiClient(configuration))
instruments = [upstox_client.Instrument(instrument_key="NCD_FO|15758",quantity=5,product="D",transaction_type="BUY")]
margin_body = upstox_client.MarginRequest(instruments)
try:
api_response = api_instance.post_margin(margin_body)
print(api_response)
except ApiException as e:
print("Exception when calling Margin API: %s\n" % e.body)
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 instruments =[new UpstoxClient.Instrument("NCD_FO|15758",1,"D","BUY")];
let postMarginRequest = new UpstoxClient.MarginRequest(instruments)
apiInstance.postMargin(postMarginRequest, (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log(data);
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.*;
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 api = new ChargeApi();
MarginRequest marginRequest = new MarginRequest();
Instrument instrument = new Instrument();
instrument.setInstrumentKey("NCD_FO|15758");
instrument.setQuantity(1);
instrument.setProduct("D");
instrument.setTransactionType("BUY");
marginRequest.addInstrumentsItem(instrument);
try {
PostMarginResponse response = api.postMargin(marginRequest);
System.out.println(response);
} catch (ApiException e) {
System.err.println("Exception when calling Margin API " + e.getResponseBody());
e.printStackTrace();
}
}
}