api.polygon.historic_agg returns incorrect timestamp
-
symbols="TSLA" minute_history ={} minute_history[symbols] = api.polygon.historic_agg( size="minute", symbol=symbols, limit=6,to='2020-01-03 14:59:00-0500' ).df df=minute_history[symbols] df
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.
What is wrong here. Please help
-
https://forum.alpaca.markets/ is probably a better place to ask about it.
-
Without knowing nothing about that API I would argue that this call
@Ronan-Dunham said in api.polygon.historic_agg returns incorrect timestamp:
minute_history[symbols] = api.polygon.historic_agg( size="minute", symbol=symbols, limit=6,to='2020-01-03 14:59:00-0500' ).df
returns probably the right things,. i.e.:
- A 1st timestamp which is the beginning of the epoch adjusted for the timezone
-5
(hence 19:00 on 1969-12-31, instead of 00:00 on 1970-01-01) - The 1st additional 5 bars to honor the
limit=6
(1 timestamp bar + 5 data bars) - The
to='2020-01-03 14:59:00-0500'
can obviously not be reached, because there are many more minutes than 6 from the beginning of the simybol (apparently it started trading on2016-06-29 15:25 UTC
, which was probably the pre-market before the opening at15:30 UTC
)
There is no obvious
from
limitation in the call, so the API seems to be doing its best to grant the request as issued. - A 1st timestamp which is the beginning of the epoch adjusted for the timezone
-
Hi @backtrader ,
Thank you for the reply.
api = alpaca_trade_api.REST( base_url=base_url, key_id=api_key_id, secret_key=api_secret)
this is indeed alpaca_trade_api.REST(). How can I get only the last 6 data bars from the code? what changes would i have to make. Would you happen to know? Thanks in advance.
@vladisld I did post in alpaca forum but havenot received any feedback for days. I seem to get help here more often. Sorry didnot mean to spam this forum.
-
To me it would seem sensible to try a
from
parameter.The problem is the
limit=6
, which seems arbitrary. Backfilling is difficult, because you may know what you want, but APIs have to cope with facts like non-trading hours. That's why you usually saysfrom => to
and get the number of bars that are available, regardless of non-trading days and non-trading hours.