API not pulling historical bars

A few issues. 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. If it doesn’t interpret the formatting correctly, it silently errors and uses the default date values. In this case the default is None for the start and the current date for end. So what the code above ends up like is this

barset = api.get_barset(‘AAPL’, ‘minute’, limit=1000)

That defaults to the current day and then counts backwards 1000 minutes.

The data doesn’t go back as far as 2010 (only 2015) but that’s fine. The following will fetch all the available minute data for AAPL

import pandas as pd
import pytz

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

fetch_start = pd.Timestamp('2010-04-02 00:00', tz=NY_TIMEZONE).isoformat()

bardata = api.get_barset(fetch_ticker, 'minute', start=fetch_start)

There is a post relating to a similar issue here. Good luck.

2 Likes