0

I want to compile a list of the stocks that fit the criteria I set. I am looking at companies that have a market cap between $150,000 and $10,000,000 (in millions). When running the code below I am getting an error. I want to know what exactly I am doing wrong

''' import yfinance as yf, pandas as pd, shutil, os, time, glob, smtplib, ssl from get_all_tickers import get_tickers as gt

tickers = gt.get_tickers_filtered(mktcap_min=150000, mktcap_max=10000000)

print("The amount of stocks chosen to observe: " + str(len(tickers)))

'''

Additional Data:

runfile('A:/Misc Financial Docs/stocks_data/OBV_Email.py', wdir='A:/Misc Financial Docs/stocks_data') Traceback (most recent call last):

File "A:\Misc Financial Docs\stocks_data\OBV_Email.py", line 13, in tickers = gt.get_tickers_filtered(mktcap_min=150000, mktcap_max=10000000)

File "c:\users\aos82\appdata\local\programs\python\python39\lib\site-packages\get_all_tickers\get_tickers.py", line 84, in get_tickers_filtered tickers_list.extend(__exchange2list_filtered(exchange, mktcap_min=mktcap_min, mktcap_max=mktcap_max, sectors=sectors))

File "c:\users\aos82\appdata\local\programs\python\python39\lib\site-packages\get_all_tickers\get_tickers.py", line 145, in __exchange2list_filtered df = __exchange2df(exchange)

File "c:\users\aos82\appdata\local\programs\python\python39\lib\site-packages\get_all_tickers\get_tickers.py", line 134, in __exchange2df df = pd.read_csv(data, sep=",")

File "c:\users\aos82\appdata\local\programs\python\python39\lib\site-packages\pandas\io\parsers.py", line 605, in read_csv return _read(filepath_or_buffer, kwds)

File "c:\users\aos82\appdata\local\programs\python\python39\lib\site-packages\pandas\io\parsers.py", line 463, in _read return parser.read(nrows)

File "c:\users\aos82\appdata\local\programs\python\python39\lib\site-packages\pandas\io\parsers.py", line 1052, in read index, columns, col_dict = self._engine.read(nrows)

File "c:\users\aos82\appdata\local\programs\python\python39\lib\site-packages\pandas\io\parsers.py", line 2056, in read data = self._reader.read(nrows)

File "pandas_libs\parsers.pyx", line 756, in pandas._libs.parsers.TextReader.read

File "pandas_libs\parsers.pyx", line 771, in pandas._libs.parsers.TextReader._read_low_memory

File "pandas_libs\parsers.pyx", line 827, in pandas._libs.parsers.TextReader._read_rows

File "pandas_libs\parsers.pyx", line 814, in pandas._libs.parsers.TextReader._tokenize_rows

File "pandas_libs\parsers.pyx", line 1951, in pandas._libs.parsers.raise_parser_error

ParserError: Error tokenizing data. C error: Expected 1 fields in line 23, saw 4

1
  • Hello. Please 1) Type your question 2) Give example datas 3) Give reproducible example 4 ) Use triple quote for code. stackoverflow.com/help/formatting Commented Feb 3, 2021 at 15:16

1 Answer 1

2

this appears to have to do with a new URL for the Nasdaq API. The authors have a ticket open here: https://github.com/shilewenuw/get_all_tickers/issues/12. Basically there's a new header that they use.

import pandas as pd

headers = {
    'authority': 'api.nasdaq.com',
    'accept': 'application/json, text/plain, */*',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
    'origin': 'https://www.nasdaq.com',
    'sec-fetch-site': 'same-site',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'referer': 'https://www.nasdaq.com/',
    'accept-language': 'en-US,en;q=0.9',
}

params = (
    ('tableonly', 'true'),
    ('limit', '25'),
    ('offset', '0'),
    ('download', 'true'),
)

r = requests.get('https://api.nasdaq.com/api/screener/stocks', headers=headers, params=params)`
data = r.json()['data']
df = pd.DataFrame(data['rows'], columns=data['headers'])

Also in the link above, there's a contributor that provides a full replacement for the get_tickers.py file that I used and it works for me.

Sign up to request clarification or add additional context in comments.

1 Comment

Doesn't work anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.