Last active
April 4, 2020 13:13
-
-
Save afestein/2bb3a6725030e346f60b1272573df8be to your computer and use it in GitHub Desktop.
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
import time | |
import requests | |
symbols = [ | |
"ARA", | |
"LN", | |
"ARCH", | |
"NTB", | |
"TELL", | |
"WINS", | |
"NBEV", | |
"GLBS", | |
"NAK", | |
"VST", | |
"TECK", | |
"EBR", | |
"CRBP", | |
"WRN", | |
"CLF", | |
"LEU", | |
"SKY", | |
"AKS", | |
"GSS", | |
"X", | |
"AMD", | |
"CC", | |
"DGSE", | |
"COE", | |
"AXU", | |
"FBK", | |
"CDE", | |
"AKTS", | |
"DMPI", | |
"SINO", | |
"SID", | |
"EVI", | |
"USAS", | |
"CYBE", | |
"MTL", | |
"GV", | |
"DRD", | |
"JAG", | |
"HCLP", | |
"NVDA", | |
"NXE", | |
"VGZ", | |
"GDS", | |
"NAV", | |
"GPL", | |
"GRVY", | |
"QUAD", | |
"GSV", | |
"CECO", | |
"BGI", | |
"SPAR", | |
] | |
listed_in_target_year = [] | |
for i in range(len(symbols)): | |
symbol = symbols[i] | |
print(f"Checking {symbol}...") | |
api_key = "GRF31138021UY295" | |
api_url = f"https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol={symbol}&apikey={api_key}" | |
request = requests.get(api_url) | |
response = request.json() | |
if "Note" in response: | |
print(response["Note"]) | |
exit() | |
elif "Error Message" in response: | |
print(f"Error fetching data for {symbol}:") | |
print(response["Error Message"]) | |
else: | |
target_year = 2016 | |
keys = list(response["Monthly Time Series"].keys()) | |
earliest_entry = keys[-1] | |
parsed_date = time.strptime(earliest_entry, "%Y-%m-%d") | |
earliest_year = parsed_date.tm_year | |
if earliest_year == target_year: | |
listed_in_target_year.append(symbol) | |
most_recent_entry = keys[0] | |
parsed_date = time.strptime(most_recent_entry, "%Y-%m-%d") | |
most_recent_year = parsed_date.tm_year | |
if i + 1 != len(symbols) and (i + 1) % 5 == 0: | |
print("API limit reached. Sleeping for a minute...") | |
time.sleep(60) | |
print( | |
"The earliest data found for these stocks was in the target year, meaning it was probably an IPO:\n", | |
listed_in_target_year, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment