Margin calculation?

healthsecure15
I read this: https://kite.trade/docs/connect/v3/margins/

Seems very interesting. I cannot find the python call for it.

I tried:

kite.margins([
{
"exchange": "NSE",
"tradingsymbol": "INFY",
"transaction_type": "BUY",
"variety": "regular",
"product": "CNC",
"order_type": "MARKET",
"quantity": 1,
"price": 0,
"trigger_price": 0

}
])

Which gave the obvious output. What would be the correct call for calculation of margin as per the kite.trade doc linked above?

Thanks
  • rakeshr
    I cannot find the python call for it.
    You can use order_margin method to make the order margin calculation call. You can refer python example code for the same here.
  • mayankk
    @rakeshr can you please help answer how to get the margin for the basket order. I used order_margins for multiple orders but it only gives the individual orders margin. How do I get the final margin for the basket using python. appreciate your help thanks
  • mlearner
    You can use order_margin method to make the order margin calculation call. You can refer python example code for the same here.
    @rakeshr - The python call as mentioned in sample code is not working for me.
    margin_detail = kite.order_margins(order_param_single)
    Getting below error -
    INFO:root:Required order margin: 'KiteConnect' object has no attribute 'order_margins'
    Also for basket orders, will "kite.order_margins()" work or the python call is "kite.basket_margins()"?
  • rakeshr
    INFO:root:Required order margin: 'KiteConnect' object has no attribute 'order_margins'
    You need to update your package using pip install --upgrade kiteconnect.
    Also for basket orders, will "kite.order_margins()" work or the python call is "kite.basket_margins()"?
    Also for basket orders, will "kite.order_margins()" work or the python call is "kite.basket_margins()"?
    We haven't added basket margins APIs to python client, as of now. You will have to use requests to use this, for now. We will add this to python client soon.
  • akshay_thakker
    akshay_thakker edited March 2022
    Hi Rakeshr,
    I am getting a `TypeError: order_margins() got an unexpected keyword argument 'mode'` error when i use the mode='compact' argument. Code is as below
    def order_margin():
    order_param_single = [{
    "exchange": "NFO",
    "tradingsymbol": "NIFTY22MARFUT",
    "transaction_type": "BUY",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 50
    }]
    margin = kite.order_margins(order_param_single, mode='compact')
    return margin

    Also how do i post formatted code into the comments?

    and finally isnt a format similar to
    kite.place_order(variety='regular', exchange='NFO', tradingsymbol='NIFTY22MARFUT'
    transaction_type='BUY', quantity=100, product='MIS', order_type=kite.ORDER_TYPE_LIMIT, price=200) easier to use for the kite.order_margins() format as well?
  • rakeshr
    I am getting a `TypeError: order_margins() got an unexpected keyword argument 'mode'` error when i use the
    You would be on an older version of the python kiteconnect client. You can upgrade the package using:
    pip install kiteconnect --upgrade
  • akshay_thakker
    akshay_thakker edited March 2022
    Thanks for a prompt response.
    upgraded to kiteconnect 4.0 but still gives the same error.
    Also can you please tell me how to put in formatted code into my posts?
  • sujith
    You can select code block and click on dropdown next to list formatter and then select code.


  • akshay_thakker
    Thanks Sujith
    BTW do you think it makes sense to convert the format for kite.order_margin() to a format similar to
    kite.place_order(variety='regular', exchange='NFO', tradingsymbol='NIFTY22MARFUT'
    transaction_type='BUY', quantity=100, product='MIS', order_type=kite.ORDER_TYPE_LIMIT, price=200)
    easier to use for the kite.order_margins() format as well?
  • stockants
    order_param_single =[{"exchange": "NFO",
    "tradingsymbol": "NIFTY22AUG13800CE",
    "transaction_type": "sell",
    "variety": "regular",
    "product": "MIS",
    "order_type": "MARKET",
    "quantity": 50}]



    {'NFO:NIFTY22AUG13800CE': {'instrument_token': 10204674, 'last_price': 4165.85}}
    [{'type': 'equity', 'tradingsymbol': 'NIFTY22AUG13800CE', 'exchange': 'NFO', 'span': 0, 'exposure': 0, 'option_premium': 208292.50000000003, 'additional': 0, 'bo': 0, 'cash': 0, 'var': 0, 'pnl': {'realised': 0, 'unrealised': 0}, 'leverage': 1, 'total': 208292.50000000003}]


    getting wrong total


    data validated from zerodha margin calculator

    Premium receivable ? Rs. 2,08,293

    Total margin ? Rs. 3,18,520




  • SRIJAN
    You are using incorrect value for transaction_type.

    It should be in upper case.
  • stockants
    Thanks @SRIJAN i made change still getting different values.

    my code:
    order_param_single = [{
    "exchange": "NFO",
    "tradingsymbol": "BANKNIFTY2290135500PE",
    "transaction_type": "SELL",
    "variety": "regular",
    "product": "NRML",
    "order_type": "MARKET",
    "quantity": 25,
    }]

    margin_detail = kite.order_margins(order_param_single)
    print(margin_detail)
    logging.info("Required margin for single order: {}".format(order_param_single))




    Response:

    [{'type': 'equity', 'tradingsymbol': 'BANKNIFTY2290135500PE', 'exchange': 'NFO', 'span': 59336.755000000005, 'exposure': 30131.43975, 'option_premium': 0, 'additional': 0, 'bo': 0, 'cash': 0, 'var': 0, 'pnl': {'realised': 0, 'unrealised': 0}, 'leverage': 1, 'total': 89468.19475000001}]

    Response from zerodha calculator:

    Span Rs. 58,008

    Exposure margin Rs. 29,532

    Premium receivable ? Rs. 153

    Total margin ? Rs. 87,540
  • stockants
    Thanks for prompt reply.
Sign In or Register to comment.