margin shortfall error during squareoff position

Why is it require margin to squareoff positions?

placed squareoff order with code;

data = {“id”: 'NSE:NIFTY23N0220400CE-MARGIN’}

response = self.fyers.exit_positions(data=data)

Got error: RED:Sqroff Shortfall:INR 9,370.12 Available:INR **for C XA[FYERS_RISK_CUG]

Hi @yogendrayadav08-6j8
Possible reason can be that after exiting this position you current position exceeding the limit of margin.

Can you place same order via web and let me know what you get from there.

calendar spread is in place, I was exiting one side. and I placed exit order for short leg first. Then I had to place manual order.

Hi @yogendrayadav08-6j8

So Same order you got placed from api , that got rejected and for same payload from web it is executed
This is your issue ?

yes

Hi @yogendrayadav08-6j8

Margin shortfall rejection can occur in specific situations with open positions:

Check this sample scenarios

Scenario A: When you have a pending order for an open position, and without cancelling that order you’re trying to square off the position.

Scenario B: When you have a hedge spread and attempt to close the buy orders first, without having adequate margin for the potential naked positions after the closing.

It seems that your situation falls into Scenario B, as you mentioned you were dealing with a calendar spread.