Tigger order in platform that automatically places order in options on the basis of underlying Index price

i need to take below script for API trading on upstox.

tigger order that automatically places order in options on the basis of underlying Index price.

for example, whenever nifty go on 24375 i want to buy atm put option with stoploss on inder of vale 24400 and target as 24300.

Use websocket to get live market price. when nifty hits 24375 trigger a buy order…as of now there is no option for stoploss and target.so when nifty hits your sl or target trigger sell order.

Let’s suppose with websocket I have opened a buy order, is it possible to monitor I will monitor price with websocket and whenever price reached to my specific level (target or stop loss ) trigger one square off command to Upstox order which was open earlier.

Get nifty live price using websocket…Trigger buy order when the price reach your desired level.(use an if condition .Once you have a websocket connection you will get live NIFTY price until the market closes)If you know the target price or stop loss of the option, directly place a limit sell order.
I dont think you can directly square off using upstox API. You have to trigger a separate sell order.
If you dont know the SL/target of the option, you have to trigger an option sell order whenever the NIFTY crosses target/SL

Yes, @fallen_coconut is correct. You can’t directly square off your position; you need to place an opposite leg order to do so.