loader2
Partner With Us NRI

Open Free Demat Account Online with ICICIDIRECT

Where to manually find list of stock codes for Breeze API

27 May 2022 0 COMMENT

To start exploring the multiple features of Breeze API, one would need to enter certain parameters for a successful output. For example, in trying to download minute by minute historical data for Ashok Leyland’s stock price on NSE exchange for the 1st week of May, the code should like something like below:

# importing required libraries

from breeze_connect import BreezeConnect

import pandas as pd

 

# generating session through

isec = BreezeConnect(api_key="K%834G9%)2M9z75111V2dP")

isec.generate_session(api_secret="a69+y9097T9r279342xC513O82#ucU1a0",session_token="1117193")

 

# get historical data for Ashok Leyland

data = isec.get_historical_data(interval="1minute",

                            from_date= "2022-05-03T07:00:00.000Z",

                            to_date= "2022-05-06T18:00:00.000Z",

                            stock_code="ASHLEY",

                            exchange_code="NSE",

                            product_type="cash")

 

Please note that the api_key and api_secret are shown for demo purpose only. Users would need to enter their own api key and secret key, as can be seen in the view app section of Breeze Hompage. Refer to our articles on “How to register an App” and “How to generate the session key” to know about the starting process. The links for those are mentioned below:

  1. https://www.icicidirect.com/futures-and-options/api/breeze/article/introduction-to-trading-apis-and-how-to-start-using-breezeapi
  2. https://www.icicidirect.com/futures-and-options/api/breeze/article/what-is-a-session-key-and-how-to-generate-it-for-using-breezeapi

 

What inputs are allowed to go in parameters?

The key thing to note in the above code is that the parameters (like interval, to_date, from_date, stock_code, exchange_code and product_type) can take input in a specific format only. For instance, parameter ‘interval’ will accept “1minute” but not if you enter “1min” or “01m”. Even if you miss a double quote “at the end or start of the parameter, the code would throw an error. This is standard protocol of any programming language (python in this case) and we have to abide by this.

Now the next thing that one would like to know is how to get all the list of available inputs that go in these parameters. For example, at the time of writing this article the parameter “interval” can accept the following inputs:

“1minute” , “5minute” , “30minute” , “1day”

While we are building new capabilities for the Breeze API on a regular basis, make sure you check out our community for regular updates.

Link to Breeze Community:

https://community.icicidirect.com/api

Where to get the list of stock codes?

To get the parameter “stock_code” you will have to go to à

https://api.icicidirect.com/breezeapi/documents/index.html?python#instruments

You can download the Security Master file from the above link. It is generated/updated daily at 8:00 AM.

 

Above is a snapshot of how the .txt file looks from inside. If you want to search the stock code for a particular instrument, simply use “ctrl + f” to find the related instrument.

#Note: You can open the file in excel too, just that, you would need to use a delimiter “,” to separate the field values and create a dataset.

Notice the second column “Short Name” in the dataset. This corresponds to the stock code required in the input parameter of API endpoints.

So let’s say you want to download daily closing price for Reliance Industries Limited from NSE for the entire 2021 year. You should first look for Reliance Industries in the stock master file and on doing so should come across “RELIND” as the short name for Reliance Industries as listed on NSE.

The final code should look something like below:

# importing required libraries

from breeze_connect import BreezeConnect

import pandas as pd

 

# generating session through

isec = BreezeConnect(api_key="K%834G9%)2M9z75111V2dP")

isec.generate_session(api_secret="a69+y9097T9r279342xC513O82#ucU1a0",session_token="1117193")

 

# get historical data for Reliance Industries

data = isec.get_historical_data(interval="day",

                            from_date= "2021-01-01T07:00:00.000Z",

                            to_date= "2021-12-31T07:00:00.000Z",

                            stock_code="RELIND",

                            exchange_code="NSE",

                            product_type="cash") 

 

Similarly, you can look for stock codes for all the asset classes – equity, futures, options etc. using the respective master security file (example : NSE script master or FnO scrip master file) available on the same link as mentioned above on our documentation page à instruments section. 

For more information on Breeze API, please check out our homepage, which contains access to articles, videos and webinars for the same. The link for the same is mentioned below:

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

Disclaimer: ICICI Securities Ltd.( I-Sec). Registered office of I-Sec is at ICICI Securities Ltd. - ICICI Venture House, Appasaheb Marathe Marg, Prabhadevi, Mumbai - 400025, India, Tel No:- 022 - 2288 2460, 022 - 2288 2470. I-Sec is a Member of National Stock Exchange of India Ltd (Member Code:-07730) and BSE Ltd (Member Code :103) and having SEBI registration no. INZ000183631. Name of the Compliance officer (broking): Mr. Anoop Goyal, Contact number: 022-40701000, E-mail address: complianceofficer@icicisecurities.com. Investment in securities market are subject to market risks, read all the related documents carefully before investing. The contents herein above shall not be considered as an invitation or persuasion to trade or invest.  I-Sec and affiliates accept no liabilities for any loss or damage of any kind arising out of any actions taken in reliance thereon.