Wrong margin calculation by margin api

zhkas
I am using margin api at kite doc, and it provides me value of around 25 lakhs and also in fund tab it was showing 25 lakhs used funds.
I had around 5 lakh free funds
but still my orders got rejected and error message was to require 31 lakhs
What the hell is this?

Why are you reporting wrong margin in funds tab and margin api and it caused me loose money today, who the hell responsible for this ?

  • sujith
    Can you paste the sample request and response?
  • zhkas
    I don't have request and response from that time
    but even now, 09:54:08, it is reporting wrong margin for following request
    its is reporting 2025653.7149999999 , but it should be around 25 lakhs

    or can you please provide me the exact formula or doc where I can find margin on my own? that will be very grateful thanks

    request

    [
    {
    "exchange": "NFO",
    "tradingsymbol": "NIFTY21N0316900PE",
    "transaction_type": "BUY",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 1800,
    "price": 0,
    "trigger_price": 0
    },
    {
    "exchange": "NFO",
    "tradingsymbol": "NIFTY21N0317800CE",
    "transaction_type": "SELL",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 1500,
    "price": 0,
    "trigger_price": 0
    },
    {
    "exchange": "NFO",
    "tradingsymbol": "NIFTY21N0317800PE",
    "transaction_type": "SELL",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 1500,
    "price": 0,
    "trigger_price": 0
    },
    {
    "exchange": "NFO",
    "tradingsymbol": "NIFTY21N0318700CE",
    "transaction_type": "BUY",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 1800,
    "price": 0,
    "trigger_price": 0
    }
    ]



    response

    {
    "status": "success",
    "data": {
    "initial": {
    "type": "",
    "tradingsymbol": "",
    "exchange": "",
    "span": 2480521.62,
    "exposure": 1085692.935,
    "option_premium": 11070,
    "additional": 0,
    "bo": 0,
    "cash": 0,
    "var": 0,
    "pnl": {
    "realised": 0,
    "unrealised": 0
    },
    "leverage": 0,
    "total": 3577284.5550000006
    },
    "final": {
    "type": "",
    "tradingsymbol": "",
    "exchange": "",
    "span": 1281465.78,
    "exposure": 1085692.935,
    "option_premium": -341505,
    "additional": 0,
    "bo": 0,
    "cash": 0,
    "var": 0,
    "pnl": {
    "realised": 0,
    "unrealised": 0
    },
    "leverage": 0,
    "total": 2025653.7149999999
    },
    "orders": [
    {
    "type": "equity",
    "tradingsymbol": "NIFTY21N0316900PE",
    "exchange": "NFO",
    "span": 0,
    "exposure": 0,
    "option_premium": 5940,
    "additional": 0,
    "bo": 0,
    "cash": 0,
    "var": 0,
    "pnl": {
    "realised": 0,
    "unrealised": 0
    },
    "leverage": 1,
    "total": 5940
    },
    {
    "type": "equity",
    "tradingsymbol": "NIFTY21N0317800CE",
    "exchange": "NFO",
    "span": 2480521.62,
    "exposure": 543151.74,
    "option_premium": 0,
    "additional": 0,
    "bo": 0,
    "cash": 0,
    "var": 0,
    "pnl": {
    "realised": 0,
    "unrealised": 0
    },
    "leverage": 1,
    "total": 3023673.3600000003
    },
    {
    "type": "equity",
    "tradingsymbol": "NIFTY21N0317800PE",
    "exchange": "NFO",
    "span": 0,
    "exposure": 542541.1950000001,
    "option_premium": 0,
    "additional": 0,
    "bo": 0,
    "cash": 0,
    "var": 0,
    "pnl": {
    "realised": 0,
    "unrealised": 0
    },
    "leverage": 1,
    "total": 542541.1950000001
    },
    {
    "type": "equity",
    "tradingsymbol": "NIFTY21N0318700CE",
    "exchange": "NFO",
    "span": 0,
    "exposure": 0,
    "option_premium": 5130,
    "additional": 0,
    "bo": 0,
    "cash": 0,
    "var": 0,
    "pnl": {
    "realised": 0,
    "unrealised": 0
    },
    "leverage": 1,
    "total": 5130
    }
    ]
    }
    }
  • rakeshr
    its is reporting 2025653.7149999999 , but it should be around 25 lakhs
    We just checked the basket margin for the same order and can confirm it's showing the same around 2025653(exact to be 2018230).
    Can you let us know the source of this it should be around 25 lakhs?
  • zhkas
    It is what showing on https://opstra.definedge.com/ website

    and my orders were rejected by stating the reason of requirement of 31 lakhs at the time, while your api was providing me 25 lakhs requirement

    so i checked on opstra, and there it was showing 31 lakhs which was reported in the rejection reason

    so, your RMS might be reporting correct margin, that's why rejecting orders, but your api giving me wrong calculation

    this caused me 48K loss
  • zhkas
    Can you please refer me some doc to calculate it on my side?
    This will be very helpful
  • zhkas
    HI, any update @rakeshr
  • themohammedfaisal
    Hey @zhkas,
    This happens if you create a 3 legged portfolio and the margin benefit is fully passed on after the position is created(not when the 3rd leg order is placed). This is done to ensure that the margin doesn't significantly go up if the client closes the margin benefit position before the full portfolio is created.

  • zhkas
    zhkas edited November 2021
    My orders are like this
    step 1 : long 1PE + long 1CE ( once entered not exiting these long positions )

    step 2 : short 1PE + short 1CE (both of same strike)
    till here margin was showing around 24 lakhs used + 5 lakhs free

    step 3 : exit from step 2 short positions

    step 4 : short 1PE + short 1CE (again both of same strike, but one strike difference from step 2)
    only one leg 1CE got executed , but other leg 1PE got rejected stating , I need 31 lakhs margin

    I am not able to understand why margin spiked to 31 lakhs for almost same risk
    also, margin api was saying 24 lakhs requirement for the full basket on step 4
    why margin api reporting wrong margin requirement
    or
    I am not interpreting the output of margin api correctly ?

    Thanks
  • zhkas



    In the screenshot you can see, that available margin is 2,71,158.75 or used margin : 27,65,651.25 as reported in fund tab
    this is the same margin reported by margin api

    but it is not allowing selling one lot of nifty, because wrong margin is being shown in fund tab
    margin requirement in rejection error is correct as per other websites margin reporting

    please fix it, show the correct margin in fund tab or margin api response
  • chandan1312
    chandan1312 edited February 2023
    Hi team, I am getting correct margins for following bucket:

    order_param_basket = [
    {
    "exchange": "NFO",
    "tradingsymbol": "NIFTY2330217450CE",
    "transaction_type": "BUY",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 50
    },{
    "exchange": "NFO",
    "tradingsymbol": "NIFTY2330217950CE",
    "transaction_type": "SELL",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 50
    }]

    But when I create a similar spread with puts, the margin figure I get is way off:
    order_param_basket = [
    {
    "exchange": "NFO",
    "tradingsymbol": "NIFTY2330216900PE",
    "transaction_type": "BUY",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 50
    },{
    "exchange": "NFO",
    "tradingsymbol": "NIFTY2330217400PE",
    "transaction_type": "SELL",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 50
    }]

    I am fetching margins using following command:
    margin_amount_comt = kite.basket_order_margins(order_param_basket, mode='compact')
    margin_per_lot = margin_amount_comt['final']['total']

    Any idea why this might be happening?
  • sujith
    Can you paste the complete debug logs with request and response?
  • sujith
    PS: Make sure to remove app and client specific tokens.
  • chandan1312
    I am not getting any bug. Just getting a wrong answer for the margin.

    Sell 1 lot: NIFTY2330217500CE
    Buy 1 lot: NIFTY2330218000CE

    But as you can check in screenshot, the margin is different as shown in zerodha app.

    And in the code that I am running, the margin value I am getting is different:


  • sujith
    Did you try include positions on UI?
Sign In or Register to comment.