Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stock_info.tickers_sp500() returning strings of underscores #105

Open
GrainsofSalt opened this issue Apr 25, 2023 · 6 comments
Open

stock_info.tickers_sp500() returning strings of underscores #105

GrainsofSalt opened this issue Apr 25, 2023 · 6 comments

Comments

@GrainsofSalt
Copy link

GrainsofSalt commented Apr 25, 2023

from yahoo_fin import stock_info as si
tickers = si.tickers_sp500()
print(tickers)

returns this:
['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '----', '-----', '-----', '-----']

@3den
Copy link
Contributor

3den commented May 24, 2023

I'm having the same problem, that only to happens tickers_sp500, dow and nasdaq work fine

@3den 3den mentioned this issue May 24, 2023
@3den
Copy link
Contributor

3den commented May 24, 2023

I sent a pr to fix it, not sure when it will get merged

@rnbguy-zz
Copy link

Any updates on this?

@j2r2jones
Copy link

I'm also having this issue, any updates?

@peanutsee
Copy link

A little late, but this package seems old and it's not being maintained. A work around:

sp500_tickers = pd.read_html("https://en.wikipedia.org/wiki/List_of_S%26P_500_companies")[0]['Symbol'].to_list()

@GrainsofSalt
Copy link
Author

GrainsofSalt commented Feb 4, 2025

Yeah, it seems the problem is with their API. The underlying methods still work. I would suggest as a work around people just use them directly. For sake of ease:

import pickler as pickle
import ftplib
import io
import pandas as pd

def tickers_snp():
tickers = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0].Symbol.tolist()
return tickers

def tickers_nasdaq(include_company_data = False):
ftp = ftplib.FTP("ftp.nasdaqtrader.com")
ftp.login()
ftp.cwd("SymbolDirectory")

r = io.BytesIO()
ftp.retrbinary('RETR nasdaqlisted.txt', r.write)

if include_company_data:
    r.seek(0)
    data = pd.read_csv(r, sep = "|")
    return data

info = r.getvalue().decode()
splits = info.split("|")


tickers = [x for x in splits if "\r\n" in x]
tickers = [x.split("\r\n")[1] for x in tickers if "NASDAQ" not in x != "\r\n"]
tickers = [ticker for ticker in tickers if "File" not in ticker]    

ftp.close()    

return tickers

def tickers_dow(include_company_data = False):
site = "https://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average"

table = pd.read_html(site, attrs = {"id":"constituents"})[0]

if include_company_data:
    return table

dow_tickers = sorted(table['Symbol'].tolist())

return dow_tickers    

def tickers_clean(tickers):
return [s for s in tickers if not (len(s) == 5 and s[-1] in {'W', 'R', 'P', 'Q'})]

if name=="main":
tickers = tickers_clean(tickers_snp())
print("snp: ", tickers, "\n")
pickle.pickleDump(tickers, "./tickers/snp")

tickerss = tickers_clean(tickers_nasdaq())
print("nasdaq: ", tickerss, "\n")
pickle.pickleDump(tickerss, "./tickers/nasdaq")

tickersss = tickers_clean(tickers_dow())
print("dow: ", tickersss, "\n")
pickle.pickleDump(tickersss, "./tickers/dow")

print("SNP: ", pickle.pickleRead("./tickers/snp"), "\n")
print("NASDAQ: ", pickle.pickleRead("./tickers/nasdaq"), "\n")
print("DOW: ", pickle.pickleRead("./tickers/dow"), "\n")

This will also pickle the output to a local folder called "tickers" incase something changes with the scraping in the future, you can have the lists locally.

-- Sorry, not sure why it is formatting poorly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants