[API] How to Terminate websocket conditionally

Hi @Dhan , @Dhan_Cares, @Hardik ,

  1. Just like I start the wss using feed.run_forever(), what is the syntax to end dhan wss?
    I tried feed.close(), but doesn’t seems to work

  2. Also once feed.run_forever() is started, can we subscribe or unsubscribe instruments?

Hello @TraderX

  1. We are working on few updates on DhanHQ Python Library, this should be fixed post that.
  2. Yes, you can, using subscribe_symbols function.
1 Like

How to disconnect the sockets?

Hi @Hardik,

is there an update on way to terminating the feed condition basis?

Hi @Tradex,

Were you able to find an alternative way to terminate the feed

Hey there, I am simply looking for a code to stream live data of symbols using websocket. by any chance would you be able to me with such?

is this issue fixed ?
how to close the socket conditionally ?

@Hardik , any update on this? Thanks

Hello @bharathi_komaravolu

Welcome to MadeForTrade community!

You can do that by terminating the loop. We are adding function soon which will allow to close it conditionally as well.

@TraderX Hope this answers your question.

1 Like

Thanks @Hardik , looking forward to it

Hy…

I am new to Api trading and phython. I am learning… Can anyone help to login my account in Dhan Api. I am not able to login account.
when i am login through dhan api. this msg is shown… " ModuleNotFoundError: No module named ‘websockets’
Any can help me.

Hello @Hemant_alw

Welcome to MadeForTrade community!

Yes, you can update your dhanhq library, we have added websockets as a requirement while installing library itself.

Update with:

pip install --upgrade dhanhq

Hi Hardik,

I tried implementing the DhanHQ Live feed using WebSockets in Android kotlin. However, after sending the data in required format it never hits the OnMessage to read the data. Do you have any sample code for Android?

Hello @Vineet_Kum

Welcome to MadeForTrade community!

Usually the issue happens in authorising/sending the subscription packets itself. Once that is done, the data is published irrespective of the client device. Can you check the same if that is as per documentation itself?

Yes, it is as per documentation. Authorisation was successful, and after which I’m sending only 1 instrument. Basically it should a byte size of 108. It is same as per the documentation, however, after I send, it is not hitting back the OnMessage to read the data. Since it’s binary, it gets a bit difficult to see if the bytes format are proper.

@Vineet_Kum

I guess this is where the issue is. Even if you are subscribing to 1 instrument, the byte size should be 2187, as you will have to send the rest of instrument list padded as 0.