@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
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.
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?
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?
margin_detail = kite.order_margins(order_param_single) print(margin_detail) logging.info("Required margin for single order: {}".format(order_param_single))
order_margin
method to make the order margin calculation call. You can refer python example code for the same here.pip install --upgrade kiteconnect
. 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.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?
pip install kiteconnect --upgrade
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?
BTW do you think it makes sense to convert the format for
kite.order_margin()
to a format similar to easier to use for the kite.order_margins() format as well?"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
It should be in upper case.
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
The margin you get from API is the correct one always.