Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get historical data of indices? #78

Closed
hemangjoshi37a opened this issue May 11, 2020 · 3 comments
Closed

How to get historical data of indices? #78

hemangjoshi37a opened this issue May 11, 2020 · 3 comments
Assignees
Labels

Comments

@hemangjoshi37a
Copy link

Dear sir,

There is absolute no documentation on how to read indices like NIFTY from historical_data() function or by any other way.

Please help me.
Thank you in advance sir.

@rahulmr
Copy link

rahulmr commented Dec 29, 2020

Not sure about the documentation but I think below code might help you.

...
...
import pandas as pd
from datetime import datetime as dt
from datetime import timedelta as td
...
...
... 
# do all kite object creation steps
sbin_token = kite.ltp("NSE:SBIN")['NSE:SBIN']['instrument_token']
df = pd.DataFrame(kite.historical_data(
    sbin_token, dt.today() - td(days=7), dt.today(), '15minute'))
print(df)

nf_token = kite.ltp("NSE:NIFTY 50")['NSE:NIFTY 50']['instrument_token']
df = pd.DataFrame(kite.historical_data(
    nf_token, dt.today() - td(days=7), dt.today(), '15minute'))
print(df)
bnf_token = kite.ltp("NSE:NIFTY BANK")['NSE:NIFTY BANK']['instrument_token']
df = pd.DataFrame(kite.historical_data(
    bnf_token, dt.today() - td(days=7), dt.today(), '15minute'))
print(df)

@vividvilla vividvilla self-assigned this Feb 17, 2021
@vividvilla vividvilla added the bug label Feb 17, 2021
@ranjanrak
Copy link
Member

ranjanrak commented Aug 19, 2022

The response structure section of all APIs explains the fields.

@hemangjoshi37a
Copy link
Author

Not sure about the documentation but I think below code might help you.

...
...
import pandas as pd
from datetime import datetime as dt
from datetime import timedelta as td
...
...
... 
# do all kite object creation steps
sbin_token = kite.ltp("NSE:SBIN")['NSE:SBIN']['instrument_token']
df = pd.DataFrame(kite.historical_data(
    sbin_token, dt.today() - td(days=7), dt.today(), '15minute'))
print(df)

nf_token = kite.ltp("NSE:NIFTY 50")['NSE:NIFTY 50']['instrument_token']
df = pd.DataFrame(kite.historical_data(
    nf_token, dt.today() - td(days=7), dt.today(), '15minute'))
print(df)
bnf_token = kite.ltp("NSE:NIFTY BANK")['NSE:NIFTY BANK']['instrument_token']
df = pd.DataFrame(kite.historical_data(
    bnf_token, dt.today() - td(days=7), dt.today(), '15minute'))
print(df)

Thanks. Your solution works.
https://hjlabs.in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants