pocketful logo light
pocketful logo light

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 NameValueDescription
AuthorizationBearer <your_access_token>Valid Bearer access token for authentication
clientid<client_id>Unique client identifier
Content-Typeapplication/jsonFormat of the request body
acceptapplication/jsonResponse 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 NameData TypeDescription
exchangeStringExchange segment where the order is to be placed (e.g. NFO, BFO, NSE, BSE, MCX).
modeStringOrder lifecycle mode. Typically NEW for new orders or MODIFY for order amendments.
priceStringLimit price for margin calculation. Feed "0" or current market price for market orders.
productStringProduct type identifier (e.g. "2" for NRML, or "MIS", "CNC").
quantityStringTotal quantity/lot size to be traded.
segmentStringMarket segment (FutOpt for Futures & Options, Capital for Equity Cash).
seriesStringInstrument series (e.g. FUTSTK, FUTIDX, OPTSTK, OPTIDX, EQ).
sideStringTransaction side: BUY or SELL.
symbolStringTrading symbol of the instrument (e.g. ADANIENT26SEPFUT).
tokenStringUnique instrument token of the contract (e.g. 68417).
underlyingStringUnique 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

KeyData TypeDescription
statusBooleanIndicates whether the request was successful (true or false).
messageStringServer response status message (SUCCESS on successful execution).
errorcodeStringSpecific error code returned by the system (empty when successful).
dataObjectMain container holding the combined and individual margin calculations.
combinedMarginObjectAggregate margin breakdown for the entire basket taking into account offsetting positions.
deliveryMarginFloatMargin blocked towards physical settlement/delivery obligation for expiring derivatives.
spanFloatStandardized Portfolio Analysis of Risk (SPAN) margin requirement.
somtierMarginFloatSecond Order Margin (SOM) tier margin required for contracts in tender/expiry periods.
additionalMarginFloatRegulatory or exchange-mandated additional surveillance margin requirement.
spanSpreadMarginFloatSpread margin benefit or requirement for offsetting calendar/hedge positions.
varMarginFloatValue at Risk (VaR) margin calculated to cover probable daily market price swings.
exposureMarginFloatMargin levied above SPAN margin to safeguard against extreme market fluctuations.
premiumMarginFloatPremium amount required to purchase option contracts.
premiumBenefitFloatBenefit credit applied to the required margin from offsetting/sold option premiums.
extremeLossMarginFloatExtreme Loss Margin (ELM) to protect against severe tail-risk events.
maxSpanFloatMaximum SPAN margin across multiple portfolio stress test scenarios.
netSpanFloatNet effective SPAN margin after applying portfolio spread benefits and hedging credits.
netSpanArrayArrayScenario-wise breakdown of net SPAN margin values if applicable.
compositeDeltaFloatCombined net delta of the portfolio basket representing overall directional exposure.
futureBuyQuantityIntegerTotal quantity of long (Buy) futures contracts in the basket.
futureSellQuantityIntegerTotal quantity of short (Sell) futures contracts in the basket.
optionSellQuantityIntegerTotal quantity of short (Sell) option contracts in the basket.
optionBuyQuantityIntegerTotal quantity of long (Buy) option contracts in the basket.
underlyingTokenIntegerUnique identifier token of the underlying scrip.
somRateFloatSecond Order Margin (SOM) rate percentage applied to the contract.
spreadRateFloatSpread margin rate applied to the hedged contract pair.
individualMarginValuesArrayDetailed 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": {}
}