title: Binance - Get current price of selected coins through WebSockets
body: <p>Binance offers Web Socket Streams with several functions such as Aggregate Streams, Trade Streams, Kline/Candlestick Streams, etc. that you can see here <a href="https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md" rel="noreferrer">https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md</a></p>
  <p>I'm looking to get the current price &amp; last 24h % change of my selected coins and I can't understand how do I manage to get this information. The prices must be in real time, the 24h % change can be called every 60 seconds or something.</p>
  <p>I'm currently using CoinCap <a href="https://docs.coincap.io/" rel="noreferrer">https://docs.coincap.io/</a> and it's pretty easy:</p>
  <ol>
  <li>To get the 24h % I call the endpoint <code>https://api.coincap.io/v2/assets?ids=bitcoin,ethereum</code></li>
  <li>To get the prices in real time I call the endpoint <code>wss://ws.coincap.io/prices?assets=bitcoin,ethereum</code></li>
  </ol>
  <p>The problem with CoinCap is that I can't filter the prices with the exchange that I want, which in this case is Binance. So I keep getting prices that do not match the Binance.</p>
  <pre><code>var socket = new WebSocket('wss://ws.coincap.io/prices?assets=bitcoin,ethereum');
  socket.addEventListener('message', function (event)
  {
    // parse &amp; show the data
  });
  </code></pre>
  <hr />
  <p>For example, the Kline/Candlestick Streams says the following:</p>
  <blockquote>
  <p>The Kline/Candlestick Stream push updates to the current
  klines/candlestick every second</p>
  </blockquote>
  <p>And returns the following data:</p>
  <pre><code>{
    &quot;e&quot;: &quot;kline&quot;,     // Event type
    &quot;E&quot;: 123456789,   // Event time
    &quot;s&quot;: &quot;BNBBTC&quot;,    // Symbol
    &quot;k&quot;: {
      &quot;t&quot;: 123400000, // Kline start time
      &quot;T&quot;: 123460000, // Kline close time
      &quot;s&quot;: &quot;BNBBTC&quot;,  // Symbol
      &quot;i&quot;: &quot;1m&quot;,      // Interval
      &quot;f&quot;: 100,       // First trade ID
      &quot;L&quot;: 200,       // Last trade ID
      &quot;o&quot;: &quot;0.0010&quot;,  // Open price
      &quot;c&quot;: &quot;0.0020&quot;,  // Close price
      &quot;h&quot;: &quot;0.0025&quot;,  // High price
      &quot;l&quot;: &quot;0.0015&quot;,  // Low price
      &quot;v&quot;: &quot;1000&quot;,    // Base asset volume
      &quot;n&quot;: 100,       // Number of trades
      &quot;x&quot;: false,     // Is this kline closed?
      &quot;q&quot;: &quot;1.0000&quot;,  // Quote asset volume
      &quot;V&quot;: &quot;500&quot;,     // Taker buy base asset volume
      &quot;Q&quot;: &quot;0.500&quot;,   // Taker buy quote asset volume
      &quot;B&quot;: &quot;123456&quot;   // Ignore
    }
  }
  </code></pre>
  <p>Based on this what is the current price that matches the value seen in the Binance Platform <a href="https://www.binance.com/en/markets" rel="noreferrer">https://www.binance.com/en/markets</a>?</p>