Upstox V3 WebSocket connected but FeedResponse feeds empty (only heartbeat packets)

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:

  1. Are these the correct instrument keys for Nifty and BankNifty index in WebSocket subscriptions?

  2. Is there any additional step required after connecting to the authorized_redirect_uri WebSocket?

  3. How can we differentiate heartbeat vs market data packets in FeedResponse?

  4. 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!

@UDAY_1050972 Kindly follow the example code. upstox-python/examples/websocket/market_data/v3/websocket_client.py at master · upstox/upstox-python · GitHub

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.

Kindly follow the example from the link mentioned above. Also make sure to include files MarketDataFeedV3.proto and MarketDataFeedV3_pb2.py for parsing the protobuf response. upstox-python/examples/websocket/market_data/v3 at master · upstox/upstox-python · GitHub

1 Like

Update following:

# await websocket.send(json.dumps(payload))

await websocket.send(json.dumps(payload).encode('utf-8'))