ICICI Direct Automate Trades Utilizing Free of Cost Breeze Connect API in Python

Breeze API: Registration & Login Guide

Breeze API: Checksum Computation & Login

1. App Registration (OAuth 2.0)

Authentication follows the OAuth 2.0 protocol to ensure all request fields are protected from tampering.

To register an app on the Breeze API portal, provide the following:

  • App Name
  • Redirect URL: https://127.0.0.1

After successful registration, you will receive a unique pair of keys:

  • App Key: The unique identity of your application within the API system.
  • Secret Key: Used to encrypt messages sent from your client to the API.

2. Required Request Parameters

Every API request must include the following components:

  • App Key
  • Secret Key
  • Session Token

3. Login Flow

Initiate the login process by navigating to the login URL with your URL-encoded App Key:

https://api.icicidirect.com/apiuser/login?api_key=Your_AppKey

  1. Upon successful login, retrieve the API_Session value displayed in your browser's address bar.
  2. Pass this API_Session value under the key SessionToken in the CustomerDetails API.
  3. The API will respond with a session_token.
  4. Use this session_token as the SessionToken to authenticate all subsequent API requests.

Setup and Installation

Open your terminal or command prompt.
Type pip install breeze-connect to get the official Python SDK.
Open your Python editor or Jupyter Notebook
Get the token from the redirect url as this https://www.profitaddaweb.com/?apisession=your_session_token then paste that token in the given below code with api key, secret and generating session token then go with order placement and queries you prefer.


Video Tutorial

For a visual walkthrough of the process, refer to the official YouTube tutorial:


from breeze_connect import BreezeConnect
import dbm
db=dbm.open('config','r')
api_key=db['api_key'].decode()
api_secret=db['api_secret'].decode()

breeze=BreezeConnect(api_key=api_key)
breeze.generate_session(api_secret=api_secret,session_token='your_session_token')

print(breeze.get_demat_holdings())

Key Rules and Limits


Cost: Completely free of charge for all ICICI Direct customers.
Rate Limits: Maximum of 100 API calls per minute and 5,000 calls per day.
Requirements: An active ICICI Direct trading account and a registered app session token generated daily.

NSE India API Live Analysis Variations Index Gainers in Python

India VIX in Decision Making Fetching Data Directly from NSE India API


Follow the Instructions from the Video then go for the Code Input:

 
import requests
import pandas as pd

url='https://www.nseindia.com/api/equity-stockIndices?index=INDIA VIX'

headers={
    'User-Agent' : 'Mozilla/5.0'

}

response=requests.get(url,headers=headers)
data=response.json()
print(data)


df=pd.concat([pd.DataFrame(data['data'])[['symbol','lastPrice']]])
print(df)

Most Active Securities by Volume NSE India API Live Analysis


Follow the Instructions from the Video then go for the Code Input:

  
import requests
import pandas as pd  

url='https://www.nseindia.com/api/live-analysis-most-active-securities?index=volume'
headers={
    'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebkit/537.36',
    'Accept-Language' : 'en-US, en; q=0.9'
}

response=requests.get(url,headers=headers)
data=response.json()
    


df=pd.concat([pd.DataFrame(data['data'])[['symbol','lastPrice','totalTradedVolume']] ])
df_sorted=df.sort_values('lastPrice').reset_index(drop=True)
print(df_sorted.to_string(index=False))

Most Active Securities by Value NSE India API Live Analysis


Follow the Instructions from the Video then go for the Code Input:

  
import requests   
import pandas as pd  

url='https://www.nseindia.com/api/live-analysis-most-active-securities?index=value'

headers={
    'User-Agent' : 'Mozilla/5.0'

}

response=requests.get(url,headers=headers)
data=response.json()


df=pd.concat([pd.DataFrame(data['data'])[['symbol','lastPrice','totalTradedValue','lastUpdateTime']]])
df_sorted=df.sort_values('lastPrice').reset_index(drop=True)

print(df_sorted.to_string(index=False))

NSE India API Live Analysis Variations Index Gainers in Python


Follow the Instructions from the Video then go for the Code Input:

  
import json
import pandas as pd  

with open('gain.json','r') as f:
    data=json.load(f)
    
categories=['NIFTY', 'BANKNIFTY','NIFTYNEXT50','SecGtr20','SecLwr20','FOSec','allSec']

df=pd.concat([pd.DataFrame(data[cat]['data'])[['symbol','ltp']] for cat in categories if cat in data])
df_sorted=df.sort_values('ltp').reset_index(drop=True)
print(df_sorted.to_string(index=False))

Read NSE Gainers Data Directly from NSE India API


Follow the Instructions from the Video then go for the Code Input:

  
import requests
import pandas as pd  

url='https://www.nseindia.com/api/live-analysis-variations?index=gainers'
headers={
    'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebkit/537.36',
    'Accept-Language' : 'en-US, en; q=0.9'
}

response=requests.get(url,headers=headers)
data=response.json()
    
categories=['FOSec']

df=pd.concat([pd.DataFrame(data[cat]['data'])[['symbol','ltp']] for cat in categories if cat in data])
df_sorted=df.sort_values('ltp').reset_index(drop=True)
print(df_sorted.to_string(index=False))