investpy icon indicating copy to clipboard operation
investpy copied to clipboard

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

Open KalinNonchev opened this issue 2 years ago • 6 comments

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,

KalinNonchev avatar Nov 20 '21 09:11 KalinNonchev

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

yuchio8156 avatar Nov 23 '21 09:11 yuchio8156

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.

karim1104 avatar Dec 20 '21 03:12 karim1104

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

simona-juv avatar Jan 18 '22 17:01 simona-juv

@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.

KalinNonchev avatar Jan 18 '22 17:01 KalinNonchev

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

simona-juv avatar Jan 18 '22 17:01 simona-juv

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

ymyke avatar Apr 30 '22 08:04 ymyke