Historical data

ayush
Hi, I cannot get minute level historical data of more than 2 years earlier of nifty50 stocks. Is anyone else facing the same issue? I need to test a strategy on it.
  • Imran
    Imran edited August 2018
    hii @ayush
    1 minute ohlc data can be retrieved for only last 30 days.
    for 15,30 minutes it can be for last 180 days.
  • rakeshr
    @ayush @Imran
    We don't provide accumulated 1-minute level data in single go for more than 30 days. Alternatively, you can run loop at your end and accumulate month wise 1 minute data and keep on adding it.
    Something like this(for python client) for 2 years data:
    #Assign month and date from which you want to start
    calendar_month=datetime.datetime(2016,7, 12)
    #loop for 24 months
    for i in range(24):
    #keep increasing month to next month in every loop
    calendar_month=calendar_month+datetime.timedelta(weeks=4)
    #fetch Historical data
    historical_data=kite.historical_data(instrument_token=408065,from_date=calendar_month, to_date=calendar_month+datetime.timedelta(weeks=4), interval='minute', continuous=False)
    #Store above data in your database or which ever datastructure you want.
    #historical_data['date']
    #historical_data['high']
    #historical_data['low']
    #historical_data['close']
    #historical_data['volume']
  • ayush
    Yeh like I am iterating month on month for the data. But cannot retrieve it for the time period before 2016.
  • rakeshr
    @ayush
    Equity Intraday minute data is available from Feb 2015.
  • ayush
    Will check on that and let you know
  • Imran
    Imran edited August 2018
    @ayush
    import datetime
    import time
    from kiteconnect import KiteConnect


    tdelta0=datetime.timedelta(days=30)
    tdelta=datetime.timedelta(days=29)

    ak='xxxxxxxxxxxxxxxxxx'
    asecret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

    kite = KiteConnect(api_key=ak)
    request_tkn = input("[*] Enter Your Request Token Here : ");
    data = kite.generate_session(request_tkn, api_secret=asecret)
    kite.set_access_token(data["access_token"])

    interval = "day"


    savedata={}
    def get_historical_data(instrument_token):
    return kite.historical(instrument_token, from_date, to_date, interval)

    trd_portfolio={5633: 'ACC',6401: 'ADANIENT',3861249: 'ADANIPORTS',2079745: 'AJANTPHARM'}

    for token in trd_portfolio:
    f= open(str(trd_portfolio[token])+".txt","w+")
    from_date=datetime.date(2015,2,1)
    to_date=from_date+tdelta
    for x in range(1,45):
    print(x)
    print("\n",from_date)
    print(to_date)
    records = kite.historical_data(token, from_date, to_date, interval)
    f.write(str(records))
    for x in records:
    print(x)
    from_date=from_date+tdelta0
    to_date=from_date+tdelta
    print(token)


    the code above saves historical data and generates a separate file for each ...
Sign In or Register to comment.