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

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},
  ...
  ...
  ...
  ...
  ...]
				
			
Post a comment

Leave a Comment

Your email address will not be published. Required fields are marked *

×Close