Not getting historical data please help I AM USING GOOGLE COLAB

import requests
import pandas as pd

Load the CSV file and clean column names

file_path = ‘/content/drive/My Drive/INVESTMENT/FOR ALGO TRADING/EQUITY_L.csv’
df = pd.read_csv(file_path)
df.columns = df.columns.str.strip()

Function to fetch historical data

def fetch_historical_data(INSTRUMENT_KEY, start_date, end_date, interval=‘30minute’):
url = f’https://api.upstox.com/v2/historical-candle/NSE_EQ|{INSTRUMENT_KEY}/{interval}/{start_date}/{end_date}
headers = {
‘Accept’: ‘application/json’,
‘Authorization’: ‘Bearer <access_token>’
}

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

if response.status_code == 200:
    return response.json()
else:
    print(f"Failed to fetch data for {INSTRUMENT_KEY}: {response.status_code}, {response.json()}")
    return None

Example usage

start_date = ‘2023-11-12’
end_date = ‘2023-11-01’

Fetch data for each stock in the DataFrame

for index, row in df.iterrows():
INSTRUMENT_KEY = row[‘INSTRUMENT KEY’]
print(f"Fetching data for {INSTRUMENT_KEY}")
data = fetch_historical_data(INSTRUMENT_KEY, start_date, end_date)

if data and data.get('data', {}).get('candles'):
    print(f"Data for {INSTRUMENT_KEY}: {data}")
else:
    print(f"No data for {INSTRUMENT_KEY}: {data}")

The fetch_historical_data function will return the response body in the specified format if the request is successful and there is data.

BUT I GOT OUTPUT LIKE THIS NO CANDLE DATA SHOWN

Fetching data for INE144J01027
No data for INE144J01027: {‘status’: ‘success’, ‘data’: {‘candles’: }}
Fetching data for INE253B01015
No data for INE253B01015: {‘status’: ‘success’, ‘data’: {‘candles’: }}
Fetching data for INE466L01038
No data for INE466L01038: {‘status’: ‘success’, ‘data’: {‘candles’: }}
Fetching data for INE748C01038
No data for INE748C01038: {‘status’: ‘success’, ‘data’: {‘candles’: }}
Fetching data for INE470A01017
No data for INE470A01017: {‘status’: ‘success’, ‘data’: {‘candles’: }}
Fetching data for INE105C01023
No data for INE105C01023: {‘status’: ‘success’, ‘data’: {‘candles’: }}

@SHIVAM_JI Please refer the correct API Example code for historical data.