I am an Upstox Plus subscriber and I am using the Market Data Feed V3 WebSocket API for a personal project. My Client ID is: 297293
I am able to connect to the WebSocket and successfully subscribe to and receive a live full_d30 data feed for indices like NSE_INDEX|Nifty 50 and NSE_INDEX|Nifty Bank. The data for these indices streams perfectly.
However, I am facing an issue when I try to add individual stocks to the subscription. When I include any equity instrument (e.g., NSE_EQ|RELIANCE) in my subscription request, I receive an initial empty data packet for the stock, but no subsequent live data ticks are ever sent from the server. The data feed for stocks remains completely silent, while the index data continues to stream correctly.
I have thoroughly reviewed your API documentation and confirmed that:
-
I am using the correct
full_d30mode as required for Upstox Plus members. -
My subscription request respects the 50-instrument limit for a single connection.
This leads me to believe that my API key, despite being on a Plus plan, may not be fully enabled for live data streaming for equity instruments.
Could you please check my account and confirm if my API key is provisioned to receive a live data feed for equities? If it is not enabled, I would be grateful if you could enable it.
THIS ISSUE IS WITH MY ACCOUNT OR WITH API, PLEASE HELP
Import necessary modules
import asyncio
import json
import ssl
import websockets
import requests
from google.protobuf.json_format import MessageToDict
import MarketDataFeedV3_pb2 as pb
def get_market_data_feed_authorize_v3():
“”“Get authorization for market data feed.”“”
IMPORTANT: Replace with your actual access token
access_token = ‘API TOKEN’
headers = {
‘Accept’: ‘application/json’,
‘Authorization’: f’Bearer {access_token}’
}
url = ‘https://api.upstox.com/v3/feed/market-data-feed/authorize’
api_response = requests.get(url=url, headers=headers)
return api_response.json()
def decode_protobuf(buffer):
“”“Decode protobuf message.”“”
feed_response = pb.FeedResponse()
feed_response.ParseFromString(buffer)
return feed_response
async def fetch_market_data():
“”“Fetch market data using WebSocket and print it.”“”
# Create default SSL context
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
# Get market data feed authorization
response = get_market_data_feed_authorize_v3()
# Connect to the WebSocket with SSL context
async with websockets.connect(response["data"]["authorized_redirect_uri"], ssl=ssl_context) as websocket:
print('Connection established')
await asyncio.sleep(1) # Wait for 1 second
# Data to be sent over the WebSocket
data = {
"guid": "someguid",
"method": "sub",
"data": {
"mode": "full",
# Changed to subscribe to TATAMOTORS and RELIANCE
"instrumentKeys": ["NSE_EQ|TATAMOTORS", "NSE_EQ|RELIANCE"]
}
}
# Convert data to binary and send over WebSocket
binary_data = json.dumps(data).encode('utf-8')
await websocket.send(binary_data)
# Continuously receive and decode data from WebSocket
while True:
message = await websocket.recv()
decoded_data = decode_protobuf(message)
# Convert the decoded data to a dictionary
data_dict = MessageToDict(decoded_data)
# Print the dictionary representation
print(json.dumps(data_dict))
Execute the function to fetch market data
asyncio.run(fetch_market_data())