404 error
autoparts494 opened this issue · 10 comments
Getting current ticker data...
Success.
Getting list of assets...
Success.
Tracking 201 symbols.
Getting historical data...
Traceback (most recent call last):
File "C:/Users/colef/PycharmProjects/Code/Python/Momentum-Trading-Example-master/algo.py", line 400, in
run(get_tickers(), market_open, market_close)
File "C:/Users/colef/PycharmProjects/Code/Python/Momentum-Trading-Example-master/algo.py", line 90, in run
minute_history = get_1000m_history_data(symbols)
File "C:/Users/colef/PycharmProjects/Code/Python/Momentum-Trading-Example-master/algo.py", line 40, in get_1000m_history_data
size="minute", symbol=symbol, limit=1000
File "C:\Users\colef\Anaconda3\lib\site-packages\alpaca_trade_api\polygon\rest.py", line 123, in historic_agg
raw = self.get(path, params)
File "C:\Users\colef\Anaconda3\lib\site-packages\alpaca_trade_api\polygon\rest.py", line 37, in get
return self._request('GET', path, params=params, version=version)
File "C:\Users\colef\Anaconda3\lib\site-packages\alpaca_trade_api\polygon\rest.py", line 33, in _request
resp.raise_for_status()
File "C:\Users\colef\Anaconda3\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.polygon.io/v1/historic/agg/minute/ARLO?limit=1000&apiKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Process finished with exit code 1
Can someone please help me with this. I have a valid Brokerage account but it still gives me this error.
I also have this issue using Python 3.8.2. Tried changing the HTTP endpoints in the rest.py, but have not been able to get it to work. Using Postman, I can GET and POST to Alpaca using https://paper-api.alpaca.markets/v2/
as my endpoint. However, the algo still does not have the right endpoints and updating rest.py with different urls has not fixed it. Any help will be appreciated.
I'm also having this same issue:
HTTPError: 404 Client Error: Not Found for url: https://api.polygon.io/v1/historic/agg/minute/
This may be completely wrong, but I believe the V2 looks like this:
Calling API:
minute_history[symbol] = api.polygon.historic_agg_v2( timespan="minute", symbol=symbol, limit=1000, multiplier=1, _from='2020-04-05', to='2020-04-06' ).df
Updated polygon code.
The API now has a v2 function:
def historic_agg_v2(self, symbol, multiplier, timespan, _from, to, unadjusted=False, limit=None): path = '/aggs/ticker/{}/range/{}/{}/{}/{}'.format( symbol, multiplier, timespan, _from, to ) params = {} params['unadjusted'] = unadjusted if limit: params['limit'] = limit raw = self.get(path, params, version='v2') return Aggsv2(raw)
Obviously the dates cannot be hardcoded into the api call but I was testing it, I don't know if this is the right step in the right direction.
I also got that error. Can't figure it out yet as it does not happen each time the algo is ran. I am not sure if the GET request is getting the wrong info or if the JSON isn't being parsed correctly. The current way I call the V2 API is incredibly slow. Not sure if it is the code or if its limitations of the API. Takes about 5 minutes to populate the list of the aggregated data.
This is the response from GET https://api.polygon.io/v2/aggs/ticker/AAL/range/1/minute/2020-04-01/2020-04-06?apiKey=xxxxxxxxxxxx.
{ "ticker": "AAL", "status": "OK", "queryCount": 3241, "resultsCount": 3241, "adjusted": true, "results": [ { "v": 1761, "vw": 11.727, "o": 11.81, "c": 11.5, "h": 11.81, "l": 11.5, "t": 1585728000000, "n": 23 }, { "v": 600, "vw": 11.5, "o": 11.5, "c": 11.5, "h": 11.5, "l": 11.5, "t": 1585728060000, "n": 9 },...............
Added generation of yesterday/today dates to the historical data function using api.polygon.historic_agg_v2
of the API, that was mentioned here: ##14 (comment)
#add date to imports
from datetime import date, datetime, timedelta
def get_1000m_history_data(symbols):
print('Getting historical data...')
minute_history = {}
c = 0
today = date.today()
yesterday = date.today() - timedelta(days=1)
for symbol in symbols:
minute_history[symbol] = api.polygon.historic_agg_v2(
timespan="minute", symbol=symbol, limit=1000, multiplier=1, _from=yesterday.strftime("%Y-%m-%d"), to=today.strftime("%Y-%m-%d")
).df
c += 1
print('{}/{}'.format(c, len(symbols)))
print('Success.')
return minute_history
I am also having this issue but I can't seem to figure out what you did to fix it
Getting current ticker data...
Success.
Tracking 127 symbols.
Getting historical data...
Traceback (most recent call last):
File "algof.py", line 396, in
run(get_tickers(), market_open, market_close)
File "algof.py", line 87, in run
minute_history = get_1000m_history_data(symbols)
File "algof.py", line 38, in get_1000m_history_data
minute_history[symbol] = api.polygon.historic_agg(
AttributeError: 'REST' object has no attribute 'historic_agg'
try this: api.polygon.historic_agg_v2