alvarobartt / investpy

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

Failure to retrieve investing.com exiting mutual funds by "isin" #356

Open angel-mi-alvarez opened 3 years ago

angel-mi-alvarez commented 3 years ago

Hi Alvaro

the search_funds gives an error when trying to search some existing funds by 'isin' e.g. couple of examples:

ES0124143001

ES0124143019

running this Python code you can reproduce the issue and see the error

search_results = investpy.funds.search_funds(by='isin', value='ES0124143001') search_results.head()

RuntimeError Traceback (most recent call last)

in ----> 1 search_results = investpy.funds.search_funds(by='isin', value='ES0124143001') 2 search_results.head() ~/opt/anaconda3/lib/python3.8/site-packages/investpy/funds.py in search_funds(by, value) 969 970 if len(search_result) == 0: --> 971 raise RuntimeError('ERR#0043: no results were found for the introduced ' + str(by) + '.') 972 973 search_result.drop(columns=['matches'], inplace=True) RuntimeError: ERR#0043: no results were found for the introduced isin.
alvarobartt commented 3 years ago

Hi @angel-mi-alvarez, the function investpy.search_funds() just searches between the indexed funds in the static file funds.csv which is incomplete and not up to date... But for those financial products that are missing in the static files (which is a known error as Investing.com indexing is not that good which makes scraping really hard) you can use the function investpy.search_quotes() so as to search for any financial product available at Investing.com! 🤗

Here's a sample piece of code that you can use:

import investpy

search_result = investpy.search_quotes(text='ES0124143001', products=['funds'], countries=['spain'], n_results=1)
print(search_result)

historical = search_result.retrieve_historical_data(from_date='01/01/2020', to_date='01/01/2021')
print(historical.head())

Note: you need to install the latest investpy version which is investpy v1.0.6, install it using pip install investpy --upgrade.