I'm getting error while fetching historical data.
-
[E 241216 10:28:43 smartConnect:243]
-
@Ekraj in the screenshot you have provided, the request message for API does not have the symboltoken.
-
@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 TOTPkey_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_datahdfc_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
-
@admin I tried but still not working i'm getting same error.
[E 241220 10:16:15 smartConnect:243] Error occurred while making a POST request to https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData. Error: Something Went Wrong, Please Try After Sometime. URL: https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData, Headers: {'Content-type': 'application/json', 'X-ClientLocalIP': '127.0.0.1', 'X-ClientPublicIP': '106.193.147.98', 'X-MACAddress': 'a4:42:3b:fe:86:9c', 'Accept': 'application/json', 'X-PrivateKey': 'xv5pzSlS', 'X-UserType': 'USER', 'X-SourceID': 'WEB'}, Request: {'exchange': 'NSE', 'interval': 'ONE_HOUR', 'fromdate': '2024-08-22 00:00', 'todate': '2024-12-20 00:00'}, Response: {'message': 'Something Went Wrong, Please Try After Sometime', 'errorcode': 'AB1004', 'status': False, 'data': None}
-
Please verify by hitting the API through postman, it is working fine.
-
for me too.
It was fine on Friday.
I am trying to 5 Minute of historical data. but an empty response.
Data available up to 13-Dec-2024 only. -
Can you give more details about the same? eg. what are you trying to fetch via the API, and the snippet of the API.