Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda