WebSocket Bars - missing/inconsistent data stream

Hello hello!

I’m consuming minute bars over the web socket and I realised I always have missing bars for some symbols.

I’m opening a connection to get minute bars data for the NASDAQ-100 symbols. Since we are talking about minute bars and not quotes, I would expect to get a bar for each symbol, without exception. So how come I’m not getting data for some symbols?

  • I’m using the @alpacahq/alpaca-trade-api node package
  • I’m subscribing to the bars for all nasdaq symbols (total of 101)
  • on message, I just update a local variable with the latest bars

Even if I leave the code running for a couple of minutes, I always have a few symbols without any bar.

From the last 4 times I ran the code over the last hour, these are the symbols for which I did not get any bar, in order
Run 1: [ 'ASML', 'BIIB', 'CTAS', 'INTU', 'MELI', 'ODFL', 'REGN', 'ROP']
Run 2: [ 'BKNG', 'AVGO', 'CDW', 'KLAC' ]
Run 3: ['MELI']
Run 4: [ 'CTAS' ]

Stripped down, the code is just:

// tickers.length => 101

const bars = new Set();
const socket = alpaca.data_stream_v2;
socket.onConnect(() => {
socket.onStockBar((quote) => {

// show what we got every minute
setInterval(() => {
  console.log(tickers.filter(t => !bars.has(t)));
}, 1_000 * 60);

I think Alpaca is not sending minute bars for symbols without much movement, but my understanding is that I would be getting a minute bar, for every symbol, no matter what. Is my assumption incorrect? What could the issue be?


@Nicola_Ferracin Bars are only created, and therefore only streamed, if there were trades during the bar to calculate. Additionally, not all trades are considered ‘valid’ and used for calculating bars. Many trades are not typical market and buy orders, but rather could be based upon a previously agreed upon price or based upon delivery within 60 days (and not the typical T+2 days). These, would generally be executed at different prices than ‘regular’ trades and therefore are not in included in bar calculations. Also, some of the ‘trades’ are either ‘late’ trades (ie they occurred earlier in the day) or are potentially simply updates to already reported trades. Again, these are not included in bar calculations. One can tell the type of trade by looking at the trade ‘conditions’. Again, no valid trades then no bar. There is an article explaining in more depth how bars are calculated here. Take a look if you are interested.

Hey @Dan_Whitnable_Alpaca , thanks for the thorough answer. I suspected that could be the issue.

1 Like