Api.polygon.historic_agg returns unwanted timestamp

minute_history ={}
minute_history[symbols] = api.polygon.historic_agg(
    size="minute", symbol=symbols, limit=6,to='2020-01-03 14:59:00-0500'

the output seems as below:

i am only looking at last 6 data points (each every last 6 mins before 1-3 14:59 pm. but data shows year 1969 which is incorrect.

What is wrong here. Please help

I should add, it is probably doing what it is supposed to be doing but the result is not what I desire. from the api call is it possible to only return last 6 databars before a specified time (say 14:59:00 PM)

I could do post processing after getting the data frame but ideally would like to fix it in the source so it is efficient.
I added _from=None as well and removed the time part in “to=” and nothing changed. if i remove to it gives post market data as well

minute_history[symbols] = api.polygon.historic_agg(
size="minute", symbol=symbols, limit=6,_from=None,to= '2020-01-03 15:59:00-0500').df

I was playing around with it and this seems to work:
test_df = api.get_barset(symbols, ‘1Min’, limit =6, start=‘2020-01-03 15:59:00-0500’,).df

This might help IF you are just looking to get a pd.DataFrame and use it.
I just don’t understand the difference in



REST.get_barset(symbols, timeframe, limit, start=None, end=None, after=None, until=None)

so I have only used the rest.get_barset()

Hi Chris,
Thank you for the reply

I previously used api.get_barset previously and a lot of data was missing. And I found api.polygon.historic_agg to be more reliable on more granular data. So I am just looking to make api.polygon.historic_agg work which will return only last 6 barset before close.

get_barset works for stocks like “TSLA” and “AMZN” but data seems to be missing for small volume stocks. api.polygon.historic_agg works if i donot use the datetime filter in the query but I do need to somehow filter, may be i an using some wrong syntax?

I can’t believe this issue remains unaddressed. I spent a lot of time debugging to find these expected timestamps to be the culprit. Did you fix it by any chance? Much appreciated!

IDK if it helps I changed my timestamp when I saved the pandas Dataframe in a format that worked for me:
df.to_csv(path_or_buf=’./data/M_2019_12_06.csv’, date_format=’%Y-%m-%d %H:%M:%S’)
I went through the same crap and this allowed me to use the data in my backtest. Maybe you can change the format in some other way? I hope this helps :grin: