Skip to content

Margin ​

Calculate margin requirement for a basket of positions. Useful for pre-trade margin checks.

Endpoint URL ​

http
Local Host   :  POST http://127.0.0.1:5000/api/v1/margin
Ngrok Domain :  POST https://<your-ngrok-domain>.ngrok-free.app/api/v1/margin
Custom Domain:  POST https://<your-custom-domain>/api/v1/margin

Sample API Request ​

json
{
  "apikey": "<your_app_apikey>",
  "positions": [
    {
      "symbol": "NIFTY25NOV2525000CE",
      "exchange": "NFO",
      "action": "BUY",
      "product": "NRML",
      "pricetype": "MARKET",
      "quantity": "65"
    },
    {
      "symbol": "NIFTY25NOV2525500CE",
      "exchange": "NFO",
      "action": "SELL",
      "product": "NRML",
      "pricetype": "MARKET",
      "quantity": "65"
    }
  ]
}

Sample cURL Request ​

bash
curl -X POST http://127.0.0.1:5000/api/v1/margin \
  -H 'Content-Type: application/json' \
  -d '{
  "apikey": "<your_app_apikey>",
  "positions": [
    {
      "symbol": "NIFTY25NOV2525000CE",
      "exchange": "NFO",
      "action": "BUY",
      "product": "NRML",
      "pricetype": "MARKET",
      "quantity": "65"
    },
    {
      "symbol": "NIFTY25NOV2525500CE",
      "exchange": "NFO",
      "action": "SELL",
      "product": "NRML",
      "pricetype": "MARKET",
      "quantity": "65"
    }
  ]
}'

Sample API Response ​

json
{
  "status": "success",
  "data": {
    "total_margin_required": 91555.7625,
    "span_margin": 0.0,
    "exposure_margin": 91555.7625
  }
}

Request Body ​

ParameterDescriptionMandatory/OptionalDefault Value
apikeyYour Tradeboard API keyMandatory-
positionsArray of 1 to 50 position objectsMandatory-

MarginCalculatorSchema declares only apikey and positions. Any other top-level field returns HTTP 400.

Position Object Fields ​

FieldDescriptionMandatory/OptionalDefault Value
symbolTrading symbol, 1 to 50 charactersMandatory-
exchangeAny value in the shared VALID_EXCHANGES listMandatory-
actionBUY or SELL (lowercase accepted)Mandatory-
quantityPosition quantity, sent as a stringMandatory-
productProduct type: MIS, CNC, NRMLMandatory-
pricetypePrice type: MARKET, LIMIT, SL, SL-MMandatory-
priceOrder price, sent as a stringOptional"0"
trigger_priceTrigger price, sent as a stringOptional"0"

quantity, price, and trigger_price are declared as string fields to match the existing API contract; their numeric ranges are checked in the service layer, not by marshmallow. Sending them as JSON numbers returns HTTP 400. These eight keys are the whole item schema; anything else returns HTTP 400 for the entire request.

Response Fields ​

FieldTypeDescription
statusstring"success" or "error"
dataobjectMargin calculation results

Data Object Fields ​

FieldTypeDescription
total_margin_requirednumberTotal margin required for the basket
span_marginnumberSPAN margin component. 0 for brokers that do not break it out
exposure_marginnumberExposure margin component. 0 for brokers that do not break it out
margin_benefitnumberMargin benefit from hedged positions. Broker-dependent: only some broker mappers emit this key, so treat it as optional

Notes ​

  • Between 1 and 50 positions per request
  • Margin calculation includes hedging benefits for spread positions
  • Actual margin may vary slightly due to real-time price changes
  • Brokers without a margin_api module return HTTP 501 with a "not supported" message
  • Use this for pre-trade validation to check if sufficient margin exists

Use Cases ​

  • Pre-trade check: Verify margin before placing orders
  • Strategy planning: Calculate margin for option strategies
  • Risk management: Understand margin exposure

Example: Iron Condor Margin ​

json
{
  "apikey": "<your_app_apikey>",
  "positions": [
    {"symbol": "NIFTY25NOV2526500CE", "exchange": "NFO", "action": "SELL", "quantity": "65", "product": "NRML", "pricetype": "MARKET"},
    {"symbol": "NIFTY25NOV2527000CE", "exchange": "NFO", "action": "BUY", "quantity": "65", "product": "NRML", "pricetype": "MARKET"},
    {"symbol": "NIFTY25NOV2525500PE", "exchange": "NFO", "action": "SELL", "quantity": "65", "product": "NRML", "pricetype": "MARKET"},
    {"symbol": "NIFTY25NOV2525000PE", "exchange": "NFO", "action": "BUY", "quantity": "65", "product": "NRML", "pricetype": "MARKET"}
  ]
}

Back to: API Documentation