What is the WebSocket subscription, urls to configured to receive option chain data?

in short what is process of WebSocket to work with option chain???

To access option chain data, it’s crucial to adhere to the guidelines provided on this page: Upstox API Documentation - Market Data Feed. Familiarizing yourself with the Market Data documentation section is advised for seamless integration.

Additionally, we offer sample code for various programming languages, which can be found here: Sample Implementations. Feel free to proceed with the language of your choice. We are continuously updating the SDK and examples to ensure smooth integration.

For subscription purposes, you’ll need to supply the instrument keys, available in both CSV and JSON formats, at Instruments Documentation.

We hope you find this information useful.

1 Like

I AM NOT ABLE TO DO THAT . KINDLY GUIDE ME , I AM ABLE TO FETCH INDEX SPOT THROUGH WEBSOCKET BUT NOT ABLE TO FETCH OPTION CHAIN ,
THIS IS WHERE I AM ABLE TO FETCH ONLY THE INDEX SPOT ,BUT NO OPTION CHAIN.—

import asyncio
import json
import ssl
import upstox_client
import websockets
from google.protobuf.json_format import MessageToDict

import MarketDataFeed_pb2 as pb

received_data = []

def get_market_data_feed_authorize(api_version, configuration):


** 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):


** feed_response = pb.FeedResponse()**
** feed_response.ParseFromString(buffer)**
** return feed_response**

async def fetch_market_data():



** ssl_context = ssl.create_default_context()**
** ssl_context.check_hostname = False**
** ssl_context.verify_mode = ssl.CERT_NONE**


** configuration = upstox_client.Configuration()**

** api_version = ‘2.0’**
** configuration.access_token = ‘…S4iSFMyNTYifQ.eyJzdWIiOiIiLCJqdGkiOiI2NW3…’**


** response = get_market_data_feed_authorize(**
** api_version, configuration)**


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

** await asyncio.sleep(1) **


** data = {**
** “guid”: “someguid”,**
** “method”: “sub”,**
** “data”: {**
** “mode”: “full”,**
** “instrumentKeys”: [“NSE_INDEX|Nifty Bank”,‘NSE_INDEX|Nifty 50’]**
** }**
** }**


** binary_data = json.dumps(data).encode(‘utf-8’)**
** await websocket.send(binary_data)**

** print(‘Subscription request sent’) **


** while True:**
** message = await websocket.recv()**

** decoded_data = decode_protobuf(message)**


** data_dict = MessageToDict(decoded_data)**


** received_data.append(data_dict)**

** print(‘Received data:’, data_dict) **

asyncio.run(fetch_market_data())

GUIDE ME TO FETCH THE OPTION CHAIN .
@Pradeep_Jaiswar