Trying to run an Intraday Chart from Yahoo that runs and updates every 5 minutes Mondays through Fridays

34 Views Asked by At

I have an LQD Price Graph importing data from Yahoo Finance. I think I have a pretty good base line of code but struggling to execute. Trying to run Funcanimation function to time the run in 5-minute intervals but getting some Attribute Errors. Essentially, I want the graph to run and update automatically. Thank you!

def is_market_hours():
     now=datetime.now()
     market_start = now.replace(hour=9, minute=30, second= 0, microsecond=0)
     market_end = now.replace(hour=16, minute=0, second=0, microsecond=0)
     return market_start <= now <= market_end and now.weekday() , 5
     def run_LQDYahoo():
         if is_market_hours():
             data = yf.download(tickers='LQD', period= '1d', interval = '5m')
             fig = go.Figure()
             fig.add_trace(go.Candlestick(x=data.index, 
                                         open=data['Open'],
                                         high=data['High'],
                                         low=data['Low'],
                                         close=data['Close'], name = 'market data'))
             fig.update_layout(
                    title='LQD Live Price Evolution',
                    yaxis_title='Price')
             fig.update_xaxes(
                    rangeslider_visible=True,
                    rangeselector=dict(
                         buttons=list([
                            dict(count=15, label="15m", step="minute", stepmode="backward"),
                            dict(count=45, label="45m", step="minute", stepmode="backward"),
                            dict(count=1, label="HTD", step="hour", stepmode="todate"),
                            dict(count=2, label="3h", step="hour", stepmode="backward"),
                            dict(step="all")
                         ])
                    )
                )

ani = FuncAnimation(fig, is_market_hours, frames = None, interval =300000)

fig.show()
0

There are 0 best solutions below