alvarobartt / investpy

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

Fail to retrieve all requested etfs #368

Closed dapaexp closed 3 years ago

dapaexp commented 3 years ago

Hi, I'm encounterign some problems in retrieving al the requested etf. In this case I just retrieve 4 over 5 etfs.

available_etfs = ip.etfs.get_etfs(country='italy') available_etfs = available_etfs.rename(columns={'isin': 'isincode'}) isins = ['IE00B4L5Y983','IE00B4WXJJ64','IE00BYZTVT56','IE00B4WPHX27','LU0629459743'] etfs_target = available_etfs.loc[available_etfs['isincode'].isin(isins)] etfs_target

And, after this I cannot find historicale data: investpy.get_etf_historical_data( etf='UBS ETF MSCI World Socially Responsible UCITS USD', country= 'italy', from_date= '01/01/2020', to_date= '03/05/2021')

Receiving this warning: _C:\Users\Administrator\anaconda3\lib\site-packages\investpy\etfs.py:587: Warning: Selected country does not contain the default stock exchange of the introduced ETF. Default country is: "germany" and default stockexchange: "Xetra". warnings.warn(

Thanks for your suppport!

dapaexp commented 3 years ago

Looks like it is missing IE00B4WPHX27

alvarobartt commented 3 years ago

Hi @dapaexp :fire:

As you may know, the investpy.search_quotes() function uses the Investing.com search engine so as to retrieve any financial product, but as you may know, the investpy.get_etfs_historical_data() (applies to any data retrieval function in investpy) retrieves the information from Investing.com based on the IDs stored in the static CSV files.

That means that investpy.search_quotes() contains ALL the information available at Investing.com while all the other functions just some of them, since the Investing.com indexing is tricky and it's hard to keep the script up to date...

So I highly recommend you to just use the investpy.search_quotes() function if the financial product you are looking for is not available in the static CSV files (the error you shared above).

:pushpin: Make sure that you are using the latest investpy version! investpy v1.0.6

Also, in order to retrieve either the recent data, historical data, or the information, you can use the SearchObj class methods! Here's an example of how to do that:

import investpy

search_result = investpy.search_quotes(text='IE00B4WPHX27', products=['etfs'], countries=['germany'], n_results=1)

recent_data = search_result.retrieve_recent_data()
historical_data = search_result.retrieve_historical_data(from_date='01/01/2020', to_date='01/01/2021')
information = search_result.retrieve_information()

To further explore the functionality of investpy.search_quotes() please check [Wiki - investpy.search_quotes()](https://github.com/alvarobartt/investpy/wiki/investpy.search_quotes())

alvarobartt commented 3 years ago

Also, the warning that you shared above tells you that the ETF is available in more than one stock_exchange, so the information may differ between all the available stock exchanges, but that's simply a warning so that you keep it in mind! 👍🏻

alvarobartt commented 3 years ago

BTW here's my recommendation to retrieve the historical data from all the ISIN codes you shared above, feel free to use it or modify it according to your needs! :fire:

import investpy

isins = ['IE00B4L5Y983', 'IE00B4WXJJ64', 'IE00BYZTVT56', 'IE00B4WPHX27', 'LU0629459743']
results = dict()

for isin in isins:
    search_result = investpy.search_quotes(text=isin, products=['etfs'], countries=['germany'], n_results=1)
    results[isin] = search_result.retrieve_historical_data(from_date='01/01/2020', to_date='06/05/2021')

So that results is a Python dictionary where each key-value pair is the ISIN and the historical data (as a pandas.DataFrame) in the introduced date range for each ETF!

:pushpin: And, again, please check that you are using the latest investpy version! investpy v1.0.6

dapaexp commented 3 years ago

Thanks a lot!!