RomelTorres / alpha_vantage

A python wrapper for Alpha Vantage API for financial data.
MIT License
4.25k stars 740 forks source link

Asyncio example code throws errors #337

Closed Omidgholi closed 1 year ago

Omidgholi commented 1 year ago

DeprecationWarning: There is no current event loop: loop = asyncio.get_event_loop()

DeprecationWarning: There is no current event loop: group1 = asyncio.gather(*tasks)

Taken from the provided example code

import asyncio
from alpha_vantage.async_support.timeseries import TimeSeries

symbols = ['AAPL', 'GOOG', 'TSLA', 'MSFT']

async def get_data(symbol):
    ts = TimeSeries(key="KZ2BLSHOXOXZRU4V")
    data, _ = await ts.get_quote_endpoint(symbol)
    await ts.close()
    return data

loop = asyncio.get_event_loop()
tasks = [get_data(symbol) for symbol in symbols]
group1 = asyncio.gather(*tasks)
results = loop.run_until_complete(group1)
loop.close()
print(results)
AlphaVantageSupport commented 1 year ago

Closing for now. Will reopen if there is further community response. Thanks!