alvarobartt / investpy

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

Query historical data for multiple stocks in a single website request in order to solve Error 429 #488

Open KalinNonchev opened 2 years ago

KalinNonchev commented 2 years ago

Hello,

Thanks for the great package! I saw that you are aware of the problem that you are banned when you query information for multiple stocks in a short period of time - https://github.com/alvarobartt/investpy/issues/469. Query for multiple stocks in a single request was also suggested recently - https://github.com/alvarobartt/investpy/issues/57. I would like to ask if you are reevaluating this feature(to query data for multiple stocks in a single website request)? Knowing how many times you can query before getting a ban is not really a long term solution. It is annoying that you get banned for 2 days if you go over this threshold. I think that the multiple stock query is the only sustainable software decision that would solve the problem with Error 429 and significantly relax the burden on Investing.com.

I could imagine that the syntax is like:

import investpy
stocks = ["A", "B"]
investpy.get_stock_historical_data(stock=stocks, 
                                            country='XXX',
                                            from_date='01/01/2020',
                                            to_date='01/01/202')

What do you think?

Best,

yuchio8156 commented 2 years ago

Dear investpy authors, Is it possible to add custom proxy optional parameter to get_data() function? thanks

karim1104 commented 2 years ago

You can create a list of tickers and write a loop with time.sleep(5) to go through them. I've been trying it for a few days, and I haven't been blocked yet. I can't guarantee this will always work, but for now, it seems to be the only solution.

simona-juv commented 2 years ago

Hi Karim, would you mind sharing the code? This issue is quite blocking.

KalinNonchev commented 2 years ago

@simona-juv It would look like

import time
stocks = ["A", "B"]
for stock in stocks:
    data = investpy.get_stock_historical_data(stock=stock, 
                                            country='XXX',
                                            from_date='01/01/2020',
                                            to_date='01/01/202')
   time.sleep(5)

but we still need better solution, otherwise it takes days to query the data for a bunch of stocks.

simona-juv commented 2 years ago

@KalinNonchev thank you, it should work for the moment. But you're right, it would take ages.

ymyke commented 2 years ago

I wrote the tessa package to help with issues such as these. It also implements a more generic solution to the 429 error. See here: https://github.com/alvarobartt/investpy/issues/557