Historic Api failed: 6 columns passed, passed data had 7 columns
# Historic Data and Indicator
def historicDataAPI( Symbol,noOfDays = 5,interval = TF):
logging.info("historicDataAPI OPEN")
try:
to_date = datetime.now()
from_date = to_date - timedelta(days=noOfDays)
from_date_format = from_date.strftime("%Y-%m-%d")
to_date_format = to_date.strftime("%Y-%m-%d")
data = {
"symbol":Symbol,#18April2024 22500ce
"resolution":interval,
"date_format":"1",
"range_from":from_date_format,
"range_to":to_date_format,
"cont_flag":"1"
}
response = fyers.history(data=data)
print(response)
df = pd.DataFrame(response['candles'],columns=['date','O','H','L','C','V'])
#print(df['date'])
#print(df)
# Assuming 'timestamp' is the Unix timestamp value (1712893500)
df['date'] = df['date'].apply( lambda x: datetime.utcfromtimestamp(x))
# Define the timezone (GMT+5:30 for Indian Standard Time)
timezone = pytz.timezone('Asia/Kolkata')
# Convert UTC datetime to the specific timezone
df['date'] = df['date'].apply(lambda x: x.replace(tzinfo=pytz.utc).astimezone(timezone))
# Format the 'mod_date' column as a string in the desired format
df['date'] = df['date'].apply(lambda x: x.strftime('%Y-%m-%d %H:%M:%S'))
#print(df[:1])
df.set_index('date', inplace=True)
df['symbol'] = Symbol
logging.info("historicDataAPI CLOSE w/o error")
return calculate_indicator(df)
#calculate_indicator(df)
except Exception as e:
print("Historic Api failed: {}".format(e))
telegram("Historic Api failed: {}".format(e))
logging.error("historicDataAPI CLOSE with ERRORS")