~\Desktop\Zerodha\v2\misc_func.py in candle_close(scrip_token, sl_time) 25 } 26 x = requests.get(url, headers=headers) ---> 27 for i in range(len(x.json()['data']['candles'])): 28 if x.json()['data']['candles'][i][0][11:16] == sl_time: 29 candle_minute_close = x.json()['data']['candles'][i][4]
It is an API error only, sent this to zerodha, and got "We would like to inform you that the above error is a permission issue for historical API, request you to write to forum for code related queries."
x = requests.get(url, headers=headers) candle_minute_close = x.json()['data']['candles'][i][4] TypeError: 'NoneType' object is not subscriptable
You seem to be setting wrong requests for historical data. Can you let us know more about url and headers for requests? Also, you can make use of any of our official client libs, which have easy API integration.
Even subscribed for historical API
in
----> 1 re_ce_price = candle_close(re_ce_token, entry_time)
2 re_pe_price = candle_close(re_pe_token, entry_time)
3 re_ce_sl_price = int(re_ce_price * (1+(sl/100))) + 1
4 re_pe_sl_price = int(re_pe_price * (1+(sl/100))) + 1
5
~\Desktop\Zerodha\v2\misc_func.py in candle_close(scrip_token, sl_time)
25 }
26 x = requests.get(url, headers=headers)
---> 27 for i in range(len(x.json()['data']['candles'])):
28 if x.json()['data']['candles'][i][0][11:16] == sl_time:
29 candle_minute_close = x.json()['data']['candles'][i][4]
TypeError: 'NoneType' object is not subscriptable
You can run in debug mode and paste the logs here.
PS: Make sure to remove app and client specific tokens.
"We would like to inform you that the above error is a permission issue for historical API, request you to write to forum for code related queries."
Also, you can make use of any of our official client libs, which have easy API integration.
global cookies, today
url = 'https://kite.zerodha.com/oms/instruments/historical/'+ str(scrip_token) +'/minute?user_id=' + str(user_id) + '&oi=1&from=' + today + '&to=' + today + '&ciqrandom=1597949155770'
headers = {
'authorization': cookies
}
x = requests.get(url, headers=headers)
for i in range(len(x.json()['data']['candles'])):
if x.json()['data']['candles'][i][0][11:16] == sl_time:
candle_minute_close = x.json()['data']['candles'][i][4]
return candle_minute_close
the above function is the one giving error