Check Market Holiday - Market Holiday or Muhurat - solution

pranksterguru
pranksterguru edited January 2018 in Java client
its been always a pain to know if the current day or any day is trading day or not.

I have written a simple java method that will check if any given date is working day or muhurat. i have taken the market holidays from nse website and stored it in DB . java method will loop through the table and check for market day

below is the Java method.
	public static boolean checkWorkingDay(Date inputDate)
{

boolean workingDay = true;
Date returnDt = inputDate;
returnDt.setHours(0);
returnDt.setMinutes(0);;
returnDt.setSeconds(0);

try {

List<Tradingcalendar> tradingCalendarlistHoliday = TradingCalendar.GetClassInstance().
getTradingCalendarList().stream().
filter(p -> p.getHolidaytype().equals("holiday") &&
p.getProduct().equals("equities") ).collect(Collectors.toList());

for (int i = 0; i < tradingCalendarlistHoliday.size(); i++) {
Date javaDate = new Date() ;
javaDate.setTime(tradingCalendarlistHoliday.get(i).getHolidaydate().getTime());
if (javaDate.toString().equals(returnDt.toString())) {
workingDay=false;
}
}


if (returnDt.getDay()==0 || returnDt.getDay()==6) {
List<Tradingcalendar> tradingCalendarlistMuharam = null;

tradingCalendarlistMuharam = TradingCalendar.GetClassInstance().
getTradingCalendarList().stream().
filter(p -> p.getHolidaytype().equals("muhurat") &&
p.getProduct().equals("equities") ).collect(Collectors.toList());


boolean chkMuharam=false;
for (int i = 0; i < tradingCalendarlistMuharam.size(); i++) {
Date javaDate = new Date() ;
javaDate.setTime(tradingCalendarlistMuharam.get(i).getHolidaydate().getTime());
if (javaDate.toString().equals(returnDt.toString())) {
chkMuharam=true;
}
}

if (!chkMuharam) {
workingDay=false;
}

}


} catch (Exception e) {
misc.PrintConsole(e.getMessage());
}

return workingDay;
}


below is the table structure

Tagged:
Sign In or Register to comment.