Websocket stops receiving data

Hi all,

My Python Websocket stops receiving data a fixed times (e.g. 10.00u or 16.00)u. This after running for quitte some hours. How can I keep it alive? Any sample scripts?

It start with:
binance_socket_manager._start_futures_socket(‘ethusdt@trade’, self.handle_tick)

Thx! WJ

Hi. Could you please check the following points?

  1. How many hours had it past since the connection was established? Single connection is only valid for 24 hrs. https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams
  2. If you are using a library, you may want to check its implementation details, such as how it keeps the connection alive or in what condition, it terminates the connection.
  3. Maybe this example is not highly relevant but you can take a look at it and see how it handles the connection. https://github.com/binance-exchange/binance-toolbox-python/blob/master/spot/manage_local_order_book.py

Thx for your reply. How can I keep it running after 24 hours? I want it to run continuously…

class WebSocketTester:
    def __init__(self, ):

        self.client = Client()
        self.start_socket()

    def start_socket(self):

        try:
            binance_socket_manager = BinanceSocketManager(self.client)
            binance_socket_manager._start_futures_socket('ethusdt@trade', self.handle_tick)
            conn_key = binance_socket_manager.start()

        except Exception as e:
            print('Exception in TimerWS.start_socket:', e)

    def handle_tick(self, msg):

        print(msg)


if __name__ == '__main__':
    po = WebSocketTester()