Historical Data timestamps seem to be odd

Hi , I’m linking up to to the historical feed using the SDK,
but when requesting historical data via some simple code [as per the SDK], the timestamps look random. I’m not using anything pytz-related within the code arguments - i would expect to return a vanilla timeseries df. Any ideas what could be the issue here?

def fetch_historical_bars(self):
    self.client = StockHistoricalDataClient(api_key=alpaca_api_key, secret_key=alpaca_secret)
    request_params = StockBarsRequest(
    bars = self.client.get_stock_bars(request_params=request_params)
    bars_df = bars.df
    bars_df = bars_df.reset_index()
    bars_df.drop('symbol', axis=1, inplace=True)
    return bars_df

alpaca = AlpacaMarketDataSource([‘TQQQ’],
TimeFrame(amount=5, unit=TimeFrame.Minute),
start=dt.datetime(2022, 1, 1),
end=dt.datetime.today(), live=False)

bars = alpaca.fetch_historical_bars()

running pprint.pprint(bars[‘timestamp’][:10]) …


0 2022-01-03 08:30:00+00:00
1 2022-01-03 09:21:00+00:00
2 2022-01-03 10:12:00+00:00
3 2022-01-03 11:03:00+00:00
4 2022-01-03 11:54:00+00:00
5 2022-01-03 12:45:00+00:00
6 2022-01-03 13:36:00+00:00
7 2022-01-03 14:27:00+00:00
8 2022-01-03 15:18:00+00:00
9 2022-01-03 16:09:00+00:00

I’ve checked the full dataframe for busier market hours and the timestamp issue is identical.

@Alun_Thomas The problem stems from your line of code

   `TimeFrame(amount=5, unit=TimeFrame.Minute)`

Notice you are specifying the unit as a TimeFrame and not a TimeFrameUnit. The code should be

   `TimeFrame(amount=5, unit=TimeFrameUnit.Minute)`

It was odd that it still worked and especially, as you noted, returned sort of random times. Anyway, change that and it should return the times as expected.

Dan, thanks so much for your help and replying so quickly, I really appreciate it.



@Alun_Thomas Glad to help. Good luck!