Margin Details
This API provides the functionality to retrieve the margin for an instrument. It accepts input parameters like the instrument, quantity, transaction_type and product.
Margin fields that are not applicable will be set to zero for a given instrument. A maximum of 20 instruments is allowed per request
Request
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"
}
]
}'
Additional samples in various languages are available in the Sample Code section on this page.
Request Body
| Name | Required | Type | Description |
|---|---|---|---|
| instruments | true | array | Request instruments for margin details. |
| instruments[].instrument_key | true | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
| instruments[].quantity | true | integer (int32) | Quantity with which the order is to be placed. It should be multiple of lot size. |
| instruments[].product | true | string | Product with which the order is to be placed. Possible values: I, D, CO, MTF. |
| instruments[].transaction_type | true | string | Indicates whether its a buy or sell order. Possible values: BUY, SELL. |
| instruments[].price | false | number (float) | Price with which the order is to be placed |
Responses
- 200
- 4XX
Response Body
- EQ
- Futures
- Options
- MCX
- Currency
{
"status": "success",
"data": {
"margins": [
{
"span_margin": 0,
"exposure_margin": 0,
"equity_margin": 33.6,
"net_buy_premium": 0,
"additional_margin": 0,
"total_margin": 33.6,
"tender_margin": 0
}
],
"required_margin": 33.6,
"final_margin": 33.6
}
}
{
"status": "success",
"data": {
"margins": [
{
"span_margin": 57501.5,
"exposure_margin": 12320.55,
"equity_margin": 0,
"net_buy_premium": 0,
"additional_margin": 0,
"total_margin": 69822.05,
"tender_margin": 0
}
],
"required_margin": 69822.05,
"final_margin": 69822.05
}
}
{
"status": "success",
"data": {
"margins": [
{
"span_margin": 0,
"exposure_margin": 0,
"equity_margin": 0,
"net_buy_premium": 1950,
"additional_margin": 0,
"total_margin": 1950,
"tender_margin": 0
}
],
"required_margin": 1950,
"final_margin": 1950
}
}
{
"status": "success",
"data": {
"margins": [
{
"span_margin": 436,
"exposure_margin": 91.5,
"equity_margin": 0,
"net_buy_premium": 0,
"additional_margin": 146.4,
"total_margin": 673.9,
"tender_margin": 0
}
],
"required_margin": 673.9,
"final_margin": 673.9
}
}
{
"status": "success",
"data": {
"margins": [
{
"span_margin": 1257.32,
"exposure_margin": 418.01,
"equity_margin": 0,
"net_buy_premium": 0,
"additional_margin": 0,
"total_margin": 1675.33,
"tender_margin": 0
}
],
"required_margin": 1675.3325,
"final_margin": 1675.3325
}
}
Field Description
| Name | Type | Description |
|---|---|---|
| status | string | A string indicating the outcome of the request. Typically success for successful operations. |
| data | object | Response data for margin |
| data.required_margin | float | Total margin required to execute the orders. |
| data.final_margin | float | Total margin after margin benefit. |
| data.margins | array | Response data for instrument margin. details. |
| data.margins[].equity_margin | float | Margin applicable for any equity trades |
| data.margins[].total_margin | float | Total margin required for the basket. It will be applicable for all the segments. |
| data.margins[].exposure_margin | float | Exposure margin - Based on ELM percentage values provided by exchange. It will be applicable only on FNO trades. |
| data.margins[].tender_margin | float | Tender margin - It is applicable as the futures contract approaches its expiration date. |
| data.margins[].span_margin | float | Span Margin - Upfront margin mandatory by exchange for derivatives trade. It will be applicable only on FNO trades. |
| data.margins[].net_buy_premium | float | Net Buy Premium - Option premium required. |
| data.margins[].additional_margin | float | Additional margin - Application margin applicable on MCX FNO trade for certain commodities. |
Error codes
| Error code | Description |
|---|---|
| UDAPI1054 | The product is invalid - The provided value for product is not acceptable |
| UDAPI1057 | The transaction_type is invalid - The given value for transaction_type is not valid |
| UDAPI1095 | Price must be greater than zero - Please provide a valid price field |
| UDAPI1096 | Quantity cannot be less than or equal to zero - The quantity field needs to be greater than zero |
| UDAPI1097 | The quantity is required - The quantity field needs to be provided |
| UDAPI1098 | Instrument invalid format - The instrument_token is of invalid format |
| UDAPI1099 | Instrument key is required - The instrument key is missing |
| UDAPI1100 | The product is required - The product is missing |
| UDAPI1101 | The transaction_type is required - The transaction_type is missing |
| UDAPI1102 | The instrument limit has been exceeded - 20 instruments at a time are allowed in a single request |
| UDAPI1103 | Instrument key cannot be duplicated - Same instrument key cannot be repeated |
Sample Code
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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
Loading...