How to close a position using dhanhq api

After successfully making a trade how to close a position using dhahq python api?

Hello @trading.sahu059

To close a position via APIs or any platform, you just need to take a reverse trade i.e. if you have long position of x quantity, you need to place a sell order (via Order Placement API) for the same x quantity.

This will essentially close your long position. Hope this helps!

on any strike price?
If my buy order is for strike x how can close this position via API?

Hello @Channa_Mangalore

Welcome to Dhan Community!

You can do so by first fetching your positions and checking which instrument do you have a position in. Then you can execute sell order (in case you have long position) or vice versa in the same Security ID.

@Hardik whats wrong with the below json

Below buy order is succesfull

But I am not able to trigger a sell order on the sell alert

Here is what I am generating for sell. Whats wrong I am doing?

Hello @Channa_Mangalore

Looks like you are not adding the strike price and the option type in case of sell order. Do check that and pass the same as the one in Buy JSON to close the position on sell alert.