Skip to content

Websocket doesn't re-subscribe upon disconnect #24

Description

@novicetopython

Thanks for your great work on this.

The websocket re-connects on a disconnect but doesn't seem to re-subscribe to channels.

2024-02-14 04:48:48.092 | ERROR | pybitget.stream:__on_error:235 - Connection to remote host was lost.
2024-02-14 04:48:48.093 | INFO | pybitget.stream:__re_connect:252 - start reconnection ...
2024-02-14 04:48:48.095 | INFO | pybitget.stream:__on_close:241 - ws is closeing ......close_status:None,close_msg:None
2024-02-14 04:48:49.505 | INFO | pybitget.stream:__on_open:179 - connection is success....
2024-02-14 04:48:49.566 | INFO | pybitget.stream:__on_open:179 - connection is success....

I have edited stream.py as below in to close the connection and then wait in case it needs time until properly logged in before trying to re-subscribe

def __re_connect(self):
    if not self.__keyboard_interrupt_flag:
        self.__reconnect_status = True
        logger.info("start reconnection ...")
        # Close the current connection
        self.__close()
        # Rebuild the connection
        self.build()
        # Wait for the connection to be established before resubscribing
        while not self.has_connect():
            time.sleep(1)
        for channel in self.__all_suribe:
            self.subscribe([channel])            
        #pass
        logger.info("Resubscribed to channels: {}".format(self.__all_suribe))

Could ideally do with the script catching KeyboardException (I have tried to implement within stream.py but isn't error free) and a close and reconnect if no messages received for a period of time.

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions