Merge branch 'develop' of https://github.com/Superalgos/Platform into develop

This commit is contained in:
Julian Molina committed 2020-02-04 17:20:52 +01:00
commit eddc57e89c
29 files changed
+168 -912

No files matched your search

@@ -145,7 +145,7 @@ function newNodeCloning () {
isPinned: node.payload.floatingObject.isPinned,
isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually),
isCollapsed: (node.payload.floatingObject.isCollapsed && node.payload.floatingObject.collapsedManually),
isTensed: (node.payload.floatingObject.isTensed && node.payload.floatingObject.tensedManually)
tensionLevel: (node.payload.floatingObject.tensionLevel)
},
uiObject: {
isRunning: node.payload.uiObject.isRunning,
@@ -148,7 +148,7 @@ function newProtocolNode () {
isPinned: node.payload.floatingObject.isPinned,
isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually),
isCollapsed: (node.payload.floatingObject.isCollapsed && node.payload.floatingObject.collapsedManually),
isTensed: (node.payload.floatingObject.isTensed && node.payload.floatingObject.tensedManually)
tensionLevel: (node.payload.floatingObject.tensionLevel)
},
uiObject: {
isRunning: node.payload.uiObject.isRunning,
+1
View File
@@ -83,6 +83,7 @@ function newCircularMenu () {
menuItem.disableIfPropertyIsDefined = menuItemInitialValue.disableIfPropertyIsDefined
menuItem.propertyToCheckFor = menuItemInitialValue.propertyToCheckFor
menuItem.ring = menuItemInitialValue.ring
menuItem.icons = menuItemInitialValue.icons
if (menuItem.label === undefined) {
menuItem.type = 'Icon Only'
+9 -2
View File
@@ -9,6 +9,7 @@ function newCircularMenuItem () {
confirmationLabel: undefined,
iconOn: undefined,
iconOff: undefined,
icons: undefined,
currentIcon: undefined,
disableIfPropertyIsDefined: undefined,
propertyToCheckFor: undefined,
@@ -92,6 +93,7 @@ function newCircularMenuItem () {
thisObject.container = undefined
thisObject.iconOn = undefined
thisObject.iconOff = undefined
thisObject.icons = undefined
thisObject.currentIcon = undefined
thisObject.payload = undefined
thisObject.actionFunction = undefined
@@ -208,8 +210,13 @@ function newCircularMenuItem () {
thisObject.iconOn = canvas.designerSpace.iconByUiObjectType.get(thisObject.relatedUiObject)
thisObject.iconOff = canvas.designerSpace.iconByUiObjectType.get(thisObject.relatedUiObject)
} else {
thisObject.iconOn = canvas.designerSpace.iconCollection.get(thisObject.iconPathOn)
thisObject.iconOff = canvas.designerSpace.iconCollection.get(thisObject.iconPathOff)
if (thisObject.iconPathOn !== undefined && thisObject.iconPathOff !== undefined) {
thisObject.iconOn = canvas.designerSpace.iconCollection.get(thisObject.iconPathOn)
thisObject.iconOff = canvas.designerSpace.iconCollection.get(thisObject.iconPathOff)
} else {
thisObject.iconOn = canvas.designerSpace.iconCollection.get(thisObject.icons[thisObject.actionStatus()])
thisObject.iconOff = canvas.designerSpace.iconCollection.get(thisObject.icons[thisObject.actionStatus()])
}
}
}
+40 -12
View File
@@ -22,7 +22,7 @@ function newFloatingObject () {
targetRadius: 0, // This is the target radius of the floating object with zoom applied. It should be animated until reaching this value.
isPinned: false,
isFrozen: false,
isTensed: false,
tensionLevel: TENSION_LEVEL.NO_TENSION,
isCollapsed: false,
isParentCollapsed: false,
frozenManually: false,
@@ -139,7 +139,7 @@ function newFloatingObject () {
}
function getTensionStatus () {
return thisObject.isTensed
return thisObject.tensionLevel
}
function freezeToggle () {
@@ -165,14 +165,25 @@ function newFloatingObject () {
}
function tensionToggle () {
if (thisObject.isTensed !== true) {
thisObject.isTensed = true
thisObject.tensedManually = true
} else {
thisObject.isTensed = false
thisObject.tensedManually = false
switch (thisObject.tensionLevel) {
case TENSION_LEVEL.NO_TENSION:
thisObject.tensionLevel = TENSION_LEVEL.LEVEL_360
break
case TENSION_LEVEL.LEVEL_360:
thisObject.tensionLevel = TENSION_LEVEL.LEVEL_180
break
case TENSION_LEVEL.LEVEL_180:
thisObject.tensionLevel = TENSION_LEVEL.LEVEL_90
break
case TENSION_LEVEL.LEVEL_90:
thisObject.tensionLevel = TENSION_LEVEL.LEVEL_45
break
case TENSION_LEVEL.LEVEL_45:
thisObject.tensionLevel = TENSION_LEVEL.NO_TENSION
break
}
return thisObject.isTensed
return thisObject.tensionLevel
}
function physics () {
@@ -212,7 +223,7 @@ function newFloatingObject () {
function tensionPhysics () {
/* Tension Effect */
if (thisObject.isTensed === true) {
if (thisObject.tensionLevel !== TENSION_LEVEL.NO_TENSION && thisObject.isOnFocus !== true) {
let parent = thisObject.payload.chainParent
if (parent === undefined) { return }
if (parent.payload === undefined) { return }
@@ -223,6 +234,22 @@ function newFloatingObject () {
let axisCount = parentChildren.childrenCount
let axisIndex = parentChildren.childIndex
let baseAngle = 0
let tensionLevelAngle
switch (thisObject.tensionLevel) {
case TENSION_LEVEL.LEVEL_360:
tensionLevelAngle = 360
break
case TENSION_LEVEL.LEVEL_180:
tensionLevelAngle = 180
break
case TENSION_LEVEL.LEVEL_90:
tensionLevelAngle = 90
break
case TENSION_LEVEL.LEVEL_45:
tensionLevelAngle = 45
break
}
if (axisIndex === undefined) {
axisCount = 1
@@ -242,9 +269,10 @@ function newFloatingObject () {
}
}
let angleStep = 360 / axisCount
let separatorAngle = (360 - tensionLevelAngle) / 2
let angleStep = tensionLevelAngle / axisCount
thisObject.payload.angle = baseAngle + (axisIndex - 1) * angleStep
thisObject.payload.angle = baseAngle + separatorAngle + (axisIndex - 1) * angleStep
if (thisObject.payload.angle >= 360) {
thisObject.payload.angle = thisObject.payload.angle - 360
}
+1 -1
View File
@@ -864,7 +864,7 @@ function newUiObject () {
/* Target Line */
let LINE_STYLE = UI_COLOR.TITANIUM_YELLOW
if (thisObject.payload.floatingObject.isTensed === true) {
if (thisObject.payload.floatingObject.tensionLevel !== TENSION_LEVEL.NO_TENSION) {
LINE_STYLE = UI_COLOR.GOLDEN_ORANGE
}
if (thisObject.payload.floatingObject.isFrozen === true) {
@@ -57,16 +57,12 @@ function newUiObjectConstructor () {
if (payload.node.savedPayload.floatingObject.isCollapsed === true) {
floatingObject.collapseToggle()
}
if (payload.node.savedPayload.floatingObject.isTensed === true) {
floatingObject.tensionToggle()
}
floatingObject.tensionLevel = payload.node.savedPayload.floatingObject.tensionLevel
}
/* For brand new objects being created directly by the user, we will make them inherit some properties from their parents. */
if (userAddingNew === true) {
if (payload.parentNode.payload.floatingObject.isTensed === true) {
floatingObject.tensionToggle()
}
floatingObject.tensionLevel = payload.parentNode.payload.floatingObject.tensionLevel
}
let uiObject = newUiObject()
@@ -146,8 +142,7 @@ function newUiObjectConstructor () {
currentStatus: true,
label: undefined,
visible: true,
iconPathOn: 'menu-tensor-fixed-angles',
iconPathOff: 'menu-tensor-free-angles',
icons: ['menu-tensor-free-angles', 'menu-tensor-fixed-angles', 'menu-share', 'compass', 'broken-link'],
rawRadius: 8,
targetRadius: 0,
currentRadius: 0,
@@ -315,6 +310,7 @@ function newUiObjectConstructor () {
switch (payload.node.type) {
case 'Workspace': {
level_0()
floatingObject.tensionLevel = TENSION_LEVEL.LEVEL_360
break
}
+8
View File
@@ -51,6 +51,14 @@ const GET_CONTAINER_PURPOSE = {
DRAGGING: 4
}
const TENSION_LEVEL = {
NO_TENSION: 0,
LEVEL_360: 1,
LEVEL_180: 2,
LEVEL_90: 3,
LEVEL_45: 4
}
/* User Interface Panels */
UI_PANEL = {
@@ -24,65 +24,19 @@
let utilities = UTILITIES.newCloudUtilities(bot, logger);
let year;
let month;
let statusDependencies;
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
statusDependencies = pStatusDependencies;
year = pYear;
month = pMonth;
month = utilities.pad(month, 2); // Adding a left zero when needed.
statusDependencies = pStatusDependencies;
logger.fileName = MODULE_NAME
logger.initialize();
logger.fileName = MODULE_NAME + "-" + year + "-" + month;
logger.initialize();
callBackFunction(global.DEFAULT_OK_RESPONSE);
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> pYear = " + year); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> pMonth = " + month); }
/* The very first validation is about if we are not too far in the future. In those cases we will not proceed and expect this instance to be restarted later. */
let processDate = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000");
let today = new Date();
let tomorrow = new Date(today.valueOf() + 1000 * 60 * 60 * 24);
if (processDate.valueOf() > tomorrow.valueOf()) { // This means that it should start more than a day from current time.
logger.write(MODULE_NAME, "[WARN] initialize -> Too far in the future.");
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "Too far in the future."
}
logger.write(MODULE_NAME, "[WARN] initialize -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
}
if (processDate.valueOf() > today.valueOf()) { // This means that is should start in less than a day from current time.
logger.write(MODULE_NAME, "[WARN] initialize -> Not needed now, but soon.");
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "Not needed now, but soon."
}
logger.write(MODULE_NAME, "[WARN] initialize -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
}
callBackFunction(global.DEFAULT_OK_RESPONSE);
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
/*
@@ -96,26 +50,15 @@
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); }
let processDate = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000");
let lastMinuteOfMonth = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000");
lastMinuteOfMonth.setUTCMonth(lastMinuteOfMonth.getUTCMonth() + 1); // First we go 1 month into the future.
lastMinuteOfMonth.setUTCSeconds(lastMinuteOfMonth.getUTCSeconds() - 30); // Then we go back 30 seconds, or to the last minute of the original month.
let processDate = new Date((new Date()).getUTCFullYear() + "-" + ((new Date()).getUTCMonth() + 1) + "-1 00:00:00.000 GMT+0000");
let thisDatetime = new Date();
let atHeadOfMarket; // This tell us if we are at the month which includes the head of the market according to current datetime.
if ((parseInt(year) === thisDatetime.getUTCFullYear() && parseInt(month) === thisDatetime.getUTCMonth() + 1)) {
atHeadOfMarket = true;
} else {
atHeadOfMarket = false;
}
let market = bot.market;
let lastHoleFixedFile; // Datetime of the last file certified by the Hole Fixing process as without permanent holes.
let firstTradeFile; // Datetime of the first trade file in the whole market history.
let lastFileWithoutHoles; // Datetime of the last verified file without holes.
let lastTradeFileSaved; // Datetime of the last verified file without holes.
let lastCandleClose; // Value of the last candle close.
let lastTradeFile; // Datetime pointing to the last Trade File sucessfuly processed and included in the last file.
@@ -131,7 +74,6 @@
let reportKey;
/* First Status Report */
reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Historic-Trades" + "-" + "dataSet.V1";
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); }
@@ -156,95 +98,12 @@
return;
}
if (thisReport.completeHistory === true) { // We get from the file to know if this markets history is complete or not.
firstTradeFile = new Date(thisReport.beginingOfMarket.year + "-" + thisReport.beginingOfMarket.month + "-" + thisReport.beginingOfMarket.days + " " + thisReport.beginingOfMarket.hours + ":" + thisReport.beginingOfMarket.minutes + GMT_SECONDS);
/* Before processing this month we need to check if it is not too far in the past.*/
if (
processDate.getUTCFullYear() < firstTradeFile.getUTCFullYear()
||
(processDate.getUTCFullYear() === firstTradeFile.getUTCFullYear() && processDate.getUTCMonth() < firstTradeFile.getUTCMonth())
) {
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> The current year / month is before the start of the market history for market.");
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "Month before it is needed."
}
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
}
} else {
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Trade History is not complete.");
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "Dependency not ready."
}
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
}
/* Next Status Report */
reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Historic-Trades" + "-" + "dataSet.V1"
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); }
if (statusDependencies.statusReports.get(reportKey).status === "Status Report is corrupt.") {
logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. ");
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
return;
}
thisReport = statusDependencies.statusReports.get(reportKey).file;
if (thisReport.lastFileSaved === undefined) {
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey);
logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> It is too early too run this process since the hole fixing process has not started yet for this month.");
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "Dependency does not exist."
}
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
}
if (thisReport.monthChecked === true) {
lastFileWithoutHoles = new Date(); // We need this with a valid value.
} else {
/*
If the hole report is incomplete, we are only interested if we are at the head of the market.
Otherwise, we are not going to calculate the candles of a month which was not fully checked for holes.
*/
if (atHeadOfMarket === true) {
lastFileWithoutHoles = new Date(thisReport.lastFileSaved.year + "-" + thisReport.lastFileSaved.month + "-" + thisReport.lastFileSaved.days + " " + thisReport.lastFileSaved.hours + ":" + thisReport.lastFileSaved.minutes + GMT_SECONDS);
} else {
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "Dependency not ready."
}
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
}
}
firstTradeFile = new Date(thisReport.beginingOfMarket.year + "-" + thisReport.beginingOfMarket.month + "-" + thisReport.beginingOfMarket.days + " " + thisReport.beginingOfMarket.hours + ":" + thisReport.beginingOfMarket.minutes + GMT_SECONDS);
lastTradeFileSaved = new Date(thisReport.lastFileSaved.year + "-" + thisReport.lastFileSaved.month + "-" + thisReport.lastFileSaved.days + " " + thisReport.lastFileSaved.hours + ":" + thisReport.lastFileSaved.minutes + GMT_SECONDS);
/* Final Status Report */
reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" + "-" + year + "-" + month;
reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1"
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); }
if (statusDependencies.statusReports.get(reportKey).status === "Status Report is corrupt.") {
@@ -264,34 +123,16 @@
return;
}
if (thisReport.monthCompleted === true) {
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> The current year / month was already fully processed.");
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "Month fully processed."
}
logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
lastHoleFixedFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + "00:00" + GMT_SECONDS);
lastCandleClose = thisReport.candleClose;
if (thisReport.fileComplete === true) {
buildCandlesAndVolumes();
} else {
lastHoleFixedFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + "00:00" + GMT_SECONDS);
lastCandleClose = thisReport.candleClose;
if (thisReport.fileComplete === true) {
buildCandlesAndVolumes();
} else {
lastTradeFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + thisReport.lastTradeFile.hours + ":" + thisReport.lastTradeFile.minutes + GMT_SECONDS);
findPreviousContent();
}
lastTradeFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + thisReport.lastTradeFile.hours + ":" + thisReport.lastTradeFile.minutes + GMT_SECONDS);
findPreviousContent();
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> err = " + err.stack);
if (err.message === "Cannot read property 'file' of undefined") {
@@ -436,7 +277,7 @@
Before going backwards, we need to be sure we are not at the begining of the market.
*/
if ((Number(year) === firstTradeFile.getUTCFullYear() && parseInt(month) === firstTradeFile.getUTCMonth() + 1)) {
if ((Number((new Date()).getUTCFullYear()) === firstTradeFile.getUTCFullYear() && parseInt(((new Date()).getUTCMonth() + 1)) === firstTradeFile.getUTCMonth() + 1)) {
/*
We are at the begining of the market, so we will set everyting to build the first candle.
@@ -652,47 +493,9 @@
}
}
/* Check if we are outside the currrent Month */
if (date.getUTCMonth() + 1 !== parseInt(month)) {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> End of the month reached at date = " + date.toUTCString()); }
lastHoleFixedFile = new Date(lastHoleFixedFile.valueOf() - ONE_DAY_IN_MILISECONDS);
writeStatusReport(lastHoleFixedFile, lastTradeFile, lastCandleClose, true, true, onStatusReportWritten);
return;
function onStatusReportWritten(err) {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> Entering function."); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> err = " + err.stack);
callBackFunction(err);
return;
}
let customOK = {
result: global.CUSTOM_OK_RESPONSE.result,
message: "End of the month reached."
}
logger.write(MODULE_NAME, "[WARN] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> customOK = " + customOK.message);
callBackFunction(customOK);
return;
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> err = " + err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
}
/* Check if we have past the most recent hole fixed file */
if (date.valueOf() > lastFileWithoutHoles.valueOf()) {
if (date.valueOf() > lastTradeFileSaved.valueOf()) {
writeFiles(lastHoleFixedFile, candles, volumes, false, onFilesWritten);
return;
@@ -1062,7 +865,7 @@
return;
}
let key = bot.dataMine + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion + "-" + year + "-" + month;
let key = bot.dataMine + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion
let statusReport = statusDependencies.statusReports.get(key);
statusReport.file = {
@@ -1079,7 +882,6 @@
minutes: lastTradeFile.getUTCMinutes()
},
candleClose: candleClose,
monthCompleted: isMonthComplete,
fileComplete: isFileComplete
};
@@ -30,7 +30,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
logger.fileName = MODULE_NAME;
@@ -97,7 +97,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
verbose: false,
options: options
}
console.log(JSON.stringify(exchangeConstructorParams))
const exchange = new exchangeClass(exchangeConstructorParams)
begin()
@@ -199,7 +199,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let processingDate = new Date(since)
processingDate = processingDate.getUTCFullYear() + '-' + utilities.pad(processingDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(processingDate.getUTCDate(), 2);
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getTrades -> Fetching Trades @ " + processingDate + "-> exchange = " + bot.exchange + " -> symbol = " + symbol + " -> since = " + since + " -> limit = " + limit ) }
console.log("Charly -> " + MODULE_NAME + " -> start -> getTrades -> Fetching Trades from " + bot.exchange + " " + symbol + " @ " + processingDate + " collecting " + allTrades.length + " records trades so far.")
//console.log("Charly -> " + MODULE_NAME + " -> start -> getTrades -> Fetching Trades from " + bot.exchange + " " + symbol + " @ " + processingDate + " collecting " + allTrades.length + " records trades so far.")
bot.processHeartBeat("Fetching " + allTrades.length.toFixed(0) + " trades from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well
if (fetchType === "by Id") {
@@ -295,7 +295,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
let processingDate = new Date(trade.timestamp)
processingDate = processingDate.getUTCFullYear() + '-' + utilities.pad(processingDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(processingDate.getUTCDate(), 2);
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> saveTrades -> Saving Trades @ " + processingDate + " -> i = " + i + " -> total = " + allTrades.length) }
console.log("Charly -> " + MODULE_NAME + " -> start -> saveTrades -> Saving Trades from " + bot.exchange + " " + symbol + " @ " + processingDate)
//console.log("Charly -> " + MODULE_NAME + " -> start -> saveTrades -> Saving Trades from " + bot.exchange + " " + symbol + " @ " + processingDate)
bot.processHeartBeat("Saving " + i.toFixed(0) + " trades from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well
}
@@ -425,8 +425,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt
days: beginingOfMarket.getUTCDate(),
hours: beginingOfMarket.getUTCHours(),
minutes: beginingOfMarket.getUTCMinutes()
},
completeHistory: true
}
};
if (fetchType === "by Id") {
@@ -26,7 +26,7 @@
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
@@ -20,7 +20,7 @@
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
@@ -28,7 +28,7 @@
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
@@ -121,7 +121,7 @@ Read the candles and volumes from Bruce and produce a file for each day and for
/* Second, we get the report from Bruce, to know when the marted ends. */
reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" + "-" + bot.processDatetime.getUTCFullYear() + "-" + utilities.pad(bot.processDatetime.getUTCMonth() + 1,2);
reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1"
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); }
statusReport = statusDependencies.statusReports.get(reportKey);
@@ -28,7 +28,7 @@
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
@@ -130,7 +130,7 @@
/* Second, we get the report from Bruce, to know when the marted ends. */
reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" + "-" + bot.processDatetime.getUTCFullYear() + "-" + utilities.pad(bot.processDatetime.getUTCMonth() + 1,2);
reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1"
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); }
statusReport = statusDependencies.statusReports.get(reportKey);
@@ -29,7 +29,7 @@
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
@@ -26,7 +26,7 @@
return thisObject;
function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencies, callBackFunction) {
try {
+1 -1
View File
@@ -1 +1 @@
{"type":"Workspace","name":"Bot Instance Config Cleaned","rootNodes":[{"type":"Network","name":"Superalgos","networkNodes":[{"type":"Network Node","name":"My Computer","dataStorage":{"type":"Data Storage","name":"New Data Storage","sessionIndependentData":{"type":"Session Independent Data","name":"New Session Independent Data","singleMarketData":[{"type":"Single Market Data","name":"Poloniex BTC/USDT","dataProducts":[{"type":"Data Product","name":"Candles","id":"55e735a5-60c9-4e2d-a582-a6c6eddf3502","savedPayload":{"position":{"x":20609.060583563103,"y":26956.02472972635},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candles","id":"36ae2d5d-6734-4526-b2f8-31c89a0c4fc1"}}},{"type":"Data Product","name":"Volumes","id":"ffaf5a8e-12d6-4040-922d-57845eb3377c","savedPayload":{"position":{"x":20786.769043391556,"y":26720.59025452689},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volumes","id":"b2d5ba69-67ac-490f-9e74-28239b35a92e"}}},{"type":"Data Product","name":"Candle-Stairs","id":"e1c46e1f-09d1-46a2-b738-e761b4e04cd9","savedPayload":{"position":{"x":21035.604312895422,"y":26867.33498240933},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candle-Stairs","id":"642474e9-da61-4168-97dc-7f7869bebc02"}}},{"type":"Data Product","name":"Volume-Stairs","id":"eefaf182-ffe4-457e-a7fa-f43dfabdc086","savedPayload":{"position":{"x":21313.878440686374,"y":27122.80731223341},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volume-Stairs","id":"846e9572-c4d6-4c7e-942e-c82402c5ecea"}}},{"type":"Data Product","name":"Bollinger Bands","id":"3576cfd0-1774-4094-b8a0-66e182fc4c41","savedPayload":{"position":{"x":21192.046121269403,"y":27504.219756869486},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Bands","id":"29088877-8d63-4217-8d34-8742afc262f4"}}},{"type":"Data Product","name":"Percentage Bandwidth","id":"4dfde44c-0bbf-4204-91de-ce99ecba4cf2","savedPayload":{"position":{"x":20863.410278195162,"y":27763.695479649887},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Percentage Bandwidth","id":"3b7885a0-cd72-4a3f-a38b-3dc8c47bd068"}}},{"type":"Data Product","name":"Bollinger Channels Objects","id":"6986bcb1-119c-48c9-a00b-d046e9e07951","savedPayload":{"position":{"x":20389.450696849115,"y":27792.09804727952},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Channels Objects","id":"1f111f72-624f-4166-9f99-ab8d785d5267"}}},{"type":"Data Product","name":"Bollinger Sub-Channels Objects","id":"85098ab8-a125-49f1-b24d-416c2090c7a0","savedPayload":{"position":{"x":20385.185994501047,"y":27286.852678370993},"targetPosition":{"x":20728.19588814266,"y":27145.882418400266},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Sub-Channels Objects","id":"080c87fc-4546-4482-ab11-180a33f6d9ab"}}}],"id":"49a747b4-2eb7-41d6-b0e2-493f43ceed44","savedPayload":{"position":{"x":20727.379077830854,"y":27145.746269357067},"targetPosition":{"x":20256.325880871336,"y":26996.112582106336},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Market","name":"BTC/USDT","id":"d4098b73-7e25-434e-8fd9-342393cbb400"}}},{"type":"Single Market Data","name":"Kraken ETH/BTC","dataProducts":[{"type":"Data Product","name":"Candles","id":"fce50098-d674-4006-94ad-cce46f3d59a4","savedPayload":{"position":{"x":20736.33904295617,"y":27187.275014254603},"targetPosition":{"x":20344.69667221882,"y":27169.01171494068},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"isTensed":true},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candles","id":"36ae2d5d-6734-4526-b2f8-31c89a0c4fc1"}}},{"type":"Data Product","name":"Volumes","id":"601b3615-Line truncated
{"type":"Workspace","name":"New Tension Level","rootNodes":[{"type":"Network","name":"Superalgos","networkNodes":[{"type":"Network Node","name":"My Computer","dataStorage":{"type":"Data Storage","name":"New Data Storage","sessionIndependentData":{"type":"Session Independent Data","name":"New Session Independent Data","singleMarketData":[{"type":"Single Market Data","name":"Poloniex BTC/USDT","dataProducts":[{"type":"Data Product","name":"Candles","id":"55e735a5-60c9-4e2d-a582-a6c6eddf3502","savedPayload":{"position":{"x":20411.876309482992,"y":24072.552323772936},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candles","id":"36ae2d5d-6734-4526-b2f8-31c89a0c4fc1"}}},{"type":"Data Product","name":"Volumes","id":"ffaf5a8e-12d6-4040-922d-57845eb3377c","savedPayload":{"position":{"x":21576.750162194072,"y":24897.940068643937},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volumes","id":"b2d5ba69-67ac-490f-9e74-28239b35a92e"}}},{"type":"Data Product","name":"Candle-Stairs","id":"e1c46e1f-09d1-46a2-b738-e761b4e04cd9","savedPayload":{"position":{"x":22164.192575141195,"y":25096.697726539976},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candle-Stairs","id":"642474e9-da61-4168-97dc-7f7869bebc02"}}},{"type":"Data Product","name":"Volume-Stairs","id":"eefaf182-ffe4-457e-a7fa-f43dfabdc086","savedPayload":{"position":{"x":22284.363972425384,"y":25711.81834982707},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Volume-Stairs","id":"846e9572-c4d6-4c7e-942e-c82402c5ecea"}}},{"type":"Data Product","name":"Bollinger Bands","id":"3576cfd0-1774-4094-b8a0-66e182fc4c41","savedPayload":{"position":{"x":22968.55103697409,"y":28375.729219407665},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Bands","id":"29088877-8d63-4217-8d34-8742afc262f4"}}},{"type":"Data Product","name":"Percentage Bandwidth","id":"4dfde44c-0bbf-4204-91de-ce99ecba4cf2","savedPayload":{"position":{"x":22350.09846955143,"y":28730.262872271254},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Percentage Bandwidth","id":"3b7885a0-cd72-4a3f-a38b-3dc8c47bd068"}}},{"type":"Data Product","name":"Bollinger Channels Objects","id":"6986bcb1-119c-48c9-a00b-d046e9e07951","savedPayload":{"position":{"x":19144.214049771195,"y":27912.629819702946},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Channels Objects","id":"1f111f72-624f-4166-9f99-ab8d785d5267"}}},{"type":"Data Product","name":"Bollinger Sub-Channels Objects","id":"85098ab8-a125-49f1-b24d-416c2090c7a0","savedPayload":{"position":{"x":18615.447470194533,"y":27165.9917332436},"targetPosition":{"x":22132.22295470948,"y":27728.70529460941},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Bollinger Sub-Channels Objects","id":"080c87fc-4546-4482-ab11-180a33f6d9ab"}}}],"id":"49a747b4-2eb7-41d6-b0e2-493f43ceed44","savedPayload":{"position":{"x":22132.22295470948,"y":27728.70529460941},"targetPosition":{"x":20178.49770620469,"y":27037.544811321794},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Market","name":"BTC/USDT","id":"d4098b73-7e25-434e-8fd9-342393cbb400"}}},{"type":"Single Market Data","name":"Kraken ETH/BTC","dataProducts":[{"type":"Data Product","name":"Candles","id":"fce50098-d674-4006-94ad-cce46f3d59a4","savedPayload":{"position":{"x":22188.207505020688,"y":27958.48275803743},"targetPosition":{"x":20614.630309702367,"y":27883.52403758208},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"tensionLevel":1},"uiObject":{},"referenceParent":{"type":"Product Definition","name":"Candles","id":"36ae2d5d-6734-4526-b2f8-31c89a0c4fc1"}}},{"type":"Data Product","name":"Volumes","id":"601b3615-7045-4e8f-Line truncated
+10 -10
View File
@@ -32,7 +32,7 @@ function bootLoader() {
}
function runTask(message) {
console.log('[INFO] Task Manager -> server -> runTask -> Entering function.')
//console.log('[INFO] Task Manager -> server -> runTask -> Entering function.')
if (message.event === undefined) {
console.log('[WARN] Task Manager -> server -> runTask -> Message Received Without Event -> message = ' + JSON.stringify(message))
@@ -49,8 +49,8 @@ function runTask(message) {
return
}
console.log('[INFO] Task Manager -> server -> runTask -> Task Name = ' + message.event.taskName)
console.log('[INFO] Task Manager -> server -> runTask -> Task Id = ' + message.event.taskId)
//console.log('[INFO] Task Manager -> server -> runTask -> Task Name = ' + message.event.taskName)
//console.log('[INFO] Task Manager -> server -> runTask -> Task Id = ' + message.event.taskId)
let path = process.env.TASK_SERVER_PATH + '/server.js'
@@ -77,22 +77,22 @@ function runTask(message) {
console.log(`[ERROR] Task Manager -> server -> runTask -> Task Manager exited with error ${err}`)
})
task.childProcess.on('close', (code, signal) => {
console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Name = ' + task.name)
console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Id = ' + task.id)
//console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Name = ' + task.name)
//console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Id = ' + task.id)
tasks.delete(task.id)
})
setTimeout(sendStartingEvent, 3000)
function sendStartingEvent() {
console.log('[INFO] Task Manager -> server -> runTask -> Emitting Event -> key = ' + 'Task Server - ' + task.id)
//console.log('[INFO] Task Manager -> server -> runTask -> Emitting Event -> key = ' + 'Task Server - ' + task.id)
global.SYSTEM_EVENT_HANDLER.raiseEvent('Task Server - ' + task.id, 'Run Task', message.event)
}
}
function stopTask(message) {
console.log('[INFO] Task Manager -> server -> stopTask -> Entering function.')
//console.log('[INFO] Task Manager -> server -> stopTask -> Entering function.')
if (message.event === undefined) {
console.log('[WARN] Task Manager -> server -> stopTask -> Message Received Without Event -> message = ' + JSON.stringify(message))
@@ -104,14 +104,14 @@ function stopTask(message) {
return
}
console.log('[INFO] Task Manager -> server -> stopTask -> Task Name = ' + message.event.taskName)
console.log('[INFO] Task Manager -> server -> stopTask -> Task Id = ' + message.event.taskId)
//console.log('[INFO] Task Manager -> server -> stopTask -> Task Name = ' + message.event.taskName)
//console.log('[INFO] Task Manager -> server -> stopTask -> Task Id = ' + message.event.taskId)
let task = tasks.get(message.event.taskId)
if (task) {
task.childProcess.send('Stop this Task');
console.log('[INFO] Task Manager -> server -> stopTask -> Child Process instructed to finish.')
//console.log('[INFO] Task Manager -> server -> stopTask -> Child Process instructed to finish.')
} else {
console.log('[WARN] Task Manager -> server -> stopTask -> Cannot delete Task that does not exist.')
}
+4 -2
View File
@@ -37,10 +37,12 @@ exports.newDebugLog = function newDebugLog() {
}
}
function newInternalLoop(pBot, pProcess) {
function newInternalLoop(pBot, pProcess, date) {
if (date === undefined) { date = thisObject.bot.processDatetime }
console.log(new Date().toISOString() + " " + strPad(pBot, 20) + " " + strPad(pProcess, 30) + " Entered into Internal Loop # " + strPad(internalLoopCounter + 1, 4) + " bot.processDatetime = " + thisObject.bot.processDatetime.toISOString());
console.log(new Date().toISOString() + " " + strPad(pBot, 20) + " " + strPad(pProcess, 30) + " " + strPad(thisObject.bot.exchange, 20) + " " + strPad(thisObject.bot.market.baseAsset + '/' + thisObject.bot.market.quotedAsset, 10)
+ " Entered into Internal Loop # " + strPad(internalLoopCounter + 1, 8) + " " + strPad(date.toISOString(), 30))
persist();
+6 -90
View File
@@ -85,7 +85,7 @@
}
}
function run(pMonth, pYear, callBackFunction) {
function run(callBackFunction) {
try {
@@ -145,8 +145,8 @@
/* High level log entry */
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4)
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8));
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10)
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8));
/* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */
@@ -169,7 +169,7 @@
processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger)
processExecutionEvents.initialize(pMonth, pYear, onInizialized);
processExecutionEvents.initialize(onInizialized);
function onInizialized(err) {
@@ -317,7 +317,7 @@
statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES);
statusDependencies.initialize(pMonth, pYear, onInizialized);
statusDependencies.initialize(onInizialized);
function onInizialized(err) {
@@ -496,7 +496,7 @@
usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage);
usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized);
usertBot.initialize(statusDependencies, onInizialized);
function onInizialized(err) {
@@ -530,18 +530,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -642,36 +630,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -760,18 +718,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -874,36 +820,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message);
logger.persist();
-2
View File
@@ -453,8 +453,6 @@
bot.multiPeriodProcessDatetime = new Date(bot.multiPeriodProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS);
previousDay = new Date(bot.multiPeriodProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS);
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + "bot.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime.toISOString());
if (global.WRITE_LOGS_TO_FILES === 'true') {
logger.newInternalLoop(bot.codeName, bot.process);
}
+1 -3
View File
@@ -306,9 +306,7 @@
bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS);
previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS);
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + "bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime.toISOString());
if (global.WRITE_LOGS_TO_FILES === 'true') {
logger.newInternalLoop(bot.codeName, bot.process);
}
+11 -20
View File
@@ -19,30 +19,21 @@
let processThisDependsOn; // This is the process this process needs to wait for it to finishes in order to start.
let month;
let year;
let currentProcessKey
let datetimeForLogs = ''
return thisObject;
function initialize(pMonth, pYear, callBackFunction) {
function initialize(callBackFunction) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
month = pMonth;
year = pYear;
if (month && year) {
datetimeForLogs = "Month: " + month + " Year: " + year
}
let name = 'Not Depends on any Process'
if (bot.processNode.referenceParent !== undefined) {
currentProcessKey = bot.processNode.referenceParent.name + "-" + bot.processNode.referenceParent.type + "-" + bot.processNode.referenceParent.id
let market = bot.market.baseAsset + '/' + bot.market.quotedAsset
currentProcessKey = bot.processNode.referenceParent.name + "-" + bot.processNode.referenceParent.type + "-" + bot.processNode.referenceParent.id + "-" + bot.exchange + "-" + market
if (bot.processNode.referenceParent.executionStartedEvent !== undefined) {
if (bot.processNode.referenceParent.executionStartedEvent.referenceParent !== undefined) {
@@ -51,9 +42,9 @@
name = processThisDependsOn.name
if (processThisDependsOn.code.monthlyInstances === true) {
logger.fileName = MODULE_NAME + "." + name + "." + year + "." + month;
logger.fileName = MODULE_NAME + "." + name;
}
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + datetimeForLogs + " depends on " + name); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + " depends on " + name); }
}
}
}
@@ -79,10 +70,9 @@
/* This forces this process to wait until the process that this one depends on, emits its event signaling that the process execution has finished. */
let extraCallerId = '-' + Math.trunc(Math.random() * 10000) + '-'
if (month) { extraCallerId = extraCallerId + '-' + month }
if (year) { extraCallerId = extraCallerId + '-' + year }
let key = processThisDependsOn.name + "-" + processThisDependsOn.type + "-" + processThisDependsOn.id
let market = bot.market.baseAsset + '/' + bot.market.quotedAsset
let key = processThisDependsOn.name + "-" + processThisDependsOn.type + "-" + processThisDependsOn.id + "-" + bot.exchange + "-" + market
let callerId = bot.dataMine + "-" + bot.codeName + "-" + bot.process + extraCallerId
let subscriptionId
@@ -120,7 +110,7 @@
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + datetimeForLogs + " Finished."); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Finished."); }
}
callBackFunction(message.event.err);
@@ -134,7 +124,7 @@
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " + datetimeForLogs); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " ); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
}
@@ -157,7 +147,8 @@
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Finished')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Finished', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " + datetimeForLogs); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " ); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
+11 -127
View File
@@ -53,7 +53,6 @@
function initialize(callBackFunction) {
try {
console.log(logDisplace + "Root : [INFO] initialize -> Entering function. ");
/* Global control of logging. */
@@ -159,7 +158,6 @@
function getBotConfigFromFile() {
try {
console.log(logDisplace + "Root : [INFO] start -> getBotConfigFromFile -> Entering function. ");
const FILE_STORAGE = require('./FileStorage.js');
let fileStorage = FILE_STORAGE.newFileStorage();
@@ -196,7 +194,6 @@
function bootingBot(processIndex) {
try {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Entering function. "); }
botConfig.process = global.TASK_NODE.bot.processes[processIndex].referenceParent.code.codeName
botConfig.debug = {};
@@ -252,9 +249,6 @@
}
}
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> filePathRoot = " + botConfig.filePathRoot); }
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Process found at the bot configuration file. -> process = " + global.TASK_NODE.bot.processes[processIndex].referenceParent.code.codeName); }
let processConfig = global.TASK_NODE.bot.processes[processIndex].referenceParent.code
if (processConfig.framework !== undefined) {
@@ -281,97 +275,10 @@
try {
/* We test each type of start Mode to get what to run and how. */
if (processConfig.startMode.allMonths !== undefined) {
if (processConfig.startMode.allMonths.run === "true") {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> allMonths start mode detected. "); }
for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) {
for (let month = 12; month > 0; month--) {
let padMonth = pad(month, 2)
let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig));
newInstanceBotConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine.
setTimeout(startProcess, timeDelay);
function startProcess() {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> startProcess -> Ready to start process."); }
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
case 'Indicator Bot': {
runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
}
}
}
if (processConfig.startMode.oneMonth !== undefined) {
if (processConfig.startMode.oneMonth.run === "true") {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> oneMonth start mode detected. "); }
startProcess();
function startProcess() {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> startProcess -> Ready to start process."); }
let month = pad(processConfig.startMode.oneMonth.month, 2);
let year = processConfig.startMode.oneMonth.year;
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator Bot': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
}
if (processConfig.startMode.noTime !== undefined) {
if (processConfig.startMode.noTime.run === "true") {
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.noTime.resumeExecution === true) {
botConfig.hasTheBotJustStarted = false;
} else {
@@ -380,11 +287,11 @@
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(botConfig, processConfig, month, year);
runSensorBot(botConfig, processConfig);
break;
}
case 'Indicator Bot': {
runIndicatorBot(botConfig, processConfig, month, year);
runIndicatorBot(botConfig, processConfig);
break;
}
case 'Trading Bot': {
@@ -405,12 +312,9 @@
botConfig.runAtFixedInterval = true;
botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval;
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(botConfig, processConfig, month, year);
runSensorBot(botConfig, processConfig);
break;
}
default: {
@@ -425,10 +329,6 @@
if (processConfig.startMode.userDefined.run === "true") {
botConfig.startMode = "User Defined";
console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode);
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.userDefined.resumeExecution === true) {
botConfig.hasTheBotJustStarted = false;
@@ -453,7 +353,7 @@
}
function runSensorBot(pBotConfig, pProcessConfig, pMonth, pYear) {
function runSensorBot(pBotConfig, pProcessConfig) {
try {
global.TOTAL_PROCESS_INSTANCES_CREATED++
@@ -465,8 +365,6 @@
logger.bot = pBotConfig;
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> pYear = " + pYear); }
let extractionBotMainLoop = SENSOR_BOT_MAIN_LOOP_MODULE.newSensorBotProcessMainLoop(pBotConfig, logger);
extractionBotMainLoop.initialize(pProcessConfig, onInitializeReady);
@@ -475,25 +373,19 @@
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes);
extractionBotMainLoop.run(whenRunFinishes);
function whenRunFinishes(err) {
pBotConfig.loopCounter = 0;
let botId;
if (pYear !== undefined) {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
let botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully.");
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId);
console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully.");
logger.persist();
@@ -504,7 +396,6 @@
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bye.");
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId);
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution was aborted.");
logger.persist();
}
@@ -527,7 +418,7 @@
}
}
function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) {
function runIndicatorBot(pBotConfig, pProcessConfig) {
try {
global.TOTAL_PROCESS_INSTANCES_CREATED++
@@ -539,8 +430,6 @@
logger.bot = pBotConfig;
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> pYear = " + pYear); }
let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotProcessMainLoop(pBotConfig, logger);
indicatorBotMainLoop.initialize(pProcessConfig, onInitializeReady);
@@ -549,25 +438,20 @@
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes);
indicatorBotMainLoop.run(whenRunFinishes);
function whenRunFinishes(err) {
pBotConfig.loopCounter = 0;
let botId;
if (pYear !== undefined) {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
let botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully.");
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId);
console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully.");
logger.persist();
+7 -57
View File
@@ -92,7 +92,7 @@
}
}
function run(pMonth, pYear, callBackFunction) {
function run(callBackFunction) {
try {
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] run -> Entering function."); }
@@ -148,10 +148,10 @@
bot.processDatetime = new Date(); // This will be considered the process date and time, so as to have it consistenly all over the execution.
/* High level log entry */
/* High level log entry */
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4)
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) + " bot.processDatetime = " + bot.processDatetime.toISOString());
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10)
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) )
/* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */
@@ -173,7 +173,7 @@
processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger)
processExecutionEvents.initialize(pMonth, pYear, onInizialized);
processExecutionEvents.initialize(onInizialized);
function onInizialized(err) {
@@ -321,7 +321,7 @@
statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES);
statusDependencies.initialize(pMonth, pYear, onInizialized);
statusDependencies.initialize(onInizialized);
function onInizialized(err) {
@@ -396,7 +396,7 @@
usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage, STATUS_REPORT, exchangeAPI);
usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized);
usertBot.initialize(statusDependencies, onInizialized);
function onInizialized(err) {
@@ -430,26 +430,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -550,36 +530,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err = " + err.message);
logger.persist();
+4 -26
View File
@@ -16,7 +16,7 @@
return thisObject;
function initialize(pMonth, pYear, callBackFunction) {
function initialize(callBackFunction) {
try {
@@ -44,27 +44,11 @@
let dependenciesToProcess = []
for (let i = 0; i < thisObject.nodeArray.length; i++) {
let statusDependency = {
dependency: thisObject.nodeArray[i],
month: pMonth,
year: pYear
dependency: thisObject.nodeArray[i]
}
dependenciesToProcess.push(statusDependency)
/*
For the special case that the statusDependency is a Self Reference AND this process is sliced in different
instances for each month, we will add the main self reference status report that is month/year independent.
*/
if (statusDependency.dependency.code.mainUtility === "Self Reference" && pMonth !== undefined && pYear !== undefined) {
let mainDependency = {
dependency: thisObject.nodeArray[i],
month: undefined,
year: undefined
}
dependenciesToProcess.push(mainDependency)
}
}
for (let i = 0; i < dependenciesToProcess.length; i++) {
@@ -73,7 +57,7 @@
logger.write(MODULE_NAME, "[INFO] initialize -> onInitilized -> Initializing Status Report # " + (i + 1));
let statusDependency = dependenciesToProcess[i]
statusReportModule.initialize(statusDependency.dependency, statusDependency.month, statusDependency.year, onInitilized);
statusReportModule.initialize(statusDependency.dependency, onInitilized);
function onInitilized(err) {
@@ -152,13 +136,7 @@
loadCount++;
logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Total Added = " + loadCount);
let key;
if (statusDependency.dependency.processRunMonthly === true && statusDependency.month !== undefined && statusDependency.year !== undefined) {
key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion + "-" + statusDependency.year + "-" + statusDependency.month;
} else {
key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion;
}
let key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion;
thisObject.keys.push(key);
thisObject.statusReports.set(key, statusReportModule);
+5 -266
View File
@@ -18,8 +18,7 @@
initialize: initialize,
load: load,
save: save,
status: undefined,
verifyMarketComplete: verifyMarketComplete
status: undefined
};
let statusDependencyNode;
@@ -33,14 +32,11 @@
const FILE_STORAGE = require('./FileStorage.js');
let fileStorage = FILE_STORAGE.newFileStorage(logger);
let month;
let year;
let timePath = '';
let sessionPath = ''
return thisObject;
function initialize(pStatusDependencyNode, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencyNode, callBackFunction) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
@@ -48,9 +44,6 @@
statusDependencyNode = pStatusDependencyNode;
logger.fileName = MODULE_NAME + "." + statusDependencyNode.type + "." + statusDependencyNode.name + "." + statusDependencyNode.id;
month = pMonth;
year = pYear;
/* Some very basic validations that we have all the information needed. */
if (statusDependencyNode.referenceParent === undefined) {
logger.write(MODULE_NAME, "[ERROR] initialize -> Status Dependency without Reference Parent. Status Dependency = " + JSON.stringify(statusDependencyNode));
@@ -128,11 +121,6 @@
if (bot.SESSION !== undefined && statusDependencyNode.bottype === "Trading Bot") {
sessionPath = bot.SESSION.folderName + "/"
}
if (statusDependencyNode.processRunMonthly === true && month !== undefined && year !== undefined) {
logger.fileName = MODULE_NAME + "." + statusDependencyNode.bot + "." + statusDependencyNode.process + "." + year + "." + month;
timePath = "/" + year + "/" + month;
}
callBackFunction(global.DEFAULT_OK_RESPONSE);
@@ -156,9 +144,9 @@
if (ownerId !== botId) {
let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "/" + bot.exchange;
filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process + timePath;
filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process ;
} else {
filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath;
filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process ;
}
filePath += '/' + fileName
@@ -246,7 +234,7 @@
}
let fileName = "Status.Report." + bot.market.baseAsset + '_' + bot.market.quotedAsset + ".json";
let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath;
let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process;
filePath += '/' + fileName
let fileContent = JSON.stringify(thisObject.file);
@@ -278,253 +266,4 @@
}
}
function verifyMarketComplete(callBackFunction) {
/*
The mission of this function is to update the main status report on a scheme where there are monthly sub reports.
This report contains the date of the last file sucessfully checked but in a consecutive way.
For example: if the market starts in March, and March, April and June are checked, then the file will be the last of June even if September is also checked.
IMPORTANT NOTE: Once executed, this function will leave thisObject in an inconsistant state, so you need to re-initialize it if you wish to use it again.
*/
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> Entering function."); }
let initialYear;
let initialMonth;
let finalYear = (new Date()).getUTCFullYear();
let finalMonth = (new Date()).getUTCMonth() + 1;
/* Lets load again this main status report as it might have changed since its initialization and first load. */
load(onLoad);
function onLoad(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> Entering function."); }
if (
err.result === global.CUSTOM_FAIL_RESPONSE.result &&
(err.message === 'Status Report was never created.')
) {
logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> err = "+ err.stack);
/* The first month of the market didnt create the main report yet. Aborting verification. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> Verification ABORTED since the main status report does not exist."); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> onLoad -> err = "+ err.stack);
callBackFunction(err);
return;
}
/* Here we get the initial month and year from where our verification process will start. */
initialYear = thisObject.file.lastFile.year;
initialMonth = thisObject.file.lastFile.month;
loopCycle();
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> onLoad -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
function loopCycle() {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> Entering function."); }
/* Here we read the status report file of each month / year to verify if it is complete or not. */
let paddedInitialMonth = utilities.pad(initialMonth, 2);
timePath = "/" + initialYear + "/" + paddedInitialMonth;
load(onLoad);
function onLoad(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Entering function."); }
if (
err.result === global.CUSTOM_FAIL_RESPONSE.result &&
(err.message === 'Status Report was never created.')
) {
logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack);
/* The first month of the market didnt create the main report yet. Aborting verification. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not exist. "); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack);
callBackFunction(err);
return;
}
if (thisObject.file.monthChecked === true) {
readAndWriteNewReport(JSON.stringify(thisObject.file));
} else {
/* If any of the files says that month is not checked then it is enough to know the market continuity is broken. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " is not marked as complete."); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
function readAndWriteNewReport(monthlyStatusReport) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> Entering function."); }
/* We will read the current file to preserve its data, and save it again with the new lastFile */
monthlyStatusReport = JSON.parse(monthlyStatusReport);
timePath = "";
load(onLoad);
function onLoad(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Entering function."); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> err = "+ err.stack);
callBackFunction(err);
return;
}
if (monthlyStatusReport.lastTrade.id > thisObject.file.lastTrade.id) {
thisObject.file.lastFile = monthlyStatusReport.lastFile;
thisObject.file.lastTrade = monthlyStatusReport.lastTrade;
thisObject.file.lastTrade.counter = undefined;
save(onSave);
function onSave(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> Entering function."); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> err = "+ err.stack);
callBackFunction(err);
return;
}
loop(); // Lets see the next month.
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
} else {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Main Status Report Not Updated."); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Current Trade Id (" + monthlyStatusReport.lastTrade.id + ") is <= than Id at main status report file. (" + thisObject.file.lastTrade.id + ")"); }
loop(); // Lets see the next month.
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
function loop() {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loop -> Entering function."); }
initialMonth++;
if (initialMonth > 12) {
initialMonth = 1;
initialYear++;
}
if ((initialYear === finalYear && initialMonth > finalMonth) || (initialYear > finalYear)) {
/* We arrived to the point where we have checked all the status reports of every month and they are all complete. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loop -> Verification Finished. Success."); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
loopCycle();
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loop -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
}
catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
};
+2 -44
View File
@@ -161,8 +161,8 @@
/* High level log entry */
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + bot.sessionKey
+ " Loop # " + pad(Number(bot.loopCounter), 8));
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10)
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + bot.sessionKey )
/* Checking if we need to need to emit any event */
@@ -791,18 +791,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -907,36 +895,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message);
logger.persist();
+8 -7
View File
@@ -50,7 +50,7 @@ process.on('exit', function (code) {
global.SYSTEM_EVENT_HANDLER.finalize()
global.SYSTEM_EVENT_HANDLER = undefined
console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code)
//console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code)
})
/* Here we listen for the message to stop this Task / Process comming from the Task Manager, which is the paret of this node js process. */
@@ -63,7 +63,8 @@ process.on('message', message => {
There are some process that might no be able to end grafully, for example the ones schedulle to process information in a future day or month.
In order to be sure that the process will be terminated, we schedulle one forced exit in 2 minutes from now.
*/
console.log('[INFO] Task Server -> server -> process.on -> Executing order received from Task Manager to Stop this Task. Nodejs process will be exited in less than 1 minute.')
let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id
console.log('[INFO] Task Server -> server -> process.on -> Stopping Task ' + key + '. Nodejs process will be exited in less than 1 minute.')
setTimeout(global.EXIT_NODE_PROCESS, 60000);
}
});
@@ -81,7 +82,7 @@ global.EXIT_NODE_PROCESS = function exitProcess() {
global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') // Meaning Process Stopped
}
console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server will stop in 10 seconds.");
//console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server will stop in 10 seconds.");
setTimeout(process.exit, 10000) // We will give 10 seconds to logs be written on file
}
@@ -119,7 +120,7 @@ function preLoader() {
if (taskId !== undefined) {
/* The Task Manager sent the info via a process argument. In this case we listen to an event with the Task Info that should be emitted at the UI */
try {
console.log('[INFO] Task Server -> server -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId)
//console.log('[INFO] Task Server -> server -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId)
global.SYSTEM_EVENT_HANDLER.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, undefined, undefined, eventReceived)
function eventReceived(message) {
global.TASK_NODE = message
@@ -133,7 +134,7 @@ function preLoader() {
}
else { /* This process was started not by the Task Manager, but independently (most likely for debugging purposes). In this case we listen to an event with the Task Info that should be emitted at the UI */
try {
console.log('[INFO] Task Server -> server -> preLoader -> Waiting for event to start debugging...')
//console.log('[INFO] Task Server -> server -> preLoader -> Waiting for event to start debugging...')
global.SYSTEM_EVENT_HANDLER.listenToEvent('Task Server', 'Debug Task Started', undefined, undefined, undefined, startDebugging)
function startDebugging(message) {
global.TASK_NODE = message
@@ -247,7 +248,7 @@ function bootLoader() {
function startRoot(processIndex) {
console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ')
// console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ')
const ROOT_MODULE = require('./Root')
let root = ROOT_MODULE.newRoot()
@@ -255,7 +256,7 @@ function startRoot(processIndex) {
root.initialize(onInitialized)
function onInitialized() {
console.log('[INFO] Task Server -> server -> startRoot -> onInitialized -> Entering function. ')
//console.log('[INFO] Task Server -> server -> startRoot -> onInitialized -> Entering function. ')
root.start(processIndex)
}
}