Calculate Margin Requirements with SmartAPI's New Margin Calculator API


  • We are delighted to introduce the Margin Calculator API endpoint within SmartAPI. This API delivers real-time margin calculations for a basket of positions, empowering users to evaluate margin requirements prior to executing trades. This integration not only enriches your trading experience but also equips you with critical information for making well-informed hedging benefits, calculating risk-reward ratio and evaluating available funds vs required margin.

    The Margin Calculator API:

    Endpoint: https://apiconnect.angelbroking.com/rest/secure/angelbroking/margin/v1/batch
    HTTP Method: POST
    Access Rate Limit: 10 request per second
    Number of positions input in a request: You can include up to 50 positions in a single API request, streamlining the assessment of margin requirements for a basket of positions efficiently in one query.

    Margin calculations are a crucial aspect of trading, and we've made it easier than ever before. The Margin Calculator API simplifies the process, providing real-time margin calculations based on your existing positions. Plus, it gives you a detailed breakdown of margin components so you can see exactly where your requirements are coming from.

    Request Fields Description:

    To effectively use this API, it's important to understand the request fields. Here's a quick reference:

    exchange: This is an enumeration field with values like NSE, BSE, NFO, CDS, MCX, NCDEX and BFO . It's used to specify the exchange where the instrument is traded.

    qty: Enter the quantity of the instrument you want to buy or sell. In the NFO segment, specify the number of units within a lot, not the number of lots. For instance, if you plan to trade one lot of Nifty Futures (comprising 50 units), set the quantity as 50. This maintains consistency with place order requests for NFO instruments and ensures precise margin calculations.

    price: If applicable, use this field to specify the desired price for your transaction. If a specific price isn't relevant, you can set it to 0.

    productType: This field enables you to define the product type for your transaction. It's another enumeration field with options such as CARRYFORWARD, INTRADAY, DELIVERY, MARGIN, BO, and CO.

    token: Use this field to provide the symbol token. This token uniquely identifies the symbol you're trading.

    tradeType: This is also an enumeration field with values BUY or SELL. It's used to indicate whether you're buying or selling the instrument.

    Use Cases:

    Let's dive into a real-world example. Say you're planning a covered call strategy:

    Sample Request:

    {
        "positions": [
            {
                "exchange": "NFO",
                "qty": 50,  // You can specify the quantity you want to buy
                "price": 0,  // Specify the desired price if applicable, or set to 0
                "productType": "INTRADAY",  // Specify the product type
                "token": "67300",  // Token for NFO NIFTY26OCT2319500CE
                "tradeType": "BUY"  // BUY for buying position
            },
            {
                "exchange": "NFO",
                "qty": 50,  // You can specify the quantity you want to sell
                "price": 0,  // Specify the desired price if applicable, or set to 0
                "productType": "INTRADAY",  // Specify the product type
                "token": "67308",  // Token for NFO NIFTY26OCT2319700CE
                "tradeType": "SELL"  // SELL for selling position
            }
        ]
    }
    

    Sample Response:

    {
        "status": true,
        "message": "SUCCESS",
        "errorcode": "",
        "data": {
            "totalMarginRequired": 29612.35,
            "marginComponents": {
                "netPremium": 5060.0,
                "spanMargin": 0.0,
                "marginBenefit": 79876.5,
                "deliveryMargin": 0.0,
                "nonNFOMargin": 0.0,
                "totOptionsPremium": 10100.0
            },
            "marginBreakup": [
                {
                    "exchange": "NFO",
                    "productType": "INTRADAY",
                    "totalMarginRequired": 19512.35
                }
            ],
            "optionsBuy": {
                "totOptionsPremium": 10100.0,
                "optionDetails": [
                    {
                        "exchange": "NFO",
                        "productType": "INTRADAY",
                        "token": "67300",
                        "lotMultiplier": 50,
                        "optionPremium": 10100.0
                    }
                ]
            }
        }
    }
    

    Sample screenshot from Angel One Web showing margin requirement of 29612.35 for above positions:

    3ca24391-1ee1-4ba7-a907-b7aa5a206323-image.png

    This new Margin Calculator API allows you to retrieve the margin required for your positions, broken down by various components, helping you make informed trading decisions.

    If you have any questions or need assistance with using this new endpoint, please feel free to reach out to our support team.

    Happy trading!


  • @admin
    Can you tell me if the Margin API output considers current positions as well ?


  • Hi @admin and @Moderator_1 , @Moderator_2

    Just a quick question here. I am looking to be able to calculate the margin for Options via API. The above end point should work fine, but I am wondering how to implement it for Option sell position when an buy position is already open.

    As you are aware, there is a difference in margin calculations for naked sell and covered sell. So please can you give some information regarding this.

    Many Thanks

    Cyriac


  • @admin Receiving error response while posting to this API.

    Request JSON:
    { "positions":[{
    "exchange":"NFO",
    "qty":50,
    "price":0.0,
    "productType":"INTRADAY",
    "token":"67300",
    "tradeType":"BUY"
    }]
    }

    Response JSON:
    {"message":"Null or Empty Margin Data","errorcode":"AB4022","status":false,"data":null}


  • @admin What will be the request for limit orders


  • @admin I need help in api . Not able to understand