Fetch historical daily candles
from datetime import date
candles = kite.historical_data(
instrument_token=408065, # INFY
from_date=date(2024, 1, 1),
to_date=date(2024, 12, 31),
interval="day",
)
print(candles[0])
{
"date": datetime(2024, 1, 1, 0, 0, tzinfo=...),
"open": 1465.0,
"high": 1482.0,
"low": 1460.5,
"close": 1470.2,
"volume": 3821450,
}
Load straight into a DataFrame
import pandas as pd
def fetch_daily(kite, instrument_token: int, from_date, to_date) -> pd.DataFrame:
candles = kite.historical_data(instrument_token, from_date, to_date, "day")
df = pd.DataFrame(candles)
df.set_index("date", inplace=True)
return df
df = fetch_daily(kite, 408065, date(2024, 1, 1), date(2024, 12, 31))
print(df.tail())
Requires a subscription add-on
Historical data is a separate paid subscription on top of Kite Connect (as of writing, an additional monthly fee) — a base Kite Connect app without it gets a PermissionException on this call. Check your subscription before assuming this works.
Free alternative for learning/backtesting
If you're only backtesting (not needing live-accurate recent data), NSE's own bhavcopy files (free daily EOD CSV downloads) or yfinance / nsepy-style libraries can source historical daily data without a paid subscription. Use the broker's historical API for the strategies you intend to actually run live, since it guarantees consistency with the same data source your live signals will use.