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.
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
I am trying to get option chain from your above code , but after some time the connevtoon is closed abnormally with error code 1006 with no reason plz help me to resolve this issue