How to place basket order through dhan api

Hi @Dhan @Tradehull_Imran,

First of all, thanks Imran for the video series on Youtube!
I have one query to ask. How can i place a basket order through dhan API?

How can I take hedge benefit when doing option selling through API?
When I call the margin_calculator() method, the totalmargin required doesn’t consider the hedged positions? It just gives me the independent margin required for the current order.

For example, if NIFTY is at 23000 and I want to [SELL 23000 CALL & [ BUY 24000 CALL], if I want to do this through a basket order, I will require only 1 lakh capital(as I will have hedge benefit). But through API, both the orders will go independently, I will require around 2lakhs capital(which is double). So this is a huge problem.

Please clarify. Thanks!

Place the buy order for hedge leg first. Then send the sell order. Separate both orders with atleast 500 ms delay to ensure order execution of short leg.

How can I know the margin required for selling beforehand? When I place a basket order, I am aware of the total margin required, and accordingly, I can decide the number of lots to sell.