Websocket subscription not working


Code and error please help fast

Also when used on connect function it throws an error saying: DhanFeed.init() got an unexpected keyword argument ‘on_connect’.

@Hardik

Any updates?

Hello @Akash_Sapkal

Welcome to MadeForTrade community!

Can you confirm which version of DhanHQ Library are you using and if the example code is for that version itself?

V2 version of Dhan HQ library.

@Akash_Sapkal

The sample code you are using was for V1. Hence, the error. Can you check Github and take latest sample code?

Thanks for prompt reply.

Code i am using: from dhanhq import marketfeed

Add your Dhan Client ID and Access Token

client_id = “”
access_token = “”

Structure for subscribing is (exchange_segment, “security_id”, subscription_type)

instruments = [(marketfeed.NSE, “50301”, marketfeed.Ticker)]

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)

Output:
DhanFeed.init() takes 4 positional arguments but 5 were given

1 Like

Any updates on this? @Hardik

Im getting the SAME error. dhanfeed.init() takes 4 positional args but 5 were given. Please fix this. Unable to get any Ltp @Hardik

@Hardik can you please share working code to subscribe to websocket