Unable to fetch live data for options using API

I am not able to get the live data for options, when I run code no response got.
I am using following code to get live feed.
Is my code correct? Or I need to change the code? Please suggest I am new to DhanHq API.

import pandas as pd
import numpy as np
from dhanhq import marketfeed
from datetime import datetime

import warnings
warnings.filterwarnings(“ignore”)

pd.set_option(‘display.max_rows’, 500)
pd.set_option(‘display.max_columns’, 500)
pd.set_option(‘display.width’, 1000)

scrip_master_path = “/mnt/7A42C8D342C894F3/programming/personal/marketAnalysis/trade/api-scrip-master.csv”
margin_info_path = “/mnt/7A42C8D342C894F3/programming/personal/marketAnalysis/trade/Leverage & Margins for Trading on Scrips.csv”

client_id = “CLIENT ID”
access_token = "MY TOKEN

instruments = [
# (marketfeed.IDX, “13”, marketfeed.Ticker),
# (marketfeed.IDX, “13”, marketfeed.Quote),
# (marketfeed.NSE_FNO, “50426”, marketfeed.Depth),
(marketfeed.NSE_FNO, “50426”, marketfeed.Quote),
]

try:
data = marketfeed.DhanFeed(client_id, access_token, instruments)
while True:
data.run_forever()
response = data.get_data()
print(“RESPONSE”, datetime.now())
print(response)

except Exception as e:
print(“error”)
print(e)

Close Connection

data.disconnect()

Subscribe instruments while connection is open

sub_instruments = [(marketfeed.NSE_FNO, “47168”, marketfeed.Ticker)]

data.subscribe_symbols(sub_instruments)

Unsubscribe instruments which are already active on connection

unsub_instruments = [(marketfeed.NSE_FNO, “47168”, 16)]

data.unsubscribe_symbols(unsub_instruments)

Hello @Anant_Patankar ,

The live market feed from our end is working just fine.
It seems like the error is occurring while subscribing the instrument. You can check the security ID you are subscribing to or the code where you are printing the output.

@Trishul_Devadiga
Thank you for replying.
Can you please provide what is correct way to fetch live data for options chain?

Also as per my knowledge dhan does not provided any code base for examples usage of the API.
Or if there is code examples for using dhan API can you please provide?

1 Like