Ant-A3 API - The Official Python SDK for Smart Trading

Ant-A3 API - The Official Python SDK for Smart Trading: Registration & Login Guide

Get Indian Stock Market Historical Data from ANT-A3 API Utilizing Python:


HISTORICAL DATA API — NOTES
* Base URL, endpoint, and payload JSON keys are case-sensitive. Follow the exact format specified in the documentation.
1. Only Day and Minute resolution data is available. Other resolutions (5-min, weekly, etc.) must be derived from these based on your own requirements.
2. Availability on weekdays (Mon–Fri): 5:30 PM to 8:00 AM (next day) only. Not available during market hours.
3. Availability on weekends and holidays: Full day.
Segment-wise Data Availability
--------------------------------
Segment | Data Available
--------------------------------
NSE | 2 years of historical data
NFO | Current expiry data only
CDS | Current expiry data only
MCX | Current expiry data only
BSE | Coming soon
BCD | Coming soon
BFO | Coming soon
--------------------------------

For Instructions Watch The Video Here:


  
from TradeMaster.TradeSync import *
import dbm
from datetime import datetime, timedelta
db=dbm.open('alicedb','r')
username=db['username'].decode()
api_secret=db['api_secret'].decode()
authCode='authCode'
trade=TradeHub(user_id=username,auth_code=authCode,secret_key=api_secret)
trade.get_session_id()
data=trade.get_HistoricalData(instrument=trade.get_instrument(exchange=Exchange.NSE,symbol='TATASTEEL'),
                         resolution='1', # '1' as minute and Expand Further as per interval chart 3, 5.. and for day it goes with 'D'
                         from_datetime=datetime.now() - timedelta(days=7),
                         to_datetime=datetime.now(),
                         indices=False)
print(data)

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.

For Instructions Watch The Video Here:


  
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='authCode',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)

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.