Placing Orders via APi

Hi,

I was able to successfully get my orders tested in Sandbox today :

LOW BREACHED → SHORT @ 26083.65
SHORT MARKET NIFTY FUT | Qty:75 | Price:0.00 | Trigger:0.00 | ID:251208101912386 ==> Entry order

After the Entry got triggered I place an SL order too as shown below :

LONG SL NIFTY FUT | Qty:75 | Price:26127.75 | Trigger:26127.70 | ID:251208101915740

And I set a Market order once it achieves the desired target.
TARGET 1 HIT → EXITING SHORT AT MARKET (Touched 26053.5)
LONG MARKET NIFTY FUT | Qty:75 | Price:0.00 | Trigger:0.00 | ID:251208111112846

And since the target got hit, the SL order was cancelled.
Order CANCELLED (ID: 251208101915740)

Now my question here is when the Entry order is placed with ID:251208101912386, do I need to use this Order ID itself to place the SL and Target order too or is it right that I am creating a separate order as shown above ? Hope someone can guide me with this

@Ketan or anyone else - any suggestion on this ?

Hi @elroy_savi_1055123 ,

When your entry order is executed (ID: 251208101912386), you do not reuse the same order ID for your Stop-Loss or Target orders. Each order Entry, SL, and Target — must be placed as separate orders, each receiving its own unique order ID from the system.

And yes once your target exit order got executed, it correctly cancelled the SL order, which is standard behavior for manually managed bracket-style trading.

If you don’t want to execute them manually you can try using Multi-Leg GTT order depending on your logic

Hope this helps, Thanks!

Hey @Anand_Sajankar yes this helps and solves my confusion. Thanks alot!

2 Likes

Hey @Anand_Sajankar

I just wanted to check back with you on today’s scenario

So today the opposite scenario (SL got hit first, Target order not cancelled as it is a Market order) occurred as to what happened on 8th December (Target got hit first and SL was cancelled) as explained above - so today a long side entry was triggered at 10:22 am correctly and the subsequent SL Order too got placed correctly :

2025-12-10 10:22:11,911 - INFO - Discord → DECIDER HIGH BREACHED → LONG @ 25937.60
2025-12-10 10:22:34,678 - INFO - Discord → LONG MARKET NIFTY FUT | Qty:75 | Price:0.00 | Trigger:0.00 | ID:251210102233070
2025-12-10 10:22:34,679 - INFO - PLACED LONG MARKET: 251210102233070 (Price:0.00, Trigger:0.00)
2025-12-10 10:22:36,488 - INFO - Discord → SHORT SL NIFTY FUT | Qty:75 | Price:25896.95 | Trigger:25897.00 | ID:251210102234761
2025-12-10 10:22:36,488 - INFO - PLACED SHORT SL: 251210102234761 (Price:25896.95, Trigger:25897.00)

However, I didn’t get the SL order triggered message - is it due to the limitation of the Sandbox ?

2025-12-10 10:51:10,742 - INFO - LATEST CANDLE → 10:49:00 | C=25890.95 H=25903.75 L=25889.00
2025-12-10 10:51:13,742 - WARNING - SANDBOX MODE: Skipping status check for 251210102234761 (API not supported)

I am using this in the code to check for order details :

RETRIEVE_URL_BASE = “https ://api-sandbox.upstox.com/v2/order/details” if SANDBOX_ORDERS else “https ://api.upstox.com/v2/order/details”

And this is the function :
def get_order_status(order_id, max_retries=3):

if not order_id:

return “”

if SANDBOX_ORDERS:

logging.warning(f"SANDBOX MODE: Skipping status check for {order_id} (API not supported)")

return “” # FIXED: Graceful skip in sandbox

url = f"{RETRIEVE_URL_BASE}?order_id={order_id}"

Is it possible to check the order status in SANDBOX ?

Hi @elroy_savi_1055123 No, that API is not available in Sandbox mode. Please refer to the list of supported Sandbox APIs for details. Sandbox | Upstox Developer API

Hey @Anand_Sajankar - got it thanks. But now the real concern is how do I ensure that if an SL order is placed (like in the case above), whether its getting triggered or not ? Shouldn’t that be available to test out in Sandbox ? Or is this a limitation in Sandbox ?

Also I can’t test GTT Orders in Sandbox so that is a limitation too. How do I ensure everything is working fine with the GTT order too if I can’t test it in Sandbox ?

@Anand_Sajankar - does an SL order actually get triggered in Sandbox for testing purpose or it doesn’t ?

@elroy_savi_1055123 It doesn’t, The sandbox environment lets you place orders via the API, including SL or SL-M types, and you’ll get a success response with an order_id just like in live, but the sandbox does not simulate real execution.