Multiple live stock charts

by: jfe567, 8 years ago


Hello!, I was doing the Big Data Analytics and Algorithmic Stock Trading series i besides tried different ways to solve it, i cant create multiple live charts. I managed to animate like in the videos one live stock chart but i am having problems with the animate function i think.

I would really appreciate some help. The code below is one of the things i tried but creates 2 figures with the last stock of the list. Thanks for the tutorials!    



# live stock plot for python 3.

n=''
m=''
stocks=[]
stock=''
    
while True:
    try:
        n = int(input('Number stocks to visualize up to 2: '))
        m=n
        break
    except:
        print("That's not a valid option!")

while n>0:

    stock=input('Stock to chart (Leave 0 to exit): ')
    urlToVisit='http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=1d/csv'
    sourceCode = urllib.request.urlopen(urlToVisit).read().decode()
    splitSource = sourceCode.split('n')

    if splitSource[2]=='errorid:1':
        print('Not valid')
        break

    stocks.append(stock)
    n-=1

print(stocks) # Test

if m==1:

    while True:
        stock=stocks[0]
        fig = plt.figure(figsize=(6,3), facecolor='#07000d')
        ani = animation.FuncAnimation(fig, animate, interval=3000)
        plt.show()
    
if m==2:
    
    while True:
        
        for i in stocks:
            fig=plt.figure(stocks.index(i),figsize=(6,3),facecolor='#07000d')
            ani = animation.FuncAnimation(fig ,animate, interval=2000)
        plt.show()
        
        #Continue...



imports and functions called are the same as in the videos.



You must be logged in to post. Please login or register an account.