alvarobartt / investpy

Financial Data Extraction from Investing.com with Python
https://investpy.readthedocs.io/
MIT License
1.59k stars 375 forks source link

Stock name not found #456

Open Towasi opened 2 years ago

Towasi commented 2 years ago

I am trying to download the detail of the S&P500 index (the historical price of each of the current stocks in the index).

I notice that to download the historical prices of the index we must use:

_db = investpy.get_index_historical_data (index = "S&P 500", country = 'United States', from_date = "01/01/2021", to_date = "10/14/2021", as_json = True, order = 'ascending', interval = 'Daily')_

and for the stocks:

_db = investpy.get_stock_historical_data (stock = "MMM", country = 'United States', from_date = "01/01/2021", to_date = "10/14/2021", as_json = True, order = 'ascending', interval = 'Daily')_

The problem I have is that there are some stocks in the S&P500 index that are impossible to download with these methods.

This is the list of stocks: ['BBWI', 'CARR', 'CDAY', 'CTRA', 'HWM', 'J', 'LUMN', 'MRNA', 'OGN', 'OTIS' , 'PAYC', 'RTX', 'TT', 'TFC', 'VIAC', 'VTRS']

The error I get is this:

_in get_stock_historical_data raise RuntimeError ("ERR # 0018: stock" + stock + "not found, check if correct"). RuntimeError: ERR # 0018: bbwi stock not found, check if it is correct._

PS: I have already checked the ticker symbol for the stocks on the list, and at least for NYSE and Investing.com they are correct.

Thanks in advance

rvenkkat70 commented 2 years ago

This Error occurs because the mentioned stocks are not available in resources/stock.csv. You can add the missing code to get this working. Please take a backup of this file before any modification to be on safer side. For example let us take CDAY Before adding to stocks.csv import investpy as inv rslt=inv.get_stock_information('CDAY','united states') RuntimeError: ERR#0018: stock cday not found, check if it is correct.

Get the required information by executing the below function

search_result = inv.search_quotes(text='CDAY', products=['stocks'], countries=['united states'], n_results=1) print(searchresult ) {"id": 1073206, "name": "Ceridian HCM Holding Inc", "symbol": "CDAY", "country": "united states", "tag": "/equities/ceridian-hcm-holding-inc", "pair_type": "stocks", "exchange": "NYSE"}

However ISIN is missing from above which can be look up at https://stockmarketmba.com/symbollookup.php

After updating the stocks.csv, rslt=inv.get_stock_information('CDAY','united states') print(rslt) Stock Symbol Prev. Close Todays Range Revenue Open 52 wk Range EPS \ 0 CDAY 125.25 124.51-127.08 912.1M 125.05 78.2-130.35 -0.42

  Volume    Market Cap Dividend (Yield)  Average Vol. (3m) P/E Ratio  \

0 1005971.0 1.904000e+10 N/A(N/A) 1340641.0 -

Beta 1-Year Change Shares Outstanding Next Earnings Date
0 1.36 47.32% 149861732.0 03/11/2021

Hope this helps.

aphi commented 2 years ago

Just in case you're doing this again, I created a script here to extract and format a complete row entry in stocks.csv based on the url on investing.com