# Python api live stream error

**URL:** <https://forum.alpaca.markets/t/python-api-live-stream-error/10085>\
**Category:** Alpaca Trading\
**Created:** [July 22, 2022, 5:00pm UTC](https://forum.alpaca.markets/t/python-api-live-stream-error/10085 "2022-07-22T17:00:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlos\_rubio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/carlos_rubio/32/4460_2.png) [@carlos\_rubio](https://forum.alpaca.markets/u/carlos_rubio)\
**Post date:** [July 22, 2022, 5:00pm UTC](https://forum.alpaca.markets/t/python-api-live-stream-error/10085/1 "2022-07-22T17:00:36Z")

</div>

When I use this code I get the next error:  
(RuntimeError: asyncio.run() cannot be called from a running event loop)

‘’‘’‘’  
import alpaca\_trade\_api as tradeapi

API\_KEY= ’ ’  
API\_SECRET\_KEY= ’ ’  
API\_ACCOUNT\_URL= ‘[https://paper-api.alpaca.markets](https://paper-api.alpaca.markets)’

async def bar\_callback(t):  
print(‘trade’,t)

def main():  
stream = tradeapi.Stream(key\_id=API\_KEY,base\_url=API\_ACCOUNT\_URL, secret\_key=API\_SECRET\_KEY,data\_feed=‘iex’)  
stream.subscribe\_trades(bar\_callback,‘AAPL’)  
stream.run()

data = main()  
‘’‘’‘’’  
I would appreciate any help on how to solve it, thanks.

---

<div class="post-metadata">

**Author:** ![Fairguni](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/fairguni/32/5513_2.png) [@Fairguni](https://forum.alpaca.markets/u/Fairguni)\
**Post date:** [September 12, 2023, 12:19pm UTC](https://forum.alpaca.markets/t/python-api-live-stream-error/10085/2 "2023-09-12T12:19:41Z")

</div>

Did you find your error?
