Span Margin
POST /spanMargin
The Span Margin API calculates the margin requirements for derivative contracts like futures and options on an exchange. By taking a list of requests that specify the contracts, it processes the data and returns the total margin required for those contracts. This ensures that traders maintain sufficient capital to cover potential losses. The API helps in efficient risk management by determining how much margin needs to be set aside based on the positions held. This functionality is essential for traders and brokers to comply with exchange regulations and manage risk exposure effectively.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
exchange | string | true | Name of the exchange. |
tradingSymbol | string | true | Trading Symbol of the scrip. |
qty | string | true | Quantity asked for margin. |
transactionType | string | false | Price is mandatory for single scrip. If not provided, default is considered as SELL. |
price | string | false | Price is mandatory for single scrip. |
productType | string | true | The product type of the order. It can be CNC (Cash and Carry), NRML (Normal), or MIS (Intraday). |
orderType | string | true | The type of order. It can be one of the following: L (Limit Order), SL (Stop Loss Limit). |
Sample Request Body
json
requestBody={
"request":[
{
"exchange":"NFO",
"tradingSymbol":"NIFTY24MAR2627550CE",
"qty":"65",
"transactionType":"BUY",
"price" :"6.15",
"productType" :"BO",
"orderType" :"L"
}
]
}Sample Code
bash
curl -X POST 'https://tradeapi.samco.in/spanMargin' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'x-session-token: <SESSION_TOKEN>' \
-d '{"request":[{"exchange":"NFO","tradingSymbol":"NIFTY24MAR2627550CE","qty":"65","transactionType":"BUY","price":"6.15","productType":"BO","orderType":"L"}]}'java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Sample {
public static void main(String[] args) throws Exception {
String requestBody = """
{
"request": [
{
"exchange": "NFO",
"tradingSymbol": "NIFTY24MAR2627550CE",
"qty": "65",
"transactionType": "BUY",
"price": "6.15",
"productType": "BO",
"orderType": "L"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://tradeapi.samco.in/spanMargin"))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("x-session-token", "<SESSION_TOKEN>")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
HttpResponse<String> response =
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}js
(async () => {
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-session-token': '<SESSION_TOKEN>',
};
const requestBody = {
request: [
{
exchange: "NFO",
tradingSymbol: "NIFTY24MAR2627550CE",
qty: "65",
transactionType: "BUY",
price: "6.15",
productType: "BO",
orderType: "L"
}
]
};
const response = await fetch('https://tradeapi.samco.in/spanMargin', {
method: 'POST',
headers,
body: JSON.stringify(requestBody),
});
const data = await response.json();
console.log(data);
})();py
import requests
import json
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-session-token': '<SESSION_TOKEN>',
}
requestBody = {
"request": [
{
"exchange": "NFO",
"tradingSymbol": "NIFTY24MAR2627550CE",
"qty": "65",
"transactionType": "BUY",
"price": "6.15",
"productType": "BO",
"orderType": "L"
}
]
}
r = requests.post('https://tradeapi.samco.in/spanMargin',
data=json.dumps(requestBody),
headers=headers)
print(r.json())Sample Responses
json
{
"serverTime": "17/03/26 19:02:46",
"msgId": "726494be-a5ce-45d0-8e93-fbe6aa1a5b9d",
"status": "Success",
"statusMessage": "Span margin calculated",
"spanDetails": {
"estimatedBrokerage": "20.00",
"estimatedExpenses": "3.88",
"estimatedOrderValue": "423.63",
"marginRequired": "423.63",
"exposureMargin": "0.00",
"totalMargin": "423.63"
}
}Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
serverTime | string | Time at Server. |
msgId | string | This is a unique identifier for every request into the system. Please quote this identifier to the support team if you face issues with the API request. |
status | string | The status of the API response. It can be either 'Success' or 'Failure'. |
statusMessage | string | A message describing the result of the API call. |
totalRequirement | string | This is the total amount of margin required for a particular portfolio of futures and options positions. It includes the SPAN requirement, exposure margin, and any additional margin that may be required by the exchange. |
spanRequirement | string | This is the margin requirement calculated using the SPAN algorithm, which is a risk-based margining system. The SPAN requirement takes into account factors such as price volatility, correlation between different positions, and the overall risk of the portfolio. |
exposureMargin | string | Exposure margin is an additional margin that may be required by the exchange to cover potential losses beyond those accounted for by the SPAN requirement. It provides a buffer against adverse market movements and helps ensure that traders maintain sufficient margin to cover their positions. |
spreadBenefit | string | Spread benefit refers to a reduction in margin requirements that may be applied when certain offsetting positions are held in the same account. This reduction reflects the reduced risk associated with offsetting positions and encourages traders to engage in spread trading strategies. |
estimatedBrokerage | string | Projected fee charged by brokers for making a stock trade. |
estimatedExpenses | string | Projected costs for completing a stock trade, excluding brokerage fees. |
estimatedOrderValue | string | Total projected value of a stock trade before any fees. |
marginRequired | string | Funds needed to cover potential losses in a stock trade. |
totalMargin | string | The total funds needed for a leveraged stock trade equals the sum of the margin required and the exposure margin. |