skillachie / finsymbols Goto Github PK
View Code? Open in Web Editor NEWObtains stock symbols and relating information for SP500, AMEX, NYSE, and NASDAQ
Obtains stock symbols and relating information for SP500, AMEX, NYSE, and NASDAQ
The index should be updated to 2 3 4 5 (aka, index 2 shouldn't be skipped). Otherwise the sector/industry/headquarters are all wrong.
Hello,
I have conducted a pip install of finsymbols, then attempted the following code:
`import finsymbols
sp500 = finsymbols.get_sp500_symbols()
pprint.pprint(sp500)`
the terminal reports an attribute error: AttributeError: 'module' object has no attribute 'get_sp500_symbols'
please advise.
Thank you.
If you go to: https://en.wikipedia.org/wiki/List_of_S%26P_500_companies and then look at the list of companies added you'll see that GOOGL was added April 3, 2014 and no stock was removed. You'll also note that DISCK was added August 6, 2014 and no symbol was removed. This is because both of these are class C shares of their corresponding company. I'm not sure that this is a bug in wikipedia, but for now we should ensure that finsymbols is able to tolerate this.
Also we should remove the hardcoded /exchanges/SP500.html file. This is giving us old data.
from finsymbols import symbols
sp500 = symbols.get_sp500_symbols()
AttributeError Traceback (most recent call last)
in ()
1 from finsymbols import symbols
----> 2 sp500 = symbols.get_sp500_symbols()
~\Anaconda3\lib\site-packages\finsymbols\symbols.py in get_sp500_symbols()
12 symbol_data_list = list()
13
---> 14 for symbol in symbol_table.find_all("tr"):
15 symbol_data_content = dict()
16 symbol_raw_data = symbol.find_all("td")
AttributeError: 'NoneType' object has no attribute 'find_all'
I installed this into an Anaconda python distribution in Linux.
I ran sp500 = finsymbols.get_sp500_symbols() in a terminal.
The list returned from the command had length of only 341. Same result after running this several times.
The last stock symbols in the list are NU, NRG, NUE, and NVDA.
Any ideas how to correct this?
You can dynamically generate the CSV file from
ftp://ftp.nasdaqtrader.com/SymbolDirectory/nasdaqtraded.txt
which is a better solution than hardcoding the csv because the list will change
EDIT
Even better. It seems like nasdaq has an API that will give you the csv en masse
http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=<exchange>&render=download
so for example this will get you all the csv for NYSE
http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NYSE&render=download
I've installed the package with pip but when I try to run any of them I get the error
from finsymbols import symbols
# amex = symbols.get_amex_symbols()
nyse = symbols.get_nyse_symbols()
print(nyse)
sp500 = symbols.get_sp500_symbols()
print(sp500)
It generates this error, how can we debug or update the repo or can I repurpose, reuse, take over the repo if its depreciated by @skillachie?
Traceback (most recent call last):
File "/Users/username/PycharmProjects/finsymbols/finsymbols/test1.py", line 10, in <module>
nyse = symbols.get_nyse_symbols()
File "/Users/username/PycharmProjects/finsymbols/finsymbols/symbols.py", line 43, in get_nyse_symbols
return _get_exchange_data("NYSE")
File "/Users/username/PycharmProjects/finsymbols/finsymbols/symbols.py", line 61, in _get_exchange_data
symbol_data = fetch_file(url)
File "/Users/username/PycharmProjects/finsymbols/finsymbols/symbol_helper.py", line 73, in fetch_file
file_data = file_fetcher.open(url).read()
File "/Users/username/opt/anaconda3/envs/Python37/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
After running the command:
sp500 = finsymbols.get_sp500_symbols()
I get the following error:
IOError Traceback (most recent call last)
in ()
----> 1 sp500 = finsymbols.get_sp500_symbols()
/Library/Python/2.7/site-packages/finsymbols-0.5.0-py2.7.egg/finsymbols/symbols.pyc in get_sp500_symbols()
8
9 def get_sp500_symbols():
---> 10 page_html = wiki_html('List_of_S%26P_500_companies','SP500.html')
11 wiki_soup = BeautifulSoup(page_html, "html.parser")
12 symbol_table = wiki_soup.find(attrs={'class': 'wikitable sortable'})
/Library/Python/2.7/site-packages/finsymbols-0.5.0-py2.7.egg/finsymbols/symbol_helper.pyc in wiki_html(url, file_name)
90 wiki_html = fetch_file('http://en.wikipedia.org/wiki/' + str(url))
91 #Save file to be used by cache
---> 92 save_file(file_path,wiki_html)
93 return wiki_html
/Library/Python/2.7/site-packages/finsymbols-0.5.0-py2.7.egg/finsymbols/symbol_helper.pyc in save_file(file_path, file_name)
36
37 def save_file(file_path,file_name):
---> 38 saved_file = open(file_path , "w")
39 saved_file.write(file_name)
40 saved_file.close()
IOError: [Errno 13]** Permission denied**: '/Library/Python/2.7/site-packages/finsymbols-0.5.0-py2.7.egg/finsymbols/SP500.html'
I'm trying to download the symbols for the S&P500 in python using finsymbols. This is my code:
from finsymbols import symbols
sp500 = symbols.get_sp500_symbols()
I'm getting this error:
sp500 = symbols.get_sp500_symbols()
Traceback (most recent call last):
File "", line 1, in
sp500 = symbols.get_sp500_symbols()
File "C:\Anaconda3\lib\site-packages\finsymbols\symbols.py", line 8, in get_sp500_symbols
page_html = wiki_html('List_of_S%26P_500_companies', 'SP500.html')
File "C:\Anaconda3\lib\site-packages\finsymbols\symbol_helper.py", line 95, in wiki_html
save_file(file_path, wiki_html)
File "C:\Anaconda3\lib\site-packages\finsymbols\symbol_helper.py", line 39, in save_file
saved_file.write(file_data)
File "C:\Anaconda3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2010' in position 528521: character maps to
Is there anything I can do to fix this? I'm using Anaconda 5.0.0 with Python 3.6 on a Windows 8. Thanks for the help!
and as such the symbol is now in the company column. Need to change the order or find the columns by name
The wiki page contains a "\n" after the symbol name. Need to .replace("\n", "") to trim it
Hi there,
Thanks for the awesome little program. Everything is working fine except for AMEX.
I haven't investigated very far, probably Yahoo changed something.
File "/Users/shaun/Applications/ve/lib/python3.6/site-packages/finsymbols/symbols.py", line 47, in get_amex_symbols
return _get_exchange_data("AMEX")
File "/Users/shaun/Applications/ve/lib/python3.6/site-packages/finsymbols/symbols.py", line 64, in _get_exchange_data
return get_symbol_list(symbol_data, exchange)
File "/Users/shaun/Applications/ve/lib/python3.6/site-packages/finsymbols/symbol_helper.py", line 28, in get_symbol_list
symbol_data_dict['company'] = row[1]
IndexError: list index out of range
Hi there!
The only symbols I'm able to retrieve are S&P 500.
Everything else never returns (no error, just takes forever).
Example:
sp500 = finsymbols.get_sp500_symbols() ## This works
nasdaq = finsymbols.get_nasdaq_symbols() ## never returns
amex = finsymbols.get_amex_symbols() ## never returns
I'm using Python 2.7 and I'm having an issue with get_nasdaq_symbols (see error below). I can get the sp500/amex/nyse symbols just fine with your code, but nasdaq seems to be a problem. The error is:
Traceback (most recent call last):
File "test.py", line 56, in
smbs=finsymbols.get_nasdaq_symbols()
File "C:\Python27\lib\site-packages\finsymbols\symbols.py", line 51, in get_nasdaq_symbols
return _get_exchange_data("NASDAQ")
File "C:\Python27\lib\site-packages\finsymbols\symbols.py", line 64, in _get_exchange_data
return get_symbol_list(symbol_data, exchange)
File "C:\Python27\lib\site-packages\finsymbols\symbol_helper.py", line 28, in get_symbol_list
symbol_data_dict['company'] = row[1]
IndexError: list index out of range
Press any key to continue . . .
My code is:
import finsymbols
smbs=finsymbols.get_nasdaq_symbols()
Sorry I am a novice to Python so the following may be a really green issue but...
I enter the following at python 3.5 prompt ๐
import finsymbols
xx = finsymbols.get_nasdaq_symbols()
Traceback (most recent call last):
File "", line 1, in
File "C:\Anaconda3\lib\site-packages\finsymbols\symbols.py", line 48, in get_nasdaq_symbols
return _get_exchange_data("NASDAQ")
File "C:\Anaconda3\lib\site-packages\finsymbols\symbols.py", line 61, in _get_exchange_data
return get_symbol_list(symbol_data,exchange)
File "C:\Anaconda3\lib\site-packages\finsymbols\symbol_helper.py", line 29, in get_symbol_list
symbol_data_dict['company'] = row[1]
IndexError: list index out of range
I installed using:
pip install finsymbols
Please advise.
Best regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.