I am trying to receive minute websocket bars via the Alpaca Stream function. My code is failing with the following error:
error during websocket communication: auth failed
Traceback (most recent call last):
File “/opt/anaconda3/lib/python3.9/site-packages/alpaca_trade_api/stream.py”, line 251, in _run_forever
await self._start_ws()
File “/opt/anaconda3/lib/python3.9/site-packages/alpaca_trade_api/stream.py”, line 105, in _start_ws
await self._auth()
File “/opt/anaconda3/lib/python3.9/site-packages/alpaca_trade_api/stream.py”, line 99, in _auth
raise ValueError(msg[0].get(‘msg’, ‘auth failed’))
ValueError: auth failed
Below is the code I used to run the websocket. Could someone assist in pinpointing the issue here? Seems like the authentication is failing.
async def update_bar_data(self, bar):
#update parameters for symbol
print(bar)
#MAIN FUNC FOR PRICE UPDATE AND ORDER EXECUTION
async def main(self,):
self.define_parameters()
conn = Stream(API_KEY, API_SECRET, base_url = URL(BASE_URL), data_feed = 'sip')
for sym in symbols:
conn.subscribe_bars(self.update_bar_data, sym)
await conn._run_forever()