Created
January 29, 2021 05:05
-
-
Save ejdoh1/d2f1c3ced52e5ddc2fbec21ab2b5fd47 to your computer and use it in GitHub Desktop.
Gets a list of stock ticker symbols
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 shutil | |
import urllib.request as request | |
from contextlib import closing | |
import csv | |
URLS = [ | |
{ | |
"url": "ftp://ftp.nasdaqtrader.com/SymbolDirectory/otherlisted.txt", | |
"key": "ACT Symbol" | |
}, | |
{ | |
"url": "ftp://ftp.nasdaqtrader.com/SymbolDirectory/nasdaqlisted.txt", | |
"key": "Symbol" | |
} | |
] | |
symbols = [] | |
for u in URLS: | |
with closing(request.urlopen(u['url'])) as r: | |
with open(u['url'].split("/")[-1], 'wb') as f: | |
shutil.copyfileobj(r, f) | |
with open(u['url'].split("/")[-1], 'r') as f: | |
reader = csv.DictReader(f, delimiter="|") | |
for line in reader: | |
if len(u['key'].split(' ')) == 1: | |
symbols.append(line[u['key']]) | |
print(f'Symbols count: {len(symbols)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment