Ant-A3 API - The Official Python SDK for Smart Trading: Registration & Login Guide
Call NSE Option Chain Data in a DataFrame:
POST trade.get_Underlying(exchange=Exchange.NSE_FO) Fetches the list of available underlyings (indices or symbols) for which Option Chain data can be retrieved.
POST trade.get_Underlying_expiry(exchange=Exchange.NSE_FO, underlying="TATASTEEL") Retrieves the list of available expiry dates for a given underlying symbol.
POST trade.get_Option_chain(exchange=Exchange.NSE_FO,underlying='TATASTEEL',interval='5',expiry='25AUG26') Fetches the complete Option Chain data for a specific underlying and expiry.
from TradeMaster.TradeSync import *
import pandas as pd
import dbm
db=dbm.open('alicedb','r')
username=db['username'].decode()
api_secret=db['api_secret'].decode()
trade=TradeHub(user_id=username,auth_code='IQYQKF9VEDQKOGOTGAJ4',secret_key=api_secret)
trade.get_session_id()
UNDERLYING = "TATASTEEL"
expiry = trade.get_Underlying_expiry(exchange=Exchange.NSE_FO, underlying=UNDERLYING)['result'][0]['underlying_expiry'][0]
data = trade.get_Option_chain(exchange=Exchange.NSE_FO, underlying=UNDERLYING, interval='2', expiry=expiry)['result'][0]['data']
rows = [{'strike': r['strikeprice'], **{f"CE_{k}": v for k, v in r['CE'].items()}, **{f"PE_{k}": v for k, v in r['PE'].items()}} for r in data]
df = pd.DataFrame(data)
print(df)
df.to_csv(f"{UNDERLYING}_option_chain.csv", index=False)
Upon successful login, retrieve the API_Session value displayed in your browser's address bar.
Pass this API_Session value under the key SessionToken in the CustomerDetails API.
The API will respond with a session_token.
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:
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.