import datetime
import urllib.request, urllib.parse
import json
user_id = "ABCDEF"
auth_tok = "enctoken NPPEJtGFrDlPfvAP8RhT+Hd1OiSAiW4hcMfUNGHScS1/44+u/w3UdhRRzpMymSAoVCu1b8wVOcqBYIKpJaPvcNGXUDr+HQ=="
#User-agent depends from which browser we login
head = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
'authorization': auth_tok }
def getCandles(inst_id, tf="", frm="", to="", continuous=0):
today = datetime.datetime.now().strftime("%Y-%m-%d")
if len(tf) == 0:
tf = "minute"
if len(frm) == 0:
frm = today
if len(to) == 0:
to = today
get_url = 'https://kite.zerodha.com/oms/instruments/historical/' + str(inst_id) + '/' + tf + '?user_id=' + user_id + '&oi=1&from=' + frm + '&to=' + to
req = urllib.request.Request(get_url, headers=head)
response = urllib.request.urlopen(req)
# Convert stream to dict
string = response.read().decode('utf-8
April 2021