How to fetch Historical Data for more than one month ?

genesis
when i run this :

import pandas as pd
data1=kite.historical_data(instrument_token='1270529',from_date='2015-02-02',to_date='2015-02-02',interval='minute')
data1=pd.DataFrame(data1)
data1.to_csv('icicibank.csv')

it works fine.

but when i run this :

import pandas as pd
data1=kite.historical_data(instrument_token='1270529',from_date='2015-02-02',to_date='2015-03-04',interval='minute')
data1=pd.DataFrame(data1)
data1.to_csv('icicibank.csv')

it says you cannot fetch data for 30 days , is there a workaround to this ?

for downloading data for a stock in one go from when it is available say >> 2015-02-02 till now ?
Tagged:
  • sujith
    You can make multiple calls if you have to fetch historical data for more than 30 days.
  • rjv17
    rjv17 edited December 2018
    @genesis: Piece of code from my setup for your reference:
    while days > 0:
    df_temp = pd.DataFrame()
    from_date = datetime.now() - timedelta(days=days)
    to_date = from_date + timedelta(days=30)
    download_try = 0
    while df_temp.empty == True and download_try <= 10:
    try:
    #time.sleep(0.5)
    download_try = download_try+1
    records = self.kite.historical_data(self.instrument_token\
    ,from_date,to_date,self.interval,continuous=False)
    df_temp = pd.DataFrame(records, columns=[ 'volume', 'high', 'low', 'date','close','open' ])
    self.df = self.df.append(df_temp,sort=False,ignore_index=True)
    except:
    print("%s GHD Try %d"%(self.symbol,download_try))
    pass

    days -= 30
Sign In or Register to comment.