Trying to Run a Candlestick Graph that runs and updates every minute

26 views Asked by At

I want to run a candlestick LQD price graph that updates every minute. I want to be able to automate the process instead of clicking run and getting the values manually. Attached is my code, thank you!

import numpy as np 
import pandas as pd 
import yfinance as yf  
import plotly.graph_objs as go 
import time from datetime import date, datetime  
import matplotlib.animation as animation  
import mplfinance as mpf

def animate(ival):
    data = yf.download(tickers='LQD', period= '1d', interval = '1m')
    data['minute'] = pd.to_datetime(data['minute'], format="%m/%d/%Y %H:%M")
    data.set_index('minute', inplace=True)
    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 Spread Evolution',
        yaxis_title='Spread over Benchmark')
    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 = animation.FuncAnimation(fig, animate, interval= 60000)

mpf.show()
0

There are 0 answers