The get_barset is marked as deprecated in the current Python API sources on GitHub - most probably because it uses the Alpaca Data API v1 endpoint for requesting data.
Absolutely. The documentation is a mess. I’m sure it was quite accurate and organised at the beginning, but now, with so much changes and developments, the documentation is all over the place.
I think Alpaca should completely re-do the documentation from scratch. Maybe present it in a wiki format…
Maybe you know how to fix this based on your question? I went by the documentation (beginner here) and used the example to pull for 2 days of data (current/or close and previous day close). If I change this to get_bars, it breaks.
Do you know how I need to change this to use for the get_bars() instead? I tried changing some parms around, but it seems that I get a different data object back from what I was using.
Thanks for any help!
— Update
I tried to change the date to RFC-3339 type format, but not getting anywhere. Doesn’t like this either. Stuck.
So it appears if I start 1/26/2022 and end 1/27/2022 that I get 2 bars. What I need to do is get previous day and if market is open the most recently delayed 15 min daily bar.
I think @Dan_Whitnable_Alpaca mentioned at some point that, with get_barset(), the bars are calculated backwards (or starting with the most recent one). This is why you can simply put barset = api.get_barset(ticker, ‘day’, limit=2) and get the last 2 days.
For some reason, despite being newer (and supposedly better), get_bars() doesn’t do this. Instead, the bars are calculated forwards, which means you need to specify the start time.
This should get the last two daily bars. As the market is currently open (at time of posting), the results are a bar for today and a bar for yesterday (28th and 27th).
I imagine that, if the market were currently closed, the function would return the previous two days (26th and 27th). I obviously haven’t tested this though.
Thank you so much Maxks90! This works wonderfully. I was able to quickly test to make sure I could run and then merged back into my main program. The rest of the code works great as access by index of bars[0] and bars[1]
Appreciate greatly the time and attention you provided to ensure that I build the right foundation with Alpaca.
@Dan_Whitnable_Alpaca, would it be possible to get this functionality added to get_bars()? I imagine most people would want to get the most recent bars by default, so this would make things a lot easier. Those who want to get bars from a specific date range can simply use the start and end parameters.