Kotak-Neo / kotak-neo-api

100 stars 86 forks source link

Websocket keeps disconnecting: "[OnClose]: Function is running HSWebsocket None" #32

Closed syedasif11 closed 11 months ago

syedasif11 commented 11 months ago

It disconnects every 3 minutes or so and throws following message and on_close which is set using neo_api.on_close function is never called by the API:

[OnClose]: Function is running HSWebsocket 1000 [OnClose]: Function is running HSWebsocket None

Kotak-Neo commented 11 months ago

Not happening on our end, please share your client code, team will connect and check.

syedasif11 commented 11 months ago

Here is the code:

def message():
    # Some work...
def reconnect():
    # Check if connection reqd, and if yes, the try reconnection else pass
inst_tokens = [{"instrument_token": str(47871), "exchange_segment": "nse_fo"},
                   {"instrument_token": str(25), "exchange_segment": "nse_cm"}]
client.on_message = message
client.on_close = reconnect
client.subscribe(instrument_tokens=inst_tokens)
sacbhatia commented 11 months ago

It can be because of connection or port issue. Check firewall settings. Alternatively, use on_connect and on_disconnect methods of websockets to log it and analyze.

syedasif11 commented 11 months ago

@sacbhatia Thanks for the suggestion.

shekar3110a commented 5 months ago

I figured out the hardway sometimes If there is any exceptions in the On_message you do loos the socket communication ..

check for any exceptions and handle the same .. This could be one issue and may be more .. just check once