Issue Connecting to Polygon

I am using the example https://medium.com/automation-generation/build-a-day-trading-algorithm-and-run-it-in-the-cloud-for-free-805450150668 and have followed all the instructions. When running I get the error:

Getting current ticker data…
Traceback (most recent call last):
File “algo.py”, line 396, in
run(get_tickers(), market_open, market_close)
File “algo.py”, line 49, in get_tickers
tickers = api.polygon.all_tickers()
File “/home/gferguson1815/.local/lib/python3.6/site-packages/alpaca_trade_api/polygon/rest.py”, line 212, in all_tickers
self.get(path, version=‘v2’)[‘tickers’]
File “/home/gferguson1815/.local/lib/python3.6/site-packages/alpaca_trade_api/polygon/rest.py”, line 35, in get
return self._request(‘GET’, path, params=params, version=version)
File “/home/gferguson1815/.local/lib/python3.6/site-packages/alpaca_trade_api/polygon/rest.py”, line 31, in _request
resp.raise_for_status()
File “/home/gferguson1815/.local/lib/python3.6/site-packages/requests/models.py”, line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.polygon.io/v2/snapshot/locale/us/markets/stocks/tickers?apiKey=XXXX

I have a Polygon account but in the above I am using the API key from the Alpaca dashboard for paper trading.

How do I resolve?

just letting you know , i don’t believe you can use that in paper.

1 Like

Kris is correct. You cannot access polygon data through the Alpaca API with a paper trading account. You will need to open a live account and make sure to change your endpoint to https://api.alpaca.markets.

1 Like

I changed to live endpoint and regenerated the api key and the secret and still seeing same error. I have 15K in my account. does it need 25k? I dont think so.

i have the same issue. were you able to resolve it?

I have the same issue in live account too. It worked until I needed to regenerate the api keys and it stopped connecting to Polygon

you forgot to change your api keys on your connection to polygon, when and if you changed it on alpaca

I’m storing the keys in environment variables and restarting my python console after I reset the variables. Anyways, this started working yesterday without changing anything.