Sell order for an Option Buy trade was throwing margin error

dgangwar
Hi,

I had an Option Buy trade for BANKNIFTY2350443400CE and at 15:15:03, I was trying to close that trade by placing Sell order for BANKNIFTY2350443400CE using the below-mentioned parameters. But I got this error "Insufficient funds. Required margin is 2608519.58 but available margin is 717962.80. Check the orderbook for open orders." Even though, I was able to close that manually using the UI.

Could anyone help me what could be the issue with my order?

Open Buy Order:
{'tradingsymbol': 'BANKNIFTY2350443400CE', 'exchange': 'NFO', 'instrument_token': 14554114, 'product': 'MIS', 'quantity': 450, 'overnight_quantity': 0, 'multiplier': 1, 'average_price': 137.725, 'close_price': 0, 'last_price': 235.15, 'value': -61976.25, 'pnl': 43841.25, 'm2m': 43841.25, 'unrealised': 43841.25, 'realised': 0, 'buy_quantity': 450, 'buy_price': 137.725, 'buy_value': 61976.25, 'buy_m2m': 61976.25, 'sell_quantity': 0, 'sell_price': 0, 'sell_value': 0, 'sell_m2m': 0, 'day_buy_quantity': 450, 'day_buy_price': 137.725, 'day_buy_value': 61976.25, 'day_sell_quantity': 0, 'day_sell_price': 0, 'day_sell_value': 0},

Order Sell parameter:
{'quantity': 450, 'transaction_type': 'SELL', 'tradingsymbol': 'BANKNIFTY2350443400CE', 'exchange': 'NFO', 'order_type': 'MARKET'}

Error Message:
{'account_id': 'JZ9146', 'unfilled_quantity': 0, 'checksum': '', 'placed_by': 'JZ9146', 'order_id': '230504203192019', 'exchange_order_id': None, 'parent_order_id': None, 'status': 'REJECTED', 'status_message': 'Insufficient funds. Required margin is 2608519.58 but available margin is 717962.80. Check the orderbook for open orders.', 'status_message_raw': 'RMS:Margin Exceeds,Required:2608519.58, Available:717962.80 for entity account-JZ9146 across exchange across segment across product ', 'order_timestamp': '2023-05-04 15:15:03', 'exchange_update_timestamp': None, 'exchange_timestamp': None, 'variety': 'regular', 'exchange': 'NFO', 'tradingsymbol': 'BANKNIFTY2350443400CE', 'instrument_token': 14554114, 'order_type': 'MARKET', 'transaction_type': 'SELL', 'validity': 'DAY', 'product': 'MIS', 'quantity': 450, 'disclosed_quantity': 0, 'price': 0, 'trigger_price': 0, 'average_price': 0, 'filled_quantity': 0, 'pending_quantity': 0, 'cancelled_quantity': 0, 'market_protection': 0, 'meta': {}, 'tag': None, 'guid': '25142X5q7aCya6psC4'}
  • rakeshr
    'RMS:Margin Exceeds,Required:2608519.58,
    This is the margin requirement for fresh short SELL order of BANKNIFTY2350443400CE, so the possibility can be that a different product type, then the open position, so it was considered as a new order.
  • dgangwar
    dgangwar edited May 2023
    @rakeshr My order entry is mentioned below along with the failed sell order. Both of them have product type as MIS. The only difference I can think of is the order_type. Buy order was placed using LIMIT and sell order was placed using "MARKET"

    Could you confirm if the order_type difference can make it consider the buy/sell order from the different category?
  • dgangwar
    Buy Order:
    {'account_id': 'JZ9146', 'unfilled_quantity': 0, 'checksum': '', 'placed_by': 'JZ9146', 'order_id': '230504202742163', 'exchange_order_id': '1500000139198974', 'parent_order_id': None, 'status': 'OPEN', 'status_message': None, 'status_message_raw': None, 'order_timestamp': 'REPLACED', 'exchange_update_timestamp': 'REPLACED', 'exchange_timestamp': 'REPLACED', 'variety': 'regular', 'exchange': 'NFO', 'tradingsymbol': 'BANKNIFTY2350443400CE', 'instrument_token': 14554114, 'order_type': 'LIMIT', 'transaction_type': 'BUY', 'validity': 'DAY', 'product': 'MIS', 'quantity': 450, 'disclosed_quantity': 0, 'price': 166.3, 'trigger_price': 0, 'average_price': 0, 'filled_quantity': 0, 'pending_quantity': 450, 'cancelled_quantity': 0, 'market_protection': 0, 'meta': {}, 'tag': None, 'guid': '25142XJHjTsn092QS4'}
  • dgangwar
    Sell Order:
    {'account_id': 'JZ9146', 'unfilled_quantity': 0, 'checksum': '', 'placed_by': 'JZ9146', 'order_id': '230504203192019', 'exchange_order_id': None, 'parent_order_id': None, 'status': 'REJECTED', 'status_message': 'Insufficient funds. Required margin is 2608519.58 but available margin is 717962.80. Check the orderbook for open orders.', 'status_message_raw': 'RMS:Margin Exceeds,Required:2608519.58, Available:717962.80 for entity account-JZ9146 across exchange across segment across product ', 'order_timestamp': '2023-05-04 15:15:03', 'exchange_update_timestamp': None, 'exchange_timestamp': None, 'variety': 'regular', 'exchange': 'NFO', 'tradingsymbol': 'BANKNIFTY2350443400CE', 'instrument_token': 14554114, 'order_type': 'MARKET', 'transaction_type': 'SELL', 'validity': 'DAY', 'product': 'MIS', 'quantity': 450, 'disclosed_quantity': 0, 'price': 0, 'trigger_price': 0, 'average_price': 0, 'filled_quantity': 0, 'pending_quantity': 0, 'cancelled_quantity': 0, 'market_protection': 0, 'meta': {}, 'tag': None, 'guid': '25142X5q7aCya6psC4'}
  • sujith
    At the time you were placing the order there was already a stoploss order pending. Hence the new order you placed was considered as a fresh sell. Later, it was cancelled and then position was closed.
  • dgangwar
    @sujith Thanks a lot for the update, it makes sense now. Will try to handle that in my code. :)
This discussion has been closed.