Skip to content

Instantly share code, notes, and snippets.

@ganigithub
Last active October 3, 2022 07:57
Show Gist options
  • Save ganigithub/4b9b87360bc79716c88118661125d7f8 to your computer and use it in GitHub Desktop.
Save ganigithub/4b9b87360bc79716c88118661125d7f8 to your computer and use it in GitHub Desktop.
def instrument_token(data, symbol):
"""
This function will return the token number of the instrument from data
"""
return data[data.tradingsymbol == symbol].instrument_token.values[0]
def historical_data(symbol, from_date, to_date, interval):
"""
This function will return historical data of the instrument for specific period of days for specific interval
"""
df = pd.DataFrame()
int_token = instrument_token(nse_data, symbol) #the function we defined above which will return token no. of instrument
to_date = pd.Timestamp(to_date)
from_date = pd.Timestamp(from_date)
while True:
if from_date >= (to_date - dt.timedelta(60)): #if from_date is within the 60 days limit
df = df.append(pd.DataFrame(kite.historical_data(int_token, from_date, to_date, interval)))
break
else: #if from_date has more than 60 days limit
to_date_new = from_date + dt.timedelta(60)
df = df.append(pd.DataFrame(kite.historical_data(int_token, from_date, to_date_new, interval)))
#to_date = from_date.date() + dt.timedelta(60)
from_date = to_date_new
return df
@26dhruv
Copy link

26dhruv commented Jul 4, 2022

what's instrument token in this?
[SOLVED]

@ganigithub
Copy link
Author

ganigithub commented Jul 4, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment