How to place BUY/SELL order through Upstox V2 websocket API

I am trying to send BUY/SELL order through websocket api but not able to send the request. Following are code snippet which gives a idea how i am using web scoket api
data = {
‘quantity’: 1,
‘product’: ‘D’,
‘validity’: ‘DAY’,
‘price’: 13,
‘tag’: ‘string’,
‘instrument_token’: instrumentKey,
‘order_type’: ‘LIMIT’,
‘transaction_type’: ‘BUY’,
‘disclosed_quantity’: 0,
‘trigger_price’: 13.2,
‘is_amo’: False,

async with websockets.connect(, ssl=ssl_context) as websocket:
print(‘Connection established’)

    if data != None:
        await websocket.send(json.dumps(data))
        print("\n --------------PLACE Trade ORDER ------------------ \n")

while True:
message = await websocket.recv()
message = json.loads(message)

but above code doing nothing when it send request data although it throwing error while receiving messages
exception is
websockets.exceptions.ConnectionClosedError: received 1011 (internal error); then sent 1011 (internal error)

Please help me to resolve this issue.

Thank you !!

If you’re looking to execute an order, please consult the API Documentation for placing orders and also review the Example Codes for placing orders.

It’s important to note that buy/sell orders cannot be placed via the WebSocket API.

Upstox provides two WebSocket streams:

  1. Market Data Feed: This stream delivers market updates such as the latest trading price, closing price, opening price, etc., when connected to the WebSocket.
  2. Portfolio Stream Feed: This stream communicates all order updates when connected to the WebSocket, including order status changes and other related information.

Thanks @Ketan for quick reply.

Just want to clarify, as you said BUY/SELL cannot be placed via Websocket API then it means we will have to use order web api to place BUY/SELL. If it is true then it would be real time data for placing BUY/SELL or there will be lagging in price movement. I mean it would be perfect to place BUY/SELL via order api or will be facing delay in execution.

Thanks again.

@ShalabhSaurabh There will be no delay; it is just as efficient as placing orders through our web platform or mobile app since the underlying infrastructure is the same.

After placing the order, you can receive order updates through WebSocket or via the webhook post-back URL.

@Pradeep_Jaiswar Thank you so much for valuable advice !!