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’
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.