Python Script to plot Live Stock Chart using Alpha Vantage API

In this tutorial, we would understand how to write a simple python script to plot live stock chart. In the previous tutorials, we have fetched data using Google API, but as a matter of fact Google has recently deprecated it’s API. Also, Yahoo finance API is no longer in use. In order to fetch stock data, we would use Alpha Vantage API in this script. This API is free to use, and can fetch real-time and historical data from all popular exchanges in the world. Check the API documentation here.

Check out all the Python related tutorials in the below link:

Algorithmic Trading using Python


Generate API key from Alpha Vantage website using below link:

Python Script to plot Live Stock Chart

Once the API key is generated, open command prompt and copy past the below commands (one by one) to install alpha_vantage and matplotlib modules:

pip install alpha_vantage

pip install matplotlib

install modules

Python Script to plot Live Stock Chart

from alpha_vantage.timeseries import TimeSeries
import matplotlib.pyplot as plt
import sys

def stockchart(symbol):
    ts = TimeSeries(key='your_key', output_format='pandas')
    data, meta_data = ts.get_intraday(symbol=symbol,interval='1min', outputsize='full')
    print data
    plt.title('Stock chart')

symbol=raw_input("Enter symbol name:")

Here is the output of this script when executed from PyCharm:


At the bottom left of the output screen you can see the options to zoom-in and zoom-out, and scroll through the chart.

Now, let’s understand the code logic and see how it works

The first few import statements are to use the modules we installed in previous step. Next, there is a function where we fetch the intraday data for the symbol entered. Please note that we have use the API key value from Alpha Vantage. Finally the line chart is plotted using the ‘close’ values in the time series.  Similarly you can also plot open, high , low and volume data.

You can explore the Alpha Vantage API documentation, and there are literally lot many features you can make use of. The best thing is that the API usage is free of cost, which is hard to find anywhere else. Let us know in comments section if you have any queries.


  1. hi sir not able to launch chart . i am stuck after installing matplotlib

  2. How to execute the script from pycharm.
    I installed anaconda as pip was not working for installing jupyter. I installed matplotlib in cmd and save script in anaconda folder then I run command python then nothing work

  3. Admin sir, Namaskar pls advice 1. how can we learn fractals for long term investing, pls advice some books and courses 2.which software supports this technology 3 can it be used on amibroker which we are using for sometime. thanks n Regards

  4. Dear Admin,
    Can i get NSE and MCX Real Time Data from this API? If yes can you tell me How symbol Name should use to get RT for these symbols.
    current month BANKNIFTY from NSE and current month CRUDEOIL from Mcx Exchange. Thankyou .

  5. sir i m getting error as ::
    C:\>pip install alpha_vantage
    ‘pip’ is not recognized as an internal or external command,
    operable program or batch file.

    please help me

    • I think you did not install Python properly, maybe you can try reinstalling it. And when running command prompt, run it in administrator mode.

  6. sir i m getting following error in installation
    C:\>pip install alpha_vantage
    ‘pip’ is not recognized as an internal or external command,
    operable program or batch file.
    please help me

    • Hi Charusheela,

      I think you missed to set the environment variable. Can you please go through the article again

Leave a Reply

Your email address will not be published. Required fields are marked *