loader2
Login OPEN ICICI 3-in-1 Account
  • Text Size
  • Text to Speech
  • Color Contrast
  • Pause Animations

How to create charts using Breeze API data?

27 May 2022|
1 min read |
by ICICI Securities Team
Article Image

You might have seen a few articles from our side highlighting the many use-cases of Breeze API. In our relentless pursuit of making you aware of the multi-fold ways of using the data, let us focus on charts as well. If you’re a trader or even a beginner in the field of markets, you must have seen technical charts of markets. These charts can range from simple line graphs to complex candle sticks with multiple technical indicators fitted in.

So in this article, we will be looking at the data visualisation aspect of data. We will first download data for an equity stock using Breeze API and then use the powerful open source libraries like pandas & matplotlib to create charts for the downloaded data. 

Task

We will download daily OHLC data for ITC stock from the start of 2022 and then create a chart for it.

#We have provided each block of code with a simple explanation for your understanding:

1st step is to establish connection with Breeze API using your API keys & Session Token. (Click on the words to know where to find these keys).

from breeze_connect import BreezeConnect
isec = BreezeConnect(api_key=" your api key ")
isec.generate_session(api_secret=" your api secret key",

session_token=" your session key ")

Next step is to download certain libraries that would add to the capability of your code to do multiple things like - do spreadsheet analysis or create charts

#install pandas & matplot lib library
pip install pandas

pip install matplotlib


#import pandas library in your code
import pandas as pd
#import charting library – matplot in your code
import matplotlib.pyplot as plt

Now we will download the daily data for ‘ITC’ share as listed on NSE from start of the year i.e. 01st Jan 2022 to today i.e. 20th May 2022

#downloading daily historical data using Breeze API

data = isec.get_historical_data(interval="1day",
                            from_date= "2022-01-01T07:00:00.000Z",
                            to_date= "2022-05-20T18:00:00.000Z",
                            stock_code="ITC",
                            exchange_code="NSE",
                            product_type="cash")

#storing the above data in a dataframe to operate on it
df = pd.DataFrame(data["Success"])

We will now adjust the data we just received from Breeze API into a workable format. We do this because the data received is in text (String) format and we have to extract numbers from the data.

# convert the 'Close' column to number format
df['new_close'] = df['close'].astype(float)
# convert the 'datetime' column to Date format
df['Date']= pd.to_datetime(df['datetime'])

The last step is to create charts for the 2 columns - date (in X axis) and daily closing price (in Y axis)

#charting the coloumns - 'datetime' and 'closing price' of dataframe
plt.figure(figsize=(13,3))   #size of the chart
plt.title('Closing Price of ITC') #Title of the chart
plt.xlabel('datetime') #label of x axis
plt.ylabel('closing price') #label of y axis

plt.plot(df['Date'], df['new_close'])  #command to plot the dataframe coloumns in a chart

The output should look something like this:

 

Happy learning & Trading!!

Please check out our essential links containing more such snippets:

Home Page: https://www.icicidirect.com/futures-and-options/api/breeze

Breeze Community: https://community.icicidirect.com/api

Python SDK Package: https://pypi.org/project/breeze-connect/

Disclaimericon
Share
instagram facebook twitter linkedin mail whatsApp
Did you enjoy this article?

Related Articles

Recent Articles

View all

Vigilance Awareness Week 2026: Probity for Prosperity

Vigilance Awareness Week 2026 promotes integrity, transparency, and ethical conduct. Join the movement and take the Integrity Pledge today. 

icon5 k views icon1 minutes icon26 Oct 2026

Understanding Contango in Commodity Markets

Understand contango in commodity trading, how futures prices differ from spot prices, and how financing, storage and insurance costs influence commodity pricing.

icon1 k views icon1 minutes icon19 Oct 2026

Know Your Commodity Before You Trade: Copper

Copper is a widely used base metal known for its electrical and thermal conductivity, strength, ductility and corrosion resistance. It is used across electrical wiring, construction, machinery, power infrastructure and several industrial applications.

icon2 k views icon2 minutes icon09 Oct 2026

Download
iLearn application

Elevate Your Financial Knowledge with the
ICICI Direct iLearn App

Download
ICICI Direct app

Elevate Your Financial Knowledge with the
ICICI Direct iLearn App