Kotak-Neo / kotak-neo-api

120 stars 112 forks source link

when you disconnect from network and connect again to network, the order feed connect automatically well and works, but throws this error . #192

Open tejas-adhude opened 4 months ago

tejas-adhude commented 4 months ago

Exception in thread Thread-13 (start_hsi_ping_thread): Traceback (most recent call last): File "C:\Users\Tejas\anaconda3\envs\alpine1.0\Lib\threading.py", line 1073, in _bootstrap_inner self.run() File "C:\Users\Tejas\anaconda3\envs\alpine1.0\Lib\threading.py", line 1010, in run self._target(*self._args, **self._kwargs) File "E:#project\inprogress\MERGED\neo_api_client\NeoWebSocket.py", line 47, in start_hsi_ping_thread self.hsiWebsocket.send(json.dumps(payload)) File "E:#project\inprogress\MERGED\neo_api_client\HSWebSocketLib.py", line 1368, in send hsiWs.send(js_obj) File "C:\Users\Tejas\anaconda3\envs\alpine1.0\Lib\site-packages\websocket_app.py", line 239, in send if not self.sock or self.sock.send(data, opcode) == 0: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tejas\anaconda3\envs\alpine1.0\Lib\site-packages\websocket_core.py", line 283, in send return self.send_frame(frame) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tejas\anaconda3\envs\alpine1.0\Lib\site-packages\websocket_core.py", line 311, in send_frame
l = self._send(data) ^^^^^^^^^^^^^^^^ File "C:\Users\Tejas\anaconda3\envs\alpine1.0\Lib\site-packages\websocket_core.py", line 525, in _send return send(self.sock, data) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tejas\anaconda3\envs\alpine1.0\Lib\site-packages\websocket_socket.py", line 143, in send raise WebSocketConnectionClosedException("socket is already closed.") websocket._exceptions.WebSocketConnectionClosedException: socket is already closed

Cloudman0011 commented 4 months ago

Whenever the socket is closed the message is received in this on_close function. What I have done is declare a global variable, example live_data_errors = False and inside on_close method I make it True.. I keep checking it in my main code that if it is true then it means the socket is closed and then I call a function which is for dictionary creation with tokens and other instrument data to call the subscribe method again. I hope it helps..

def on_close(message):
      print('MY SESSION IS CLOSED: ', message)
       live_data_errors = True