Getting Historical Data of Reliance​ in JSON Using Python and Zerodha API

Amit Kumar Ghosh
2 min readSep 25, 2023

--

Now, With the instrument token in hand, we can fetch historical price data for RELIANCE.

# Fetch historical data for RELIANCE
historical_data = kite.historical_data(instrument_token, '2023-01-01', '2023-09-01', interval='minute')

In this section of the code, we utilize the kite.historical_data method to request historical data for RELIANCE.

  • We specify the instrument token.
  • We define the start date as ‘2023-01-01‘.
  • We set the end date to ‘2023-09-01‘.
  • The selected interval is ‘minute‘.

It’s important to note that the historical_data() API accepts both datetime objects and string representations as inputs for specifying the date range. In this case, we’ve used string representations of the dates (‘2023-01-01‘ and ‘2023-09-01‘) to define the date range.

This flexibility allows for convenient date range specification based on your requirements.

So, if we want the data from daily the interval as ‘day‘. This will provide daily historical data for the specified period.

# Fetch historical data for RELIANCE
historical_data = kite.historical_data(instrument_token, '2023-01-01', '2023-09-01', interval='day')

The output is a list of JSONs –

[{'date': datetime.datetime(2023, 1, 2, 0, 0, tzinfo=tzoffset(None, 19800)),
'open': 18982.5,
'high': 19123.5,
'low': 18937.15,
'close': 19074.45,
'volume': 0},
{'date': datetime.datetime(2023, 1, 3, 0, 0, tzinfo=tzoffset(None, 19800)),
'open': 19041.55,
'high': 19219.55,
'low': 19041.55,
'close': 19196.05,
'volume': 0},
{'date': datetime.datetime(2023, 1, 4, 0, 0, tzinfo=tzoffset(None, 19800)),
'open': 19172.6,
'high': 19257.05,
'low': 18966.75,
'close': 19007,
'volume': 0},
...
...
...
...
...]

A Note from Unofficed

Thank you for being a valued member of our community! Before you depart:

👏 Applaud the story and give a follow to the author 👉

📰 Explore additional content on the Unofficed

📚 Join our FREE Masterclass

📈 Unlock potent trading tools

--

--

Amit Kumar Ghosh
Amit Kumar Ghosh

Written by Amit Kumar Ghosh

Aloha, I’m Amit Ghosh, a web entrepreneur and avid blogger. Bitten by entrepreneurial bug, I got kicked out from college and ended up being millionaire!

No responses yet