Exit All Through API

Hi team,

Would like to consider you adding exit all position option for API

1 Like

Hello @mudflap175

Welcome to Dhan Community!

We have noted this. However, this can be built by any developer, or at your end too. You just need to fetch all open positions and place orders to close them.

Thanks @Hardik. I have tried that but it took some additional time while exiting all the positions.

If we have Exit All Positions it would be really fast. Thanks!

Hello @mudflap175

Yes, we have noted this feedback at our end. We will evaluate feasibility of building this on scale moving forward.

1 Like

@Hardik any update ?

Hello @SoAaDha1

No, not on this. We have evaluated this and do not feel the need to build this an an API. There shouldn’t be any time delay in placing multiple orders at once and this is more of a function than an API itself which can be build at your end.

Please introduce direct exit option trough wavehook for option trading. It is difficult to reverse the order through algo as spot price change during exit. We are using paid thirdparty bot wavehook only for exit… pls help.

Hello @Dev1

Welcome to Dhan Community!

Can you elaborate more about how should the exit functionality work here? Is is to exit specific position or all the active positions?

Hi @Hardik , in case of Cover order → the reversal order is by default placed on the main order as stop loss leg order. and lets assume main order is success and stop loss leg is in pending and after sometime i want to exit sl leg. In this case if i want to exit from stop loss leg position how can i do through api?

For example, we use to buy banknifty option with auto starike (nearest to spot) through pine script and wavehook in TV. Please introduce single code like “[{“CLOSE”:“CLOSE”,“E”:“NSE”,“P”:“INTRADAY”,“AT”:“DHANHQ”}]” to exit all open positions instead of placing a sell order with same spot price. The above syntax is from a thirtd party bot. Similarly Code for exit CNC order “[{“CLOSE”:“CLOSE”,“E”:“NSE”,“P”:“CNC”,“AT”:“DHANHQ”}]”

Hello @kedar

You can exit a position with stop loss using either of the below ways via API.

  1. Cancel your existing stop loss leg of cover order and place a new order to exit your position.
  2. Modify your existing stop loss order, with Order Modification API

Hello @Dev1

Noted. We are assessing already whether it will be feasible to have dynamic strike selection at scale or not. If yes, then this might be possible.

Hi @Hardik ,

1. Cancel your existing stop loss leg of cover order and place a new order to exit your position.

lets say I placed a cover order and assume order id is 12345. and after sometime cancelled the stop loss leg , now how can I place reversal order for the order id 12345. In python api there is no argument to specify for placing orders against a particular order id. It will result in placing completely new order.

2. Modify your existing stop loss order, with Order Modification API

modification is not working after successful execution of main leg as communicating in other thread. so no hopes on this.

@kedar

On the first point, Yes, it will create a new order to exit your entry leg, however, I don’t foresee any downside to this.

On second, this is solved now. Do try and if you face issue, let us know.

Hi @Hardik,

Second point I will try and let you know.

On first point, I might be wrong in understanding this scenario. If it is a new order then how it will help in exiting other cover order, there is no correlation between them right?
and at the end of the day I will be having two separate entities one is cover order main leg and other one later placed one.
if your thought is end of the day (one buy order and one sell order) present in my positions. so it will complete the transaction buy+sell. will I not ended up paying auto square off charges for 2 orders?

Hello @kedar

Your positions are closed at real time basis and even the margin are calculated accordingly. And ‘Exit Position’ for long position is nothing but a ‘SELL’ order and vice versa.

So when you place a new SELL order to close existing BUY position, it is considered as a square-off order only, and you won’t pay any additional such charges.

1 Like

Hi, another use case for exit all positions is when we are trading via TradingView and using webhook urls.

Consider following strategy

  • Whenever certain condition satisfied at a new candle, call webhook and buy 1 lot
  • We have pyramiding enabled so on every new candle, call webhook and buy 1 lot
  • at any point when market reverses or exit condition satisfied, call webhook to exit all positions.

Using webhook and indicator based strategy, it won’t be possible to get list of all positions and then exit them.

In addition to my previous comment, as market moves we may end up buying different strikes. TradingView doesn’t support options yet, so indicator is on say Nifty/BankNifty but we are buying options. Hence no way to know which strike we bought, hence a sell order cannot be placed.

Hello @Amit_Rana

Welcome to Dhan Community!

Understood the use case here. We will look into the feasibility of adding this, maybe exit all instead of exiting on base of particular position, as that will be difficult to map.

Exit All works in most cases

1 Like