Open sirinath opened 3 years ago
Hi @sirinath, currently invespty
has a big issue, which is related to the static data since it needs to be updated with some sort of frequency but due to the Investing.com limitations is hard to do and takes too long (I may need to rent a server with the buymeacoffee donations so that I can create a script that updates those files lets say once a week or once every two weeks)...
So on, currently, some data may be missing from stocks.csv
which is the static file, even though that data is available in Investing.com, so on I developed the function investpy.search_quotes()
that solves this issue as it's using Investing.com search engine to look for the financial products you want to.
Here's an example of how to use it for your concrete query (note that you can also run this function inside a loop just like you are doing in the code you originally sent):
import investpy
search_result = investpy.search_quotes(text='Aitken Spence Plantation', countries=['Sri Lanka'], products=['stocks'], 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()
Let me know whether this worked for you or not! :+1:
More information available at https://github.com/alvarobartt/investpy/wiki/investpy.search_quotes()
:pushpin: Note. In the recent investpy
versions, the investpy.search_quotes()
function just returns one search result whenever the value for n_results
is 1, which means that instead of expecting a list of SearchObj
class instances, you should just expect one, as shown in the example presented above.
Can I use search to get all stocks in Sri Lanka?
Yes you can @sirinath as long as all the Sri Lanka stocks are available in Investing.com :+1:
Can you make text
optional so one can do something like:
import investpy
search_result = investpy.search_quotes(countries=['Sri Lanka'], products=['stocks'])
Maybe you can introduce the exchange as a parameter also to search by exchange.
@sirinath, sorry to inform you that that's not the way to use the search engine neither from Investing.com nor from investpy
... So I cannot remove the text
parameter and if you leave it empty the function will crash!
The other option is that you go with investpy.get_stocks_list(country='Sri Lanka')
so as to retrieve all the symbols for the static stocks in stocks.csv
. That's the only option you can go with, and if you want to include new stocks or look for new stocks you should just use investpy.search_quotes()
as I described above 👍🏻
Search also cause issues with the following companies:
Aitken Spence Plantation Managements
City Housing & RE
MTD Walkers PLC
Lucky Lanka Milk Processing
Lucky Lanka Milk Processing NV
Mercantile Investments and Finance
J L Morison Sons & Jones
J L Morison Sons & Jones NV
Namal Acuity
Senkadagala Finance
Finance Company Not Voting
Also investpy.get_stocks_list(country='Sri Lanka')
gives 300 results. The stock screen on the website gives 309 results.
When I use:
df = search_result.retrieve_historical_data(
from_date='01/01/2000',
to_date=date.today())
I get error for all tickers.
Ok, let me check that! Make sure that you are properly formatting the date as day/month/year
e.g. today's date in this format is 07/05/2021
.
I'll run a script to check the following list of financial products just as you mentioned above:
Aitken Spence Plantation Managements
City Housing & RE
MTD Walkers PLC
Lucky Lanka Milk Processing
Lucky Lanka Milk Processing NV
Mercantile Investments and Finance
J L Morison Sons & Jones
J L Morison Sons & Jones NV
Namal Acuity
Senkadagala Finance
Finance Company Not Voting
I get
When the stock ASPM is there: https://www.investing.com/equities/aitken-spence-plantation-mana