Error the trigger price set for your stop loss market order is invalid

I was trying to place order using API, but the order was failing repeatedly
Although , the api response that i am getting looks like this
{‘data’: {‘order_id’: ‘240703026113829’}, ‘status’: ‘success’}

The webinterface of upstox shows that the placed order was failed (as shown in image).
[Note: the trigger price passed is integer type of python, not string.]
Please Help.

here’s the code I used @Ketan @Pradeep_Jaiswar

def send_buy_signal_MarketPrice(instrument_token, capital, current_price, stop_price, target_price, product='D'):
    # product - 'I' or 'D'
    # return order_id , 
    # placeExitTrigger({'quantity': num_shares, 'product': 'I', 'validity': 'DAY', 'instrument_token': instrument_key, 'transaction_type': 'BUY'}, tp1)
    # use target price  
    num_shares = math.floor(capital /current_price)
    to_be_invested =  num_shares* current_price

        print("Placing order")
        body ={
        "quantity": num_shares,
        "product": product,
        "validity": "DAY",
        "price": 0,
        "instrument_token": instrument_token,
        "order_type": "SL-M",
        "transaction_type": "BUY",
        "disclosed_quantity": 0,
        "trigger_price": stop_price,
        "is_amo": False

        api_response = api_instance.place_order(body, '2.0' )
        if api_response.status == "success":
            print("--------------successfully placed order--------------")
            print("captital bef", capital)
            capital-= to_be_invested
            order_json =
            print("captital after", capital)

            return order_json.order_id
            return None

    except ApiException as e:
        print("Exception when calling OrderApi->place_order(send_buy_signal_MP): %s\n" % e)

        return None

import upstox_client

configuration = upstox_client.Configuration()
configuration.access_token = access_token 

api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))

order_id = send_buy_signal_MarketPrice('NSE_EQ|INE009A01021', 2000,  1628, 1615, 1630)

@chandan22140, please make sure that the trigger_price for your buy order is higher than the last traded price of the specified stock.
Similarly, for a stop-loss market sell order, the trigger_price must be lower than the last traded price.

Thank you.

As you can see the code I posted, I am placing a buy order of type SL-M.
which means my trigger price should be smaller than the LTP. As you can see the screenshot attached in first post the trigger price is indeed smaller than the LTP. please clarify how to solve this problem. I have also posted the order ID in the first post for your reference

I reviewed your order and noticed you placed an Infosys equity SL-M order with a trigger price of 1615 when the last traded price was 1643.

I hope there is no confusion between limit orders and SL-M orders. If you want to buy at 1615 when the current price is 1643, you should place a limit order instead of a stop loss order.

Ideally, a stop-loss market buy order is used to cover sell positions. As the name suggests, it is used to stop losses on your sell position. A sell position incurs a loss when the price increases from the point where you sold it. To prevent further losses, you would place a stop-loss market buy order with a trigger price that is higher than the last traded price.

I wanted to place a market order when LTP was 1643 with stoploss at 1615

Based what I have understood from documentation (please correct me if I am wrong)
In SL-M, TRIGGER PRICE acts as the stoploss price. I think in sl-m buy order, buy happens in market price.
I don’t think, trigger price 1615 means I want to buy at 1615.
Also, here does “sell position” mean “short position”?
Please enlighten me.

Oh, I understand your case now. Currently, the API does not support two-legged orders. To replicate the case you mentioned, you need to place two separate orders:

  1. Market buy order
  2. Stop loss market SELL order with a trigger price of 1615.

And yes, by “sell position,” I meant short positions.

Trailing stop loss will be soon introduced in api. New developments at Uplink (Upstox API)