Hi Team,
Is there a requirement to give additional roles or permissions to access the live Market Data Feed V3 ?
Hi Team,
Is there a requirement to give additional roles or permissions to access the live Market Data Feed V3 ?
There are no additional roles/ permissions needed to access the live market data feed V3.
However, to access Depth 30 mode, you’ll have to be on the plus plan.
Hi Mohit,
Thank you for your response. I want to access d_30 data for a given option.
I have been struggling quite a lot with it to get d_30 information. Could you or someone from the team help review. Also, I did upgrade to the plus plan earlier this week.
Code is below
“”"
Import necessary modules
import asyncio
import json
import ssl
import upstox_client
import websockets
from google.protobuf.json_format import MessageToDict
import MarketDataFeedV3_pb2 as pb
def get_market_data_feed_authorize(api_version, configuration):
“”“Get authorization for market data feed.”“”
api_instance = upstox_client.WebsocketApi(
upstox_client.ApiClient(configuration))
api_response = api_instance.get_market_data_feed_authorize(api_version)
return api_response
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
Configure OAuth2 access token for authorization
configuration = upstox_client.Configuration()
api_version = '3.0'
configuration.access_token = ''
response = get_market_data_feed_authorize(
api_version, configuration)
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)
data = {
"guid": "hdjhfjkd-3452s2-df",
"method": "sub",
"data": {
"mode": "full_d30",
"instrumentKeys": ["NSE_FO|50917"]
}
}
binary_data = json.dumps(data).encode('utf-8')
await websocket.send(binary_data)
while True:
message = await websocket.recv()
decoded_data = decode_protobuf(message)
data_dict = MessageToDict(decoded_data)
Print the dictionary representation
print(json.dumps(data_dict))
asyncio.run(fetch_market_data())
“”"