Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Last active October 7, 2019 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickAlphaC/1c40f6944144f124dab750258c957425 to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/1c40f6944144f124dab750258c957425 to your computer and use it in GitHub Desktop.
Using a threadpoolexecutor in python
# For python 3.2+
from alpha_vantage.timeseries import TimeSeries
from concurrent.futures import ThreadPoolExecutor
import os
KEY = os.path.expandvars("$ALPHA_VANTAGE_HIGHER_KEY")
ts = TimeSeries(key=KEY, output_format='pandas')
tickers = ['ATVI','ADBE','AMD','ALXN','ALGN', 'GOOG', 'AMZN', 'AAL', 'ADI', 'AMAT']
def thread_pool():
with ThreadPoolExecutor(max_workers=10) as executor:
future_list = list()
for ticker in tickers:
future = executor.submit(ts.get_daily, symbol=ticker, outputsize='full')
future_list.append(future)
for future in future_list:
future.done()
import timeit
print("Time it took to get 10 tickers in paralell:")
print(timeit.timeit('thread_pool()', setup='from __main__ import thread_pool', number=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment