Historical Data for Futures

Hsadikot edited June 2021 in Python client

For the given Kite API Call for historical data using python:

def historical_data(self, instrument_token, from_date, to_date, interval, continuous=False, oi=False)

I have to provide instrument_token. My doubt is where do I find those?

I needed Historical Data for the below Instrument:


I have tried to use the CSV Dump.

The code is as follows:
from kiteconnect import KiteConnect
import os
import datetime as dt
import pandas as pd

cwd = os.chdir("C:/Users/hozef/OneDrive/Desktop/New Logic")

#generate trading session
access_token = open("access_token.txt",'r').read()
key_secret = open("api_key.txt",'r').read().split()
kite = KiteConnect(api_key=key_secret[0])

#get dump of all NSE instruments
instrument_dump = kite.instruments("NSE")
instrument_df = pd.DataFrame(instrument_dump)
instrument_df.to_csv("C:/Users/hozef/OneDrive/Desktop/New Logic/NSE_Instruments_31122019.csv",index=False)

The issue being there is no instrument matching the one I Want in the csv Dump

  • rakeshr
    I have to provide instrument_token. My doubt is where do I find those?
    You can find instrument_token and other detail for the required contract from the full instrument list.
  • sujith
    Kite web and app uses formatted names to help users understand. You need to search with actual tradingsymbol in the instrument dump.
  • sujith
    In this case, BANKNIFTY21JULFUT is the actual tradingsymbol
  • SafeInvest
    If you want to fetch future and option contract than you have to write "NFO" in instrument dump instead of NSE

    instrument_dump = kite.instruments("NFO")
    instrument_df = pd.DataFrame(instrument_dump)

Sign In or Register to comment.