OHLC Data Fetch History Start Time Inconsistent

Greetings,

I signed up two days ago and tried to use the python API to fetch data using get_barset.
For symbol like SPY I was able to fetch 1min bar data since 2015-01-20 up to now when I just signed up. But when I tried the same query to fetch data today (Jan 24 2020) I can only get data since 2021-01-22. Please let me know why there is a such big inconsistencies in terms of data fetch. Thank you
here is the code available:

fetch_ticker = 'SPY'
fetch_start = pd.Timestamp('2010-01-01 00:00', tz=NY)
fetch_end = pd.Timestamp('2022-01-01 00:00', tz=NY)
bardata = api.get_barset([fetch_ticker], 'minute', start=fetch_start, end=fetch_end)

The get_barset API is quite particular about the formatting of the date. It’s a good practice to use the isoformat() method to do the formatting for you. That may have been the issue? The following fetches all available minute data which you saw originally.

import pandas as pd
import pytz

NY_TIMEZONE = pytz.timezone('America/New_York')

fetch_ticker = 'SPY'
fetch_start = pd.Timestamp('2010-01-01 00:00', tz=NY_TIMEZONE).isoformat()
fetch_end = pd.Timestamp('2022-01-01 00:00', tz=NY_TIMEZONE).isoformat()

bardata = api.get_barset([fetch_ticker], 'minute', start=fetch_start, end=fetch_end)

One unfortunate (IMHO) aspect of the get_barset API is that it fails silently on a bad date format and then simply uses the default dates. In this case, it defaulted to the most current date and then used the default limit of 100 rows. There is a bit more on a similar issue in this post.

2 Likes

Appreciate the prompt reply. Yes you are right. Once I got the data to the right format the fetch result included the 2015 data. Thanks a lot.

Could I know the maximum history that I could fetch for any NYSE symbol as 1 minute data?
i.e. What is the start date that you have for 1 min historical data?

There are two data providers which Alpaca currently provides data for. IEX data is provided for both paper and live accounts. Their historical 1 minute data goes back to 2015. Polygon data is provided free of charge for users with a live funded account. Their minute data goes back to 2004 for most securities.