Hi @Hardik
Simple Python Program gives above error. Can you please share all working Python codes with examples for Dhan API. Also Which specifying which part will work when market is online and when closed. This will solve most of issues for all.
Tried all following combination
from dhanhq import dhanhq, marketfeed
from dhanhq import dhanhq
import marketfeed
Add your Dhan Client ID and Access Token
Actual code replaced
client_id = “11111111”
access_token = “xxxxxx”
dhan = dhanhq(client_id, access_token)
Structure for subscribing is (exchange_segment, “security_id”, subscription_type) 1333 HDFCBANK, 22 ACC
instruments = [(marketfeed.NSE, “1333”, marketfeed.Ticker), # Ticker - Ticker Data
(marketfeed.NSE, “1333”, marketfeed.Quote), # Quote - Quote Data
(marketfeed.NSE, “1333”, marketfeed.Full), # Full - Full Packet
(marketfeed.NSE, “22”, marketfeed.Ticker),
(marketfeed.NSE, “22”, marketfeed.Quote),
(marketfeed.NSE, “22”, marketfeed.Full)]
version = “v2” # Mention Version and set to latest version ‘v2’
In case subscription_type is left as blank, by default Ticker mode will be subscribed.
try:
data = marketfeed.DhanFeed(client_id, access_token, instruments, version)
while True:
data.run_forever()
response = data.get_data()
print(response)
except Exception as e:
print(e)
Close Connection
data.disconnect()
Subscribe instruments while connection is open
sub_instruments = [(marketfeed.NSE, “14436”, marketfeed.Ticker)]
data.subscribe_symbols(sub_instruments)
Unsubscribe instruments which are already active on connection
unsub_instruments = [(marketfeed.NSE, “1333”, 16)]
data.unsubscribe_symbols(unsub_instruments)