API to square off NIFTY Options in Intraday

Hi @Pradeep_Jaiswar @MohitGolecha
Hope you all are doing well. My question is regarding squaring off Nifty Options positions using APIs.

Note: I am an option buyer and not a seller (shorting) due to huge margin requirements.

I now have code (websockets + API) which BUYs options on its own. The pending part is squaring off.

As per earlier replies by @Pradeep_Jaiswar the standard way to square off option positions is placing the same order with opposite leg.

  1. How to set Target in api SL order - #7 by Pradeep_Jaiswar
  2. How to Square off or Exit order? - #2 by Pradeep_Jaiswar

My question is : To square off my bought PUT or CALL positions, if I place a sell order (same instrument and same quantity), will it need the additional selling margins? Honestly, if I am holding Calls worth 6 lakhs, I do not want to end up in a soup when I try to square-it off by placing SELL order (due to huge margin requirements).

I continuously monitor for target and SL price in my code and want to place SELL Market orders the moment either Target or SL price is met.

Thanks in advance,
Amit