1 min stock data not fetching

Hi Team,

I’m trying to fetch 1min data for stocks but getting empty dataframe

Empty DataFrame
Columns: [time, open, high, low, close, volume]
Index:

Here is my code:
import os

import subprocess

import pandas as pd

from fyers_api import fyersModel

Read access token from file

with open(“accesstoken.txt”, ‘r’) as accesstoken:

access_token = [accesstoken.read](http://accesstoken.read)().strip()

client_id = ‘XXXXX’

fyers = fyersModel.FyersModel(client_id=client_id, token=access_token, log_path=os.getcwd())

Define the date range

start_date = pd.Timestamp(‘2018-01-01’)

end_date = pd.Timestamp(‘2023-07-09’)

#Read symbols from file

with open(r’symbols2.txt’) as file:

symbols = [file.read](http://file.read)().splitlines()

for symbol in symbols:

# Fetch data from Fyers API

data = {

    "symbol": symbol,

    "resolution": "1m",

    "date_format": "1",

    "cont_flag": "1"

}

df = pd.DataFrame(columns=['symbol', 'date', 'open', 'high', 'low', 'close', 'volume'])

current_date = start_date

while current_date <= end_date:

    range_from = current_date.strftime('%Y-%m-%d')

    range_to = (current_date + pd.DateOffset(days=60)).strftime('%Y-%m-%d')

    data['range_from'] = range_from

    data['range_to'] = range_to

    sdata = fyers.history(data)

    #print(sdata)

    if sdata['s'] == 'ok' and len(sdata['candles']) <= 0:

       # Define the command to execute

        command = ['python', 'C:\\Users\\user-PC\\Documents\\NSE_BSE_DATA\\login_api_generate_accesstoken.py']

        # Execute the command

        process = subprocess.Popen(command)

        # Wait for the command to finish

        process.wait()

            

    if sdata['s'] == 'ok' and len(sdata['candles']) > 0:

        sdata = pd.DataFrame(sdata['candles'], columns=['date', 'open', 'high', 'low', 'close', 'volume'])

        sdata['symbol'] = symbol

        df = pd.concat([df, sdata], ignore_index=True)

    

    current_date += pd.DateOffset(days=60)

# Convert 'date' column to datetime in UTC

df['date'] = [pd.to](http://pd.to)_datetime(df['date'], unit='s').[dt.tz](http://dt.tz)_localize('UTC')

# Convert 'date' column from UTC to IST and remove timezone information

df['date'] = df['date'].[dt.tz](http://dt.tz)_convert('Asia/Kolkata').[dt.tz](http://dt.tz)_localize(None)

# Split 'date' column into separate 'date' and 'time' columns

df['time'] = df['date'].dt.strftime('%H:%M:%S')

# Reorder columns

df = df[['symbol', 'date', 'time', 'open', 'high', 'low', 'close', 'volume']]

# Set 'symbol' and 'date' columns as the index

df.set_index(['symbol', 'date'], inplace=True)

# Save data to CSV

filename = symbol.replace(':', '_').replace('NSE_', '')  # Replace ':' with '_' and remove 'NSE' from the symbol for the filename

filepath = r"C:\Users\user-PC\Documents\NSE_BSE_DATA\NSE_BSE_FYERS_DATA\1_min_stock_data"

os.makedirs(filepath, exist_ok=True)  # Create the directory if it doesn't exist

[df.to](http://df.to)_csv(os.path.join(filepath, f'{filename}.csv'))



# Print the modified DataFrame

print(df.head(5))

Though from the above code I’m able to fetch 1Day data but now I want 1min data which I’m not able to fetch.

Thanks and Regards

Avinash Baldi

They have a limitation on how much intraday data you can get which I’m not aware of. Try a shorter time frame like 10-20 days and you will get the output.

Try start_date = pd.Timestamp(‘2023-07-01’)

Hi @avi.3mgcrec3 ,

You are sending incorrect resolution. To specify a 1-minute candle, you only need to send the value “1” as the resolution. I recommend referring to the documentation for the proper format and consider including print statements in your code to help identify any issues.

Great Thanks

@ZppA1qLXjC & @vishnu_bharath

@ZppA1qLXjC I request you to look into a question of mine and a lot more folks in the community.

https://community.fyers.inhttps://fyers.in/community/t/symbol-for-finnifty-and-midcpnifty-to-stream-data-on-websocket/19443

Hi @vishnu_bharath
We are actively looking into this issue. Will update once its resolved.

hi, i have tried to fetch with 1 min, output is displaying empty but with the 5 min, i am able to get historitcal data. have a look into it.

Code Sample:

public void GetStockHistory(FyersClass fyersClass) {

StockHistoryModel model = new StockHistoryModel();

model.Symbol = “NSE:SBIN-EQ”;

model.Resolution = “1”;

model.DateFormat = “1”;

model.RangeFrom = “2026-01-02”;

model.RangeTo = “2026-01-02”;

model.ContFlag = 1;

Tuple<JSONObject, JSONObject> stockTuple = fyersClass.GetStockHistory(model);

if (stockTuple.Item2() == null) {

System.out.println("Stock History: " + stockTuple.Item1());

} else {

System.out.println("Stock History Error: " + stockTuple.Item2());

}

}

@107886270880114943746 refer the below link for what I have built, You can do a lot more.

https://www.linkedin.com/feed/update/urn:li:activity:7381001938391412736/

Also, I’m sharing the link below to download the Windows executable which runs locally in your browser and doesn’t rely on any cloud setup:

https://drive.google.com/file/d/1RkDLt7SxrqMQiSRABz17PpNsRk_QzESM/view?usp=sharing

It is built on Fyers API. There’s a detailed user manual and quick start guide included.