How do you listen to multiple streams simultaneously?

jeanthon
I am writing a piece of code in Python and Asyncio to receive and store real time data using websockets. I have some very general questions about the general principles. Suppose that I have two websocket connections open, receiving real time data from two different servers. How do I make sure not to miss any messages? I have learned a bit of asynchronous programming (python asyncio) but it does not seem to solve the problem: when I listen to one connection, I can miss a message on the other connection, right?
I can think of two solutions: the first one would require that the servers use a buffer system to send their data, but I do not think this is the case in the crypto world (Binance, Bitfinex...). The second solution I see is to listen each websocket using a different core. If I have 8 cores available I can listen to 8 connections and be sure not to miss any messages. Am I missing something here? Many thanks.
  • sujith
    I am not sure about the motive behind using two connections. You can use one connection and subscribe for up to 2000 instruments with one websocket connection.
    You can refer to this thread to know more about how others are doing this.
Sign In or Register to comment.