getPercentage implemented
This commit is contained in:
1 parent
78572f5cc0
commit
527bc18005
6 files changed
+27
-11
No files matched your search
@@ -1076,10 +1076,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function processHeartBeat(processingDate) {
|
||||
function processHeartBeat(processingDate, percentage) {
|
||||
let event = {
|
||||
seconds: (new Date()).getSeconds(),
|
||||
processingDate: processingDate
|
||||
processingDate: processingDate,
|
||||
percentage: percentage
|
||||
}
|
||||
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event)
|
||||
}
|
||||
|
||||
+7
-4
@@ -307,6 +307,8 @@
|
||||
let botNeverRan = true;
|
||||
|
||||
bot.multiPeriodDailyProcessDatetime = new Date(contextVariables.lastFile.valueOf() - ONE_DAY_IN_MILISECONDS); // Go back one day to start well when we advance time at the begining of the loop.
|
||||
let fromDate = new Date(bot.multiPeriodDailyProcessDatetime.valueOf())
|
||||
let lastDate = new Date()
|
||||
|
||||
advanceTime();
|
||||
|
||||
@@ -334,6 +336,11 @@
|
||||
|
||||
}
|
||||
|
||||
/* Telling the world we are alive and doing well */
|
||||
let currentDateString = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2);
|
||||
let currentDate = new Date(bot.multiPeriodDailyProcessDatetime)
|
||||
bot.processHeartBeat(currentDateString, global.getPercentage(fromDate, currentDate, lastDate))
|
||||
|
||||
checkStopTaskGracefully();
|
||||
|
||||
} catch (err) {
|
||||
@@ -371,10 +378,6 @@
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoop -> Entering function."); }
|
||||
|
||||
/* Telling the world we are alive and doing well */
|
||||
let processingDate = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2);
|
||||
bot.processHeartBeat(processingDate)
|
||||
|
||||
/*
|
||||
|
||||
We will iterate through all posible periods.
|
||||
|
||||
@@ -812,10 +812,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function processHeartBeat(processingDate) {
|
||||
function processHeartBeat(processingDate, percentage) {
|
||||
let event = {
|
||||
seconds: (new Date()).getSeconds(),
|
||||
processingDate: processingDate
|
||||
processingDate: processingDate,
|
||||
percentage: percentage
|
||||
}
|
||||
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event)
|
||||
}
|
||||
|
||||
@@ -1000,10 +1000,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function processHeartBeat(processingDate) {
|
||||
function processHeartBeat(processingDate, percentage) {
|
||||
let event = {
|
||||
seconds: (new Date()).getSeconds(),
|
||||
processingDate: processingDate
|
||||
processingDate: processingDate,
|
||||
percentage: percentage
|
||||
}
|
||||
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
const LOG_FILE_CONTENT = false;
|
||||
|
||||
const MODULE_NAME = "Trading Simulation -> " + bot.SESSION.name;
|
||||
const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000;
|
||||
|
||||
const GMT_SECONDS = ':00.000 GMT+0000';
|
||||
|
||||
let thisObject = {
|
||||
|
||||
@@ -25,6 +25,8 @@ global.CUSTOM_FAIL_RESPONSE = {
|
||||
message: "Custom Message"
|
||||
};
|
||||
|
||||
const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000;
|
||||
|
||||
/* Process Events */
|
||||
|
||||
process.on('uncaughtException', function (err) {
|
||||
@@ -260,3 +262,11 @@ function startRoot(processIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
global.getPercentage = function (fromDate, currentDate, lastDate) {
|
||||
let fromDays = Math.trunc(fromDate.valueOf() / ONE_DAY_IN_MILISECONDS)
|
||||
let currentDays = Math.trunc(currentDate.valueOf() / ONE_DAY_IN_MILISECONDS)
|
||||
let lastDays = Math.trunc(lastDate.valueOf() / ONE_DAY_IN_MILISECONDS)
|
||||
let percentage = (currentDays - fromDays) * 100 / (lastDays - fromDays)
|
||||
return percentage.toFixed(2) + " %"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user