Unable to reverse positions using the general webhook & json for buy and sell with double qty

Hello dhan community,
I had developed a strategy which is givingme good returns. But the problem I am facing is that I am unable to reverse positions via. webhook. Initially I tried reversing the position using double quantity opposite side order, let’s say I was having a long position open with 30 qty, so in order to reverse it y algo was placing a sell order of 60 qty. But when this order gets triggered in dhan, app is showing me margin shortage. After this, I tried reversing the position by different lines of code for example I have an open long position with 30 qty and I want to reverse it I shall be placing first a close position command like strategy.exit(“Long”, qty = 30), then I shall be placing the new entry position by strategy.entry(“Short”, qty = 30, strategy.short). When I tried this both order reaches dhan almost at the same time. That means before dhan app could exit my position a new order for entry fires thus again ending up with margin shortage. Please hep, I need to ensure smooth reversal of my positions for my algo to work perfectly.

1 Like

Hello @elishablacksmith07

There wouldn’t be any extra margin requirement in case of selling double quantity. If this is options, then your sell margin is higher than the buy margin requirement, and hence this issue might arise. In which segment are you trying to place the order here?