Last active
October 7, 2019 18:07
-
-
Save PatrickAlphaC/fae7d769afa55d5fa3011b0210116359 to your computer and use it in GitHub Desktop.
Using the threadpoolexecutor in all it's glory
This file contains hidden or 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
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: | |
generator = executor.map(lambda ticker:ts.get_daily(symbol=ticker,outputsize='full'), tickers) | |
# for data,meta_data in generator: | |
# print(type(data)) | |
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