I’m encountering an intermittent error when calling the FYERS History API. This problem seems to occur randomly, sometimes appearing and sometimes not. It started happening on March 30th, and prior to that, the same code was functioning correctly.
could you please advise if there are any ongoing issues
@shyam.cqj9mxeg you can use below code to keep a track of api hits. It’ll create a new file for a day so that if your code fails, your counts will be loaded and resume from there onwards.
hope this’ll help.
def load_number_from_json():
file_path = f"call_counts_{get_today_yyyy_mm_dd()}.json"
# Check if the file already exists
if not os.path.exists(file_path):
data = {'number': apiCntr}
# If the file doesn't exist, create an empty file
with open(file_path, 'w') as file:
json.dump(data, file)
print(f"Empty file '{file_path}' created successfully.")
return apiCntr
else:
with open(file_path, "r") as file:
data = json.load(file)
print(f"File '{file_path}' already exists. data = {data}")
return data.get('number', 0)
def save_number_to_json():
file_path = f"call_counts_{get_today_yyyy_mm_dd()}.json"
data = {'number': apiCntr}
with open(file_path, "w") as file:
json.dump(data, file)