Last active
October 7, 2019 18:07
-
-
Save PatrickAlphaC/1c40f6944144f124dab750258c957425 to your computer and use it in GitHub Desktop.
Using a threadpoolexecutor in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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