OHLC Data Fetch History Start Time Inconsistent

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