ALGO failed due to Margin requirement

ganeshv02 edited February 19 in General
My algo was not able to execute the order for BANDHAN futures today (19/02/2021). The order placement was rejected due to below error. As per zerodha margin calculator the margin required is only 2.73 LAKHS while the kite api expects around 9 LAKHS. Am I missing something @sujith ?

2021-02-19 12:15:09,068 : INFO : MainThread : Order details:
{'average_price': 0,
'cancelled_quantity': 0,
'disclosed_quantity': 0,
'exchange': 'NFO',
'exchange_order_id': None,
'exchange_timestamp': None,
'exchange_update_timestamp': None,
'filled_quantity': 0,
'guid': '18652Xt2BkTOQY7f1m',
'instrument_token': 15499778,
'market_protection': 0,
'meta': {},
'order_id': '210219202308390',
'order_timestamp': datetime.datetime(2021, 2, 19, 12, 15, 10),
'order_type': 'MARKET',
'parent_order_id': None,
'pending_quantity': 0,
'placed_by': 'ZX7461',
'price': 0,
'product': 'NRML',
'quantity': 1800,
'status': 'REJECTED',
'status_message': 'Insufficient funds. Required margin is 951250.94 but '
'available margin is 947366.90. Check the orderbook for '
'open orders.',
'status_message_raw': 'RMS:Margin Exceeds,Required:951250.94, '
'Available:947366.90 for entity account-ZX7461 across '
'exchange across segment across product ',

'tradingsymbol': 'BANDHANBNK21FEBFUT',
'transaction_type': 'BUY',
'trigger_price': 0,
'validity': 'DAY',
'variety': 'regular'}
  • rakeshr
    Were you having any open orders?
    Margin calculation considers open positions and open orders as well to calculate the final margin. You can check documentation here.
  • sujith
    You seem to be placing an NRML order, are you sure you are checking the margin requirement for the NRML product type?
  • ganeshv02
    @rakeshr - I did not have any open orders for Bandhan at that point of time. The issue again happened again this morning. my position book was completely empty. The order went through after I added 1 more lakh to my account.

    @sujith - I have attached Zerodha margin calculator screenshot. There is no product type in the margin calculator. Btw, I am using the same algo for 6 months now.

  • themohammedfaisal
    themohammedfaisal edited February 23
    Hi @ganeshv02 ,
    I went through your orders and positions for 19th Feb, I believe you had 2 other open positions before initiating this order. In the rejection that you get, you see Required margin and Available margin, the margin shortfall is for 4K only. Required margin is cumulative of all open positions that you have as well the new order being placed. This could be due to the LTP fluctuation or if the margin has gone up after the 2nd SPAN file upload that happens at around 12 PM.
  • ganeshv02
    Thanks @themohammedfaisal for the detailed explanation. Yes I had 2 other orders - One for NIFTY and other for INDUSIND future. As you said, probably there was a fluctuation in the margin requirement and I was just short of few thousand rupees. I will keep some buffer going forward.
This discussion has been closed.