Inconsistent Bars Between Stocks

I am using the free tier of Alpaca, and I am accessing the SIP historical single stock feed with 1 hour intervals from March 1st, 2024 (start) to March 3rd, 2024 (end). The limit I have set is 1000.

When I access the historical data for multiple stocks (each with single stock), I am receiving different numbers of bars for each stock:

Stock Symbols Num Bars Returned
PLTR 17
BKR 9
V 13
CSX 10
VZ 16
KO 16

Alpaca endpoint being used: Historical bars (single symbol)

Is there any way to alleviate this and have consistent data throughout each stock?

@savojosh The limit parameter doesn’t really work as one may expect. It is actually the total number of bars returned (across all requested symbols) and not the number of bar for each symbol. There is a direct way to request a specific number of bars per symbol.

Really the best approach is to not include a limit and simply provide a start and end time. Once the bars are fetched one can select the number of bars locally.

I removed the limit parameter from my requests URL, but I am still having the same issue.

My URL is:
https://data.alpaca.markets/v2/stocks/{}/bars?timeframe={}&start={}-{}-{}T{}%3A{}%3A{}Z&end={}-{}-{}T{}%3A{}%3A{}Z&adjustment=all&feed=sip&sort=asc
where I fill in all of the brackets with the relevant information.

@savojosh Bars are only created if there are ‘valid’ trades during the bar. No valid trades, then no bar. There will often be ‘missing’ bars because of this. Take a look at this article for how bars are created. Could that be the issue?

That could definitely be it. Is there another endpoint you would recommend instead of using bars? I am mostly interested in the closing price currently.

@savojosh Maybe use the latest_bars endpoint. That is updated each minute after the bar is generated. You may also want to look at the latest_quotes endpoint. I am not a big fan of looking at ‘prices’. First, they occurred in the past and don’t necessarily imply anything about what a current order will fill at. Moreover, one doesn’t really know anything about the order that got that ‘price’. If you are interested in what an order will fill at now, or what the ‘price’ now will be, look at the current quote. Buy orders typically fill at the ‘ask’ and sell orders at the ‘bid’. Those are really the ‘current prices’.