Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Should I use multiple Websocket for multiple subscription to same url with different parameters

I am creating a React app which uses Websocket to get a data from third party socket. I need subscribe to 5 endpoints where I pass different parameters so I get a different data:

function App() {

  const [topCurrencies, setTopCurrencies] = useState(['BTCUSD', 'LTCUSD', 'LTCBTC', 'ETHUSD', 'ETHBTC']);


  return (
    <div className="App">
      {topCurrencies.map(x => <CurrencyBar currency={x} />)}
    </div>
  );
}

export default App;

Now I because I need to receive each currency data and update "CurrencyBar" component based on it, I decided to use multiple WebSockets:

function CurrencyBar({currency}) {

    const [data, setData] = useState(null)

    useEffect(() => {
        const ws = new WebSocket('wss://api-pub.bitfinex.com/ws/2')
        ws.addEventListener('open', () => {

            let msg = JSON.stringify({
            event: 'subscribe',
            channel: 'ticker',
            symbol: `t${currency}`,
        })

        ws.send(msg);
        })

        ws.addEventListener('message', (event) => {
            setData(JSON.parse(event.data))
        })
    }, [])




    return (
        <>
          {data}
        </>
    )
}

export default CurrencyBar;

My question is is there a better approach because I imagine that creating 5 Websockets instead of 1 can impact a performance (even though The rate limit for the wss://api-pub.bitfinex.com/ domain is set at 20 connections per minute).

Maybe there is a better way where I only use one instance of "WebSocket"API?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda