Margin Calculator
The Margin Calculator API calculates the precise margin requirements for a single order or a multi-leg basket of orders before placing trades in the market. It provides a comprehensive breakdown of portfolio-level margins including SPAN margin, Exposure margin, Delivery margin, VaR margin, Extreme Loss Margin (ELM), Option Premium margin, and spread benefits for hedged futures and options strategies.
Algorithmic traders and risk management systems can use this endpoint to ensure sufficient account balance and determine capital efficiency before order execution.
Endpoint: /api/space/v1/orderapis/marginCalculations
Method-Type: POST
Headers
| Header Name | Value | Description |
|---|---|---|
| Authorization | Bearer <your_access_token> | Valid Bearer access token for authentication |
| clientid | <client_id> | Unique client identifier |
| Content-Type | application/json | Format of the request body |
| accept | application/json | Response content type format |
Request Body
The request payload accepts a data array containing one or more order objects to calculate individual and combined portfolio margins.
{
"data": [
{
"exchange": "NFO",
"mode": "NEW",
"price": "2939.7",
"product": "2",
"quantity": "309",
"segment": "FutOpt",
"series": "FUTSTK",
"side": "BUY",
"symbol": "ADANIENT26SEPFUT",
"token": "68417",
"underlying": "25"
},
{
"exchange": "NFO",
"mode": "NEW",
"price": "2954",
"product": "2",
"quantity": "309",
"segment": "FutOpt",
"series": "FUTSTK",
"side": "SELL",
"symbol": "ADANIENT26OCTFUT",
"token": "48711",
"underlying": "25"
}
]
}
Request Parameters
| Field Name | Data Type | Description |
|---|---|---|
exchange | String | Exchange segment where the order is to be placed (e.g. NFO, BFO, NSE, BSE, MCX). |
mode | String | Order lifecycle mode. Typically NEW for new orders or MODIFY for order amendments. |
price | String | Limit price for margin calculation. Feed "0" or current market price for market orders. |
product | String | Product type identifier (e.g. "2" for NRML, or "MIS", "CNC"). |
quantity | String | Total quantity/lot size to be traded. |
segment | String | Market segment (FutOpt for Futures & Options, Capital for Equity Cash). |
series | String | Instrument series (e.g. FUTSTK, FUTIDX, OPTSTK, OPTIDX, EQ). |
side | String | Transaction side: BUY or SELL. |
symbol | String | Trading symbol of the instrument (e.g. ADANIENT26SEPFUT). |
token | String | Unique instrument token of the contract (e.g. 68417). |
underlying | String | Unique instrument token of the underlying asset (e.g. 25). |
Example
order_basket = [
{
"exchange": "NFO",
"mode": "NEW",
"price": "2939.7",
"product": "2",
"quantity": "309",
"segment": "FutOpt",
"series": "FUTSTK",
"side": "BUY",
"symbol": "ADANIENT26SEPFUT",
"token": "68417",
"underlying": "25"
},
{
"exchange": "NFO",
"mode": "NEW",
"price": "2954",
"product": "2",
"quantity": "309",
"segment": "FutOpt",
"series": "FUTSTK",
"side": "SELL",
"symbol": "ADANIENT26OCTFUT",
"token": "48711",
"underlying": "25"
}
]
response = pocket.calculateMargin(order_basket)
Example cURL Request
curl -X 'POST' \
'https://algo.pocketful.in/api/space/v1/orderapis/marginCalculations' \
-H 'accept: application/json' \
-H 'clientid: <client_id>' \
-H 'Authorization: Bearer <your_access_token>' \
-H 'Content-Type: application/json' \
-d '{
"data": [
{
"exchange": "NFO",
"mode": "NEW",
"price": "2939.7",
"product": "2",
"quantity": "309",
"segment": "FutOpt",
"series": "FUTSTK",
"side": "BUY",
"symbol": "ADANIENT26SEPFUT",
"token": "68417",
"underlying": "25"
},
{
"exchange": "NFO",
"mode": "NEW",
"price": "2954",
"product": "2",
"quantity": "309",
"segment": "FutOpt",
"series": "FUTSTK",
"side": "SELL",
"symbol": "ADANIENT26OCTFUT",
"token": "48711",
"underlying": "25"
}
]
}'
Response
{
"status": true,
"message": "SUCCESS",
"errorcode": "",
"data": {
"combinedMargin": {
"deliveryMargin": 0,
"span": 0,
"somtierMargin": 0,
"additionalMargin": 0,
"spanSpreadMargin": 0,
"varMargin": 0,
"exposureMargin": 0,
"premiumMargin": 0,
"premiumBenefit": 0,
"extremeLossMargin": 0,
"maxSpan": 0,
"netSpan": 0,
"netSpanArray": null,
"compositeDelta": 0,
"futureBuyQuantity": 0,
"futureSellQuantity": 0,
"optionSellQuantity": 0,
"optionBuyQuantity": 0,
"underlyingToken": 0,
"somRate": 0,
"spreadRate": 0
},
"individualMarginValues": []
}
}
Response Parameters
| Key | Data Type | Description |
|---|---|---|
status | Boolean | Indicates whether the request was successful (true or false). |
message | String | Server response status message (SUCCESS on successful execution). |
errorcode | String | Specific error code returned by the system (empty when successful). |
data | Object | Main container holding the combined and individual margin calculations. |
combinedMargin | Object | Aggregate margin breakdown for the entire basket taking into account offsetting positions. |
deliveryMargin | Float | Margin blocked towards physical settlement/delivery obligation for expiring derivatives. |
span | Float | Standardized Portfolio Analysis of Risk (SPAN) margin requirement. |
somtierMargin | Float | Second Order Margin (SOM) tier margin required for contracts in tender/expiry periods. |
additionalMargin | Float | Regulatory or exchange-mandated additional surveillance margin requirement. |
spanSpreadMargin | Float | Spread margin benefit or requirement for offsetting calendar/hedge positions. |
varMargin | Float | Value at Risk (VaR) margin calculated to cover probable daily market price swings. |
exposureMargin | Float | Margin levied above SPAN margin to safeguard against extreme market fluctuations. |
premiumMargin | Float | Premium amount required to purchase option contracts. |
premiumBenefit | Float | Benefit credit applied to the required margin from offsetting/sold option premiums. |
extremeLossMargin | Float | Extreme Loss Margin (ELM) to protect against severe tail-risk events. |
maxSpan | Float | Maximum SPAN margin across multiple portfolio stress test scenarios. |
netSpan | Float | Net effective SPAN margin after applying portfolio spread benefits and hedging credits. |
netSpanArray | Array | Scenario-wise breakdown of net SPAN margin values if applicable. |
compositeDelta | Float | Combined net delta of the portfolio basket representing overall directional exposure. |
futureBuyQuantity | Integer | Total quantity of long (Buy) futures contracts in the basket. |
futureSellQuantity | Integer | Total quantity of short (Sell) futures contracts in the basket. |
optionSellQuantity | Integer | Total quantity of short (Sell) option contracts in the basket. |
optionBuyQuantity | Integer | Total quantity of long (Buy) option contracts in the basket. |
underlyingToken | Integer | Unique identifier token of the underlying scrip. |
somRate | Float | Second Order Margin (SOM) rate percentage applied to the contract. |
spreadRate | Float | Spread margin rate applied to the hedged contract pair. |
individualMarginValues | Array | Detailed breakdown of individual margin requirements for each instrument in the order list. |
Error Response
{
"status": false,
"message": "Invalid request parameters or unauthorized",
"errorcode": "40001",
"data": {}
}