alpacahq / alpaca-trade-api-python

Python client for Alpaca's trade API
https://pypi.org/project/alpaca-trade-api/
Apache License 2.0
1.73k stars 538 forks source link

asyncio.run() RuntimeError following ReadMe example #636

Open PBbanana opened 2 years ago

PBbanana commented 2 years ago

Question form pre-submit checklist.

Question

Hello,

I am new to the Alpaca API, thank you for making this resource available.

I have started with the examples in the documentation (ReadMe.md). I had no issues with the REST API to retrieve historical data. However, I can't run the example under Live Stream Market Data. Everything seems fine until I get to the command:

stream.run()

When I execute it, I get the error:

Traceback (most recent call last): Input In [12] in <cell line: 1> stream.run()

File ~/opt/anaconda3/envs/trade/lib/python3.8/site-packages/alpaca_trade_api/stream.py:1005 in run asyncio.run(self._run_forever())

File ~/opt/anaconda3/envs/trade/lib/python3.8/asyncio/runners.py:33 in run raise RuntimeError( RuntimeError: asyncio.run() cannot be called from a running event loop

Any guidance is much appreciated Thanks!

PBbanana commented 2 years ago

In case anyone encounters this problem, the issue I had was due to incompatibility between asyncio and my IDK (spyder). I switched to pycharm, seems to work fine