0

Is it possible to add .sleep() to this:

data = web.DataReader(ticker, 'yahoo', start, end)

I would like the sleep function to start every 10 seconds for a duration of 5 seconds. I want to do this because I think there is a problem with yahoo finance connection, which seems cuts out when I download bulk data. It works fine when I query just 1 symbol but gives and error such as

SymbolWarning: Failed to read symbol: 'BRK.B', replacing with NaN.
warnings.warn(msg.format(sym), SymbolWarning)

Full code :

start = datetime.date(2008,11,1)
end = datetime.date.today()
# df = web.get_data_yahoo(tickers, start, end)
df = web.DataReader(tickers, 'yahoo', start, end)

enter image description here

3
  • 2
    The answer to is it possible is almost always yes. This question is vague and it's unclear what you want the sleeping to accomplish. You need to share more of your code for some solid answers, but as it stands, my suggestion is to put time.sleep(10) at the bottom of whatever loop you're using to fetch values. Commented Nov 18, 2019 at 19:36
  • The error is unrelated to the sleep functionality. As @SyntaxVoid mentioned, without the code, it will be difficult to provide further guidance. Commented Nov 18, 2019 at 19:39
  • I have a list called ticker. Which is being passed to to pandas_datareader. I have shared the full code above as well as picture of symbol warning. Commented Nov 18, 2019 at 19:43

1 Answer 1

1

You don't have "tickers" defined. One way to do it is to make a list of stockSymbols you want to loop through:

tickers= ['AAPL', 'MSFT', 'AABA', 'DB', 'GLD']

Next, you will have to add the loop to implement a sleep timer.

start = datetime.date(2008,11,1)
end = datetime.date.today()
for stockSymbol in tickers:
    time.sleep(5) #Sleep 5 seconds
    webData[stockSymbol] = web.DataReader(stockSymbol, data_source='yahoo',start= start, end= end, retry_count= 10)   
    time.sleep(5) # Sleep for 5 more seconds, total of 10s waited.
    print(webData[stockSymbol])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.