Hi Upstox Team,
I am building a trading analytics backend called StrikeIQ using the Upstox V3 Market Data WebSocket.
Architecture:
Upstox WebSocket
→ receive binary packets
→ queue
→ protobuf decode (MarketDataFeed_pb2)
→ broadcast ticks to frontend via FastAPI WebSocket
The WebSocket connection is successful and the subscription request is sent.
However I am only receiving heartbeat packets (~154 bytes) and the protobuf FeedResponse contains 0 feeds .
Logs:
UPSTOX WS CONNECTED
SUBSCRIPTION PAYLOAD: 2 instruments
RAW PACKET SIZE = 154
PROTOBUF MESSAGE RECEIVED | feeds=0
Subscription payload used:
{
“guid”: “strikeiq-feed”,
“method”: “sub”,
“data”: {
“mode”: “full”,
“instrumentKeys”: [
“NSE_INDEX|Nifty 50”,
“NSE_INDEX|Nifty Bank”
]
}
}
Questions:
Are these the correct instrument keys for Nifty and BankNifty index in WebSocket subscriptions?
Is there any additional step required after connecting to the authorized_redirect_uri WebSocket?
How can we differentiate heartbeat vs market data packets in FeedResponse?
Is there any example Python implementation for decoding MarketDataFeed protobuf correctly?
Goal:
Receive live Nifty 50 and BankNifty spot ticks from the Upstox WebSocket feed.
Any guidance would be greatly appreciated.
Thanks!
DSingh
March 4, 2026, 7:40am
2
Thanks for the suggestion.
I checked the official example (upstox-python/examples/websocket/market_data/v3/websocket_client.py) and aligned my implementation with the same flow. Below is the simplified version of how I am connecting and subscribing to the V3 market feed using websockets and asyncio.
import asyncio
import json
import httpx
import websockets
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
async def connect_feed():
# Step 1 — Get authorized WebSocket URL
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Accept": "application/json"
}
async with httpx.AsyncClient() as client:
response = await client.get(
"https://api.upstox.com/v3/feed/market-data-feed/authorize",
headers=headers
)
ws_url = response.json()["data"]["authorizedRedirectUri"]
# Step 2 — Connect WebSocket
async with websockets.connect(ws_url) as websocket:
# Step 3 — Send subscription request
payload = {
"guid": "example-feed",
"method": "sub",
"data": {
"mode": "ltpc",
"instrumentKeys": [
"NSE_INDEX|Nifty 50",
"NSE_INDEX|Nifty Bank"
]
}
}
await websocket.send(json.dumps(payload))
print("Subscription sent")
# Step 4 — Receive packets
while True:
message = await websocket.recv()
print("Packet size:", len(message))
asyncio.run(connect_feed())
In my main application this WebSocket runs as a background service in FastAPI and the incoming packets are pushed into a queue where protobuf decoding and broadcasting to clients happens.
Currently I am receiving packets (~160 bytes) which appear to be heartbeat packets.
Still verifying whether market data packets are received consistently after subscription.
If there are any additional requirements for index subscriptions in V3 feed, please let me know.
Thanks.
DSingh
March 4, 2026, 8:34am
4
1 Like
DSingh
March 4, 2026, 11:48am
5
Update following:
# await websocket.send(json.dumps(payload))
await websocket.send(json.dumps(payload).encode('utf-8'))