GetHistoricalData for Sensex options throws invalid from date error

kmuralidaran
DateTime tradingDay = DateTime.Today;
while (tradingDay.DayOfWeek == DayOfWeek.Saturday || tradingDay.DayOfWeek == DayOfWeek.Sunday)
{
tradingDay = tradingDay.AddDays(-1);
}

// Step 5: Set market open/close
var marketOpen = new DateTime(tradingDay.Year, tradingDay.Month, tradingDay.Day, 9, 15, 0, DateTimeKind.Utc);
var marketClose = new DateTime(tradingDay.Year, tradingDay.Month, tradingDay.Day, 15, 30, 0, DateTimeKind.Utc);
var toTime = DateTime.Now > marketClose ? marketClose : DateTime.Now;

var quote = kite.GetQuote(["408065"]);

// Step 6: Fetch historical data
var historicalData = kite.GetHistoricalData(
optionInstrument.InstrumentToken.ToString(),
marketOpen,
marketClose,
Constants.INTERVAL_MINUTE, // interval
false, // continuous for options/futures
false // extended hours
);

KiteConnect.InputException: invalid from date
at KiteConnect.Kite.Request(String Route, String Method, Object Params, Dictionary`2 QueryParams, Boolean json)
at KiteConnect.Kite.Get(String Route, Dictionary`2 Params, Dictionary`2 QueryParams)
at KiteConnect.Kite.GetHistoricalData(String InstrumentToken, DateTime FromDate, DateTime ToDate, String Interval, Boolean Continuous, Boolean OI)
at SensexOptionFetcher.GetNearestSensexOptionData(Decimal strike, String type) in H:\ZerodhaAutomation\SensexOptionsFetcher.cs:line 60
at ZerodhaAutomation.MainForm.btnDownloadHistory_Click(Object sender, EventArgs e) in H:\ZerodhaAutomation\MainForm.cs:line 457
Sign In or Register to comment.