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)