nse-business-time
Version:
Calculate Business Time for NSE,BSE,MCX and NFO
51 lines (41 loc) • 2 kB
JavaScript
const admin = require('firebase-admin');
const momentz = require('moment-timezone');
const _cnst = require('./constants');
async function getHolidayList(nodePath="_services/_holidays_list"){
console.log('download data from ' + nodePath);
let snapshot = await admin.database().ref(nodePath).once('value');
if(snapshot.exists()){
let _o_tmp = snapshot.val();
_cnst.O_HLDY_LIST.NSE = _o_tmp.NSE;
_cnst.O_HLDY_LIST.BSE = _o_tmp.NSE;
_cnst.O_HLDY_LIST.NFO = _o_tmp.NSE;
_cnst.O_HLDY_LIST.MCX_MORNING = _o_tmp.MCX_MORNING;
_cnst.O_HLDY_LIST.MCX_EVENING = _o_tmp.MCX_EVENING;
_cnst.O_MKT_START.NSE = _o_tmp._config.start_time.NSE;
_cnst.O_MKT_START.BSE = _o_tmp._config.start_time.BSE;
_cnst.O_MKT_START.NFO = _o_tmp._config.start_time.NFO;
_cnst.O_MKT_START.MCX_MORNING = _o_tmp._config.start_time.MCX_MORNING;
_cnst.O_MKT_START.MCX_EVENING = _o_tmp._config.start_time.MCX_EVENING;
_cnst.O_MKT_END.NSE = _o_tmp._config.end_time.NSE;
_cnst.O_MKT_END.BSE = _o_tmp._config.end_time.BSE;
_cnst.O_MKT_END.NFO = _o_tmp._config.end_time.NFO;
_cnst.O_MKT_END.MCX_MORNING = _o_tmp._config.end_time.MCX_MORNING;
_cnst.O_MKT_END.MCX_EVENING = _o_tmp._config.end_time.MCX_EVENING;
}else{
console.error("Holiday list is not available at ", nodePath);
}
return _cnst.O_MKT_END;
}
function isHoliday(exchange, currentTime){
let day = momentz(currentTime).tz(_cnst.TIME_ZONE).format(_cnst.DATE_FORMAT);
let weekday = momentz(currentTime).tz(_cnst.TIME_ZONE).isoWeekday();
if(_cnst.O_HLDY_LIST[exchange].indexOf(day) > -1){
return true;
}else if([6,7].indexOf(weekday) > -1){
return true;
}else{
return false;
}
}
exports.getHolidayList = getHolidayList;
exports.isHoliday = isHoliday;