title: Converting continuos stock data in OHLC (Open, High, Low, Close) in JS
body: <p>I have a continuous stream of data in below format, which I want to convert into Open, High, Low and Close based on defined time slices like 5 mins, 10 mins, 30 mins etc.. At the same time the buy_quantity and sell_quantity should also be aggregated according to choosen time slice.
  What is the most efficient way to do this in Javascript on a continous stream of live data coming from websocket. 
  To add to complexity, I have atleast 50 different stock codes or instrument_token coming in.
  Ideal solution would be something like what is available in panda package of python - here is an example <a href="https://www.quantinsti.com/blog/tick-tick-ohlc-data-pandas-tutorial/" rel="nofollow noreferrer">https://www.quantinsti.com/blog/tick-tick-ohlc-data-pandas-tutorial/</a></p>
  
  <pre><code>{ 
      "_id" : "Q6GinQQKKnfA7FrAT", 
      "instrument_token" : NumberInt(11552514), 
      "last_price" : 10711.8, 
      "buy_quantity" : NumberInt(714225), 
      "sell_quantity" : NumberInt(488775), 
      "buySellRatio" : 1.4612551787632346, 
      "timestamp" : "2018 07 03 07:54:52", 
      "oi" : NumberInt(20539500), 
      "oi_day_high" : NumberInt(20539500), 
      "oi_day_low" : NumberInt(19809750)
  }
  { 
      "_id" : "Dwez3LuqLsB6MZRnB", 
      "instrument_token" : NumberInt(11552002), 
      "last_price" : NumberInt(26329), 
      "buy_quantity" : NumberInt(185520), 
      "sell_quantity" : NumberInt(201080), 
      "buySellRatio" : 0.9226178635369008, 
      "timestamp" : "2018 07 03 07:54:52", 
      "oi" : NumberInt(2163040), 
      "oi_day_high" : NumberInt(2170680), 
      "oi_day_low" : NumberInt(2018440)
  }
  { 
      "_id" : "tcDfqRPk3qs2mYmow", 
      "instrument_token" : NumberInt(11552514), 
      "last_price" : 10711.95, 
      "buy_quantity" : NumberInt(713775), 
      "sell_quantity" : NumberInt(490125), 
      "buySellRatio" : 1.4563121652639632, 
      "timestamp" : "2018 07 03 07:54:53", 
      "oi" : NumberInt(20539500), 
      "oi_day_high" : NumberInt(20539500), 
      "oi_day_low" : NumberInt(19809750)
  }
  </code></pre>