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)