Fixed Interval Execution

This commit is contained in:
Luis Fernando Molina committed 2018-04-19 18:59:36 +02:00
1 parent 57d365a1ff
commit 7cda700a50
4 files changed
+125 -62

No files matched your search

Binary file not shown.
+34 -7
View File
@@ -51,7 +51,17 @@
try {
if (FULL_LOG === true) { logger.write("[INFO] run -> Entering function."); }
loop();
let intervalHandle;
if (bot.runAtFixedInterval === true) {
intervalHandle = setInterval(loop, bot.fixedInterval);
} else {
loop();
}
function loop() {
@@ -252,6 +262,8 @@
if (shallWeStop() === true) {
if (bot.runAtFixedInterval === true) { intervalHandle.clearInterval();}
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Stopping the Loop Gracefully. See you next time! :-)"); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
@@ -262,8 +274,13 @@
switch (nextWaitTime) {
case 'Normal': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); }
setTimeout(loop, processConfig.normalWaitTime);
if (bot.runAtFixedInterval === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Fixed Interval Normal exit point reached."); }
return;
} else {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); }
setTimeout(loop, processConfig.normalWaitTime);
}
}
break;
case 'Retry': {
@@ -272,13 +289,23 @@
}
break;
case 'Sleep': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); }
setTimeout(loop, processConfig.sleepWaitTime);
if (bot.runAtFixedInterval === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Fixed Interval Sleep exit point reached."); }
return;
} else {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); }
setTimeout(loop, processConfig.sleepWaitTime);
}
}
break;
case 'Coma': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); }
setTimeout(loop, processConfig.comaWaitTime);
if (bot.runAtFixedInterval === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Fixed Interval Coma exit point reached."); }
return;
} else {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); }
setTimeout(loop, processConfig.comaWaitTime);
}
}
break;
}
+89 -53
View File
@@ -198,41 +198,44 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) {
/* We tesst each type of start Mode to get what to run and how. */
if (processConfig.startMode.allMonths.run === "true") {
if (processConfig.startMode.allMonths !== undefined) {
if (FULL_LOG === true) { logger.write("[INFO] run -> allMonths start mode detected. "); }
if (processConfig.startMode.allMonths.run === "true") {
for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) {
if (FULL_LOG === true) { logger.write("[INFO] run -> allMonths start mode detected. "); }
for (let month = 12; month > 0; month--) {
for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) {
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
for (let month = 12; month > 0; month--) {
let padMonth = pad(month,2)
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig));
let padMonth = pad(month, 2)
let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine.
setTimeout(startProcess, timeDelay);
let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig));
function startProcess() {
let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine.
setTimeout(startProcess, timeDelay);
if (FULL_LOG === true) { logger.write("[INFO] run -> startProcess -> Ready to start process."); }
function startProcess() {
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
case 'Indicator': {
runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
default: {
logger.write("[ERROR] run -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
if (FULL_LOG === true) { logger.write("[INFO] run -> startProcess -> Ready to start process."); }
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
case 'Indicator': {
runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
default: {
logger.write("[ERROR] run -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
@@ -240,23 +243,49 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) {
}
}
if (processConfig.startMode.oneMonth.run === "true") {
if (processConfig.startMode.oneMonth !== undefined) {
if (FULL_LOG === true) { logger.write("[INFO] run -> oneMonth start mode detected. "); }
if (processConfig.startMode.oneMonth.run === "true") {
startProcess();
if (FULL_LOG === true) { logger.write("[INFO] run -> oneMonth start mode detected. "); }
function startProcess() {
startProcess();
if (FULL_LOG === true) { logger.write("[INFO] run -> startProcess -> Ready to start process."); }
function startProcess() {
let month = pad(processConfig.startMode.oneMonth.month, 2);
let year = processConfig.startMode.oneMonth.year;
if (FULL_LOG === true) { logger.write("[INFO] run -> startProcess -> Ready to start process."); }
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
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 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] run -> 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();
switch (botConfig.type) {
case 'Extraction': {
@@ -267,30 +296,37 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] run -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
}
}
}
if (processConfig.startMode.noTime.run === "true") {
if (processConfig.startMode.fixedInterval !== undefined) {
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.fixedInterval.run === "true") {
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
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 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
}
}
}
+2 -2
View File
@@ -7,7 +7,7 @@
},
"executionList": [
{
"enabled": "true",
"enabled": "false",
"botPath": "../Bots/AAMasters/AAMariam-Trading-Bot",
"process": "Trading-Process"
},
@@ -32,7 +32,7 @@
"process": "Poloniex-Hole-Fixing"
},
{
"enabled": "false",
"enabled": "true",
"botPath": "../Bots/AAMasters/AACharly-Extraction-Bot",
"process": "Poloniex-Live-Trades"
},