My code is able to place a BUY order; but upon hitting the target condition, my code is not able to SELL the same option contract

Hello,
My BUY order code:

body = upstox_client.PlaceOrderRequest(
        quantity=25,
        product="I",
        validity="DAY",
        price=last_price,
        tag="string",
        instrument_token=instrument,
        order_type="LIMIT",
        transaction_type="BUY",
        disclosed_quantity=0,
        trigger_price=0,
        is_amo=False
    )

With this, the BUY order is placed successfully.

My SELL order code for the same option contract:

body = upstox_client.PlaceOrderRequest(
        quantity=25,
        product="I",
        validity="DAY",
        price=selling_price,
        tag="string",
        instrument_token=instrument,
        order_type="LIMIT",
        transaction_type="SELL",
        disclosed_quantity=0,
        trigger_price=0,
        is_amo=False
    )

But, the same option contract was not sold. However a new SELL order was attempted and then immediately faced with an error - “You need to add Rs.xxxx in your account to place this trade”.
The API did not return any error, and the above error was seen on my Upstox mobile app.

How can my code sell the SAME ORDER that the code has already purchased?

Thanks in advance for help.

The way you have written the sell order is correct but please confirm these points.

  • The instrument key you are using is the same for buy and sell order.

  • Your buy order was successfully placed by api.

  • Had a valid position of the option before placing the sell order from api.

If all these conditions are matched and you still faced the issue then please share these details for further investigation.

  1. Buy order orderId
  2. Sell order orderId
  3. Your upstox userId

Thank you.

Thanks for the reply .

  1. The instrument key i am using is the same for buy and sell order.
  2. Yes my buy order was placed successfully by api - Order ID - 240610010127625
  3. Since Buy order was successful , that means i had valid position of option before placing the sell order
  4. Sell order ID is - 2406110010128021 . This sell order is not successful due to fund availability. My luck …
  5. My upstox USER ID - 3EBJJW

Waiting for the inputs please

Hello Any updates on the topic … Again i got the same error

@Pawar You will need to rely on websocket for order updates for success/failure response from the exchange, The API will return the order_id in response.

Please refer to the following API documentation for the portfolio stream feed:

Additionally, check out the sample websocket implementation for order updates: