alpacahq / Momentum-Trading-Example

An example algorithm for a momentum-based day trading strategy.
656 stars 218 forks source link

Unauthorized for URL Error #6

Closed jmal1997 closed 5 years ago

jmal1997 commented 5 years ago

Hello!

I'm not a Python programmer at all, so I might be throwing somehow. I'm getting the following output/error when I try to run this program:

Getting current ticker data...
File "D:\John-Michael\Documents\Trading Bot Try 3\algo.py", line 396, in <module>
    run(get_tickers(), market_open, market_close)
  File "D:\John-Michael\Documents\Trading Bot Try 3\algo.py", line 49, in get_tickers
    tickers = api.polygon.all_tickers()
  File "C:\Users\John-Michael\AppData\Local\Programs\Python\Python36\lib\site-packages\alpaca_trade_api\polygon\rest.py", line 152, in all_tickers
    self.get(path, version='v2')['tickers']
  File "C:\Users\John-Michael\AppData\Local\Programs\Python\Python36\lib\site-packages\alpaca_trade_api\polygon\rest.py", line 33, in get
    return self._request('GET', path, params=params, version=version)
  File "C:\Users\John-Michael\AppData\Local\Programs\Python\Python36\lib\site-packages\alpaca_trade_api\polygon\rest.py", line 29, in _request
    resp.raise_for_status()File "C:\Users\John-Michael\AppData\Local\Programs\Python\Python36\lib\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=XXXXXXXXXXXXXXXXXXXX

where XXXXXXXXXXXXXXXXXXXX is my apiKey. Is this a problem with my connection to Polygon? Do you know if there's a fix with this? I've tried going through the code to make sure there's no obvious things I'm missing. Any help would be appreciated. As a side note, I'm using Python 3.6 and ran pip on the requirements.txt file.

jmal1997 commented 5 years ago

I spent many hours trying to figure this out, then I typed the error into Google and saw that I need an actual Alpaca brokerage account. I should know better than that. Sorry, thanks for your hard work :))

jp06980 commented 3 years ago

So this program can only be ran with a brokerage account?