Introducing: Now execute your Basket Orders via webhooks on Dhan charts

Hello @killedar.amit

Yes, we are planning to release it soon. It is a priority on our roadmap.

And along with the new version, we will try to add video guides/post on using the same to full extent, so that it’s easier for users to start using it.

Hi @Hardik ,
can a same basket be executed more than once ? In the above case , if SL hit and basket executed as triggered by the alert set at SL line ,if market reverses and reaches to target line , if alert triggers can the same basket will be triggered again.
My guess is once basket executed , should not be allowed to execute again unless its reset . Kindly confirm.

Hello @jacharjya1978

Yes, the same basket can be executed more than once. On Dhan, we do not delete the basket once it is executed and hence, the same basket can be used multiple times.

If you are setting up multiple alerts with same basket, then you need to check on such conditions where same basket can be triggered multiple times.

Thanks @Hardik , So we need to be attentive then , there is a possibility post SL HIT , a new position too can be created if it again hit the TARGET. Its good to have a basket executed once , unless it’s manually reset post execution.

In the message body for alert message body - do we need to pass JSON with secret, alerttype and order_pegs or start from transactionType?

1 Like

Hi team, I’m not able to find Generate Webhook option in Dhan desktop. I regularly use it, but not able to find it now. Is there any update going on? Please advise

Hi @Vivekgowda Welcome to Dhan community. For select users, we have moved Webhooks to Orders section of Dhan web. Please check the same, we will be put a detailed post on this when shortly.

@mtwn105 Now, with Webhooks on Dhan, you are not limited to scrips available on TradingView.com . You can place orders based on any chart in Equity, Futures, Options and even Multi-segments. Here is a detailed post on the same - Introducing: Webhooks as Order Type on Dhan. Now do Options Trading on TradingView.com

@Vivekgowda Here is a detailed video for it - How to use Dhan Webhook for TradingView | Options Trading | Pine Script | Alert Explained | Dhan - YouTube

Do we need to add symbol under the webhooks or can pass dynamic symbol to trade? So for example. I have a code that decide the strike price automatically. Do i need to ensure that strike price is available in the list under webhook before hand?

Hi, Would like to talk to the support executive to clear certain doubts about webhook basket orders…Would be nice if we can set up a short zoom meeting or a call…Thanks

Hi, My main doubt is a very simple one. Let me try to explain what I am facing. For eg. say, I have set up a webhook order to buy 1 lot of Adaniports 820PE based on an indicator set up on tradingview giving a SELL alert on AdaniPORTS stock. And when the alert was triggered the order got executed on Dhan and I have 1 lot of ADANIPORTS 820 PE running. Now let us say after a few candles, the TV fired a BUY alert based on my indicator setup on Tradingview. Now i want to exit the ADANIPORTS 820 PE trade and enter a buy order for ADANIPORTS 800 CE. How do i set up this scenario using webhook orders? Hope I have made myself clear. Or else, we can meet up on zoom or on a call…Hope we can connect at the soonest. Thanks in adv

1 Like

@jpals U seem to have a stop and reverse system. So create two baskets - one for long side trade and another for short side trade. Fill the baskets with appropriate contracts at any point of time. E.g if you get a buy signal (as in ur example) execute the long basket which has 2 orders - Sell ADANIPORTS 820 PE and Buy ADANIPORTS 800 CE. Note that if your code generates signals at high frequency then changing basket contents every now and then could be tedious.

You can also explore the new multi leg order JSON generator on Dhan web platform. Pine coding is more complex than the former but saves a lot of time if u can do it.

Thank you. It is clear about creating two baskets - one for long signals (with a CE buy and PE sell) and another for short signals (with a Ce sell and PE buy). But to start the day it should be a single order, based on which signal is generated by the indicator. Can you pls advise whether the following would be a workable solution: (for the scenario explained in my msg)

  1. Create appropriate orders in Dhan webhook orders under the ‘Options trading’ tab first – one for BUY alert with 800CE buy and another for SELL alert with 820PE buy
  2. Create 2 alerts in TV – One for BUY alert with CE buy order and another for SELL signal with PE buy order. Set the alert frequency to fire ‘Once per bar close’. Configure the alerts with webhook URL and JSON message appropriately
  3. Stop both these alerts manually whenever one of the above alerts is fired.
  4. Create appropriate orders in Dhan webhook orders under the ‘Baskets’ tab – a LONG basket for subsequent BUY alerts with 800CE buy/820PE Sell combo and another SHORT basket for subsequent SELL alerts with 820PE buy/800CE combo.
  5. Create another two alerts as you have suggested in TV – one to execute the LONG basket for BUY alerts and another to execute SHORT basket for SELL alerts when that are triggered in TV by the indicator. Set the frequency to “Once per bar close”. . Configure the alerts with webhook URL and JSON message appropriately. Keep these ‘stopped manually’ till the step no. 3 is over
  6. Once step no.3 is completed, start both these alerts
    I think this should work. Will look at the pinescript part also soon. Even if I use pinescript the JSON message need to entered manually.
    Where can I locate the new multi leg order JSON generator on Dhan web platform.
    Will wait for your sage advice.

But there is a catch in this arrangement. It is the margin requirement. For the first order to go thru you need margin for the BUY order of CE or PE which ever case it may be. For the basket order next, you have a SELL order of CE/PE and the margin required will be much higher. But it is against an existing CE/PE buy and I am not sure how Dhan will treat this basket? Will it go thru or will it fail? Can you pls advise…Hope the issue mentioned is clear to you.

If you haven’t then please go through this

For buy order u don’t have a problem. U just need to pay the option premium. As long as funds are sufficient it should go through.

For sell orders margin issue won’t come if you are closing an open position using an order leg in the basket. Dhan won’t block additional margin in this case.

Thanks. I have gone thru the document already. That is nice to know. So the arrangement should sail through.
Request you to please confirm whether the plan as explained in my previous message makes sense?

1 Like

These seem applicable for firing direct orders using the new webhook feature from dhan.

Start of the day u set basket orders with individual buy orders for call and put in long and short basket respectively.

Then 4 to 6 is correct.

Yes for basket JSONs manual entry would be needed. Although if you are always triggering same baskets only the secret code changes when a new webhook url is generated. So u can pre format the JSON string in pine script to make things little bit more easy.

{“secret”:“xxxxx”,“alertType”:“multi_leg_order”,“order_legs”:[{“transactionType”:“B”,“orderType”:“MKT”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“ADANIPORTS”,“instrument”:“OPT”,“productType”:“I”,“sort_order”:“1”,“price”:“0”,“option_type”:“CE”,“strike_price”:“830.0”,“expiry_date”:“2023-08-31”},{“transactionType”:“S”,“orderType”:“MKT”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“ADANIPORTS”,“instrument”:“OPT”,“productType”:“I”,“sort_order”:“2”,“price”:“0”,“option_type”:“PE”,“strike_price”:“830.0”,“expiry_date”:“2023-08-31”}]}

Thanks a lot and your kind assistance even on a Sunday is much appreciated

1 Like

Greetings, I have thought of one scenario here. Suppose I have manually exited the open position say for e.g. the CE . Then when the basket order goes thru how will it be handled? The sell order leg in the basket may fail because of margin issue. If that happens, what will happen to the buy order leg of the basket? Will it go thru?