alvarobartt / investpy

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

downloading stocks not working for certain stocks #484

Open ghost opened 2 years ago

ghost commented 2 years ago

Hi,

retrieving historical data for certain stocks does not seem to work. For example, I tried:

search_result = investpy.search_quotes(text='nio', products=['stocks'],
                                       countries=['united states'], n_results=1)
print(search_result)

recent_data = search_result.retrieve_recent_data()
print(recent_data.head())

Same when I tried

df = investpy.get_stock_historical_data(stock='NIO',
                                        country='United States',
                                        from_date='01/01/2010',
                                        to_date='18/11/2021')
print(df.tail())

RuntimeError: ERR#0018: stock nio not found, check if it is correct.

I have checked the investing.com site and there I see the historical data. So, the data exist for the stock in this example.

vkhamesi commented 2 years ago

Hi,

Not 100% sure about this, but after trying to debug your code and what the get_stock_historical_data() function in investpy/stocks.py really does, it seems (line 588) that it tries to check in the file investpy/resources/stocks.csv if the stock you are looking for (symbol: NIO, href: nio-inc) is in it or not. And after all, a quick search shows that NIO stock is not hard coded in the stocks.csv file.

One temporary solution may be to clone the repo on your own, insert an appropriate line in stocks.csv for the NIO stock you are looking for, which in my opinion look like this: united states,Nio A ADR,Nio Inc Class A ADR,nio-inc,US62914V1061,{insert_index},USD, NIO The insert_index should be between the past and the next value, an easy way to do would be to put the line at the end and use the last index + 1.

Then, import the "new" investpy package you just modified. Hope it helped.

aphi commented 2 years ago

The third-to-last column in stocks.csv is an ID used by investing.com (rather than an arbitrary insertion index), so it must be correct.

I created a script here to extract and format these values.

Since I was already creating a PR to add a stock for my own purposes, I included NIO along with mine: https://github.com/alvarobartt/investpy/pull/525