@admin Here is snip of my code "from SmartApi import SmartConnect
import os
import urllib
import json
import pandas as pd
import datetime as dt
from pyotp import TOTP
key_path = r"C:\Users\Ekraj\OneDrive\SmartApi"
os.chdir(key_path)
key_secret = open("key.txt","r").read().split()
obj=SmartConnect(api_key=key_secret[0])
data = obj.generateSession(key_secret[2],key_secret[3],TOTP(key_secret[4]).now())
instrument_url = "https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json"
response = urllib.request.urlopen(instrument_url)
instrument_list = json.loads(response.read())
def token_lookup(ticker, instrument_list, exchange="NSE"):
for instrument in instrument_list:
if instrument["name"] == ticker and instrument["exch_seg"] == exchange and instrument["symbol"].split('-')[-1] == "EQ":
return instrument["token"]
def symbol_lookup(token, instrument_list, exchange="NSE"):
for instrument in instrument_list:
if instrument["token"] == token and instrument["exch_seg"] == exchange and instrument["symbol"].split('-')[-1] == "EQ":
return instrument["name"]
def hist_data(ticker,duration,interval,instrument_list,exchange="NSE"):
params = {
"exchange": exchange,
"symboltoken": token_lookup(ticker,instrument_list),
"interval": interval,
"fromdate": (dt.date.today() - dt.timedelta(duration)).strftime('%Y-%m-%d %H:%M'),
"todate": dt.date.today().strftime('%Y-%m-%d %H:%M')
}
hist_data = obj.getCandleData(params)
df_data = pd.DataFrame(hist_data["data"],
columns = ["date","open","high","low","close","volume"])
df_data.set_index("date",inplace=True)
df_data.index = pd.to_datetime(df_data.index)
df_data.index = df_data.index.tz_localize(None)
return df_data
hdfc_data = hist_data("HDFC", 120, "ONE_HOUR", instrument_list)
Error
I need an solution plz tell if there any bug on my code or is there any issue with API