From a4759ebf45cbd823bbdb9f292ad5928a5c4c0516 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 18 Mar 2018 12:24:53 +0100 Subject: [PATCH] Multi Process Execution Ready --- .vs/AACloud/v15/.suo | Bin 80384 -> 86016 bytes Assistant.js | 2 + Debug Log.js | 23 ++- Extraction Bot Main Loop.js | 5 +- Indicator Bot Main Loop.js | 4 +- Run.js | 401 ++++++++++++++++++++---------------- Status Report.js | 5 +- Trading Bot Main Loop.js | 4 +- this.config.json | 11 +- 9 files changed, 265 insertions(+), 190 deletions(-) diff --git a/.vs/AACloud/v15/.suo b/.vs/AACloud/v15/.suo index a755e491534b6efb2996de9828b453fc8e26883a..1cb2334681cecf89b31ace000e85430829885af1 100644 GIT binary patch delta 3429 zcmeH}e^6A{702Is`vVqt7ZwnZ1zbRIT?sCrF)=Z$E+wQpXe6P419qlXhK}$?|Iwb0sMOeAZo;-cb%kxR?i72&^CvWB@yG0t|;2 zLN1Q#pTW+DJ_ndVJeUu9z+GT2r~$VF2bc|JffDd4NCd)Xx+HZ-nJ`?@jv~lpun6Qt z`?4V8z->`mEY=;>g%i~l82d<4{k2G9u7fFFar*_C102ScplyO5pTzI;Vq#jA`CQ)th?fH;B5=n3$3 zc}={?Zx!I)@mzMxvv|9%GdFfB!i#7IOb|&HdtC~B3D1e2Z!tm>qoS4a>Uev{R`kRY zeh>5t-~h3Ni<$kfMZ#|d!j9$J16$-<^u_WmVv2l=KGF2k^gE$104TlK__FYF7~*ig z2E<}x3BLojNOr^vepWy)0Cxki`)tlNc(WgXCT2Vc`5mwxh|E3=Hg@~wa<9Q$vKht} z@Hh}5nju@Fx(Tuk2q)ViBPYO@4e91~SRG&|P!iVCO>JGm5mKyvYUMU-hx~@b*RAdH z>k@BETy2UtuwZKRRN`hGh9P#3riF8VLHu_5gPJ30j6Qd!rpiil7H1_p<3;_6cQf`l zJv$>vt$wmwd&L5-WM}CWXO;d7A+~Uv z^Ia2(t&0 zW4;GSEz&E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c+{%Q1_#9(Q6BA(aSU$T_XWCTc5-pR;&7B`DXrxGh{q1jCP@KK3J$`Aye^0~Ak_@8$0 zHy`ifs>n9ft2y*lYOpJriYdf-pRVHfPkQ*B$bQ-;TfvZnG(PrmF(;qe$Nuxru{)AR zR{r42HN5fjRQ}#L-U=i^$``$0OW zxneGdu}A#J^yqI_|M#3=N58z&`u{RuA_Iawzg#`YeEy4fdvcTM5wgqwDEJ$s)a;E0 zwDIdK?*BG%?}>g2wx^KRGucU%3Bi|~l))$Z&vu^(6TY;nMW)9h(=$c?K44w`fpmjY z_)ysO&HmQ2Spy9ZH+(dH()3-$9Qm#UDO8O!LVB|2I))QH?5V4S ztnd~!8tAj|?!IK{Ea*$4ak1p9#zpa3EqN%oE19ZC4#C9kfdKK5NWl2b-Zhs5SDc)2 zl{3+0A<-p(mDH|9sHejGrASdvkw$$sEI~5{t?*&#vZFI@5c;vSr*r{j6N^i=!5!16 SiT_q@Zkoj%P1RA#Me1LpQ7Q2N diff --git a/Assistant.js b/Assistant.js index 14fe9acfb..7d7081b63 100644 --- a/Assistant.js +++ b/Assistant.js @@ -348,6 +348,8 @@ ) { logger.write("[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Cannot be confirmed that the order was executed. It must be manually cancelled by the user or cancelled by the exchange itself."); logger.write("[HINT] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Verify also that you were not running under a Exchange Simulation and you turned it off without deleting the Status Report file."); + logger.write("[HINT] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> If the process was abruptally cancelled and then restarted, it is possible that now is not sincronized with the exchange."); + logger.write("[HINT] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> In any case, to continue, you must delete the Status Report file so as to start over. Also, you must manually delete the orders at the exchange."); callBack(global.DEFAULT_FAIL_RESPONSE); return; } diff --git a/Debug Log.js b/Debug Log.js index 396a36642..29b9f42d9 100644 --- a/Debug Log.js +++ b/Debug Log.js @@ -12,10 +12,12 @@ let firstCall = true; let folderPath; let loopCounter; + let loopIncremented = false; let thisObject = { bot: undefined, fileName: undefined, + forceLoopSplit: false, // When set to 'true' this will force that the logs of the current module are split in many different Loop folders. write: write }; @@ -86,10 +88,25 @@ if (firstCall === true) { createFolders(); } - if (global.loopCointer !== loopCounter) { + if (thisObject.bot.loopCounter !== loopCounter) { - loopCounter = global.loopCointer; - createLoopFolder(); + if (thisObject.forceLoopSplit === false) { + + if (loopIncremented === false) { + + loopIncremented = true; + + loopCounter = thisObject.bot.loopCounter; + createLoopFolder(); + } + } else { + + loopIncremented = true; + + loopCounter = thisObject.bot.loopCounter; + createLoopFolder(); + + } } let filePath = getCurrentLogFile(folderPath + "/" + dateString + "---" + randomId + "---", this.fileName); diff --git a/Extraction Bot Main Loop.js b/Extraction Bot Main Loop.js index e37f7d5cd..f6c2c15d1 100644 --- a/Extraction Bot Main Loop.js +++ b/Extraction Bot Main Loop.js @@ -13,6 +13,7 @@ const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = bot; + logger.forceLoopSplit = true; let thisObject = { initialize: initialize, @@ -55,7 +56,7 @@ function loop() { try { - global.loopCointer++; + bot.loopCounter++; if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> Entering function."); } @@ -74,8 +75,8 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ - let dependencies; let userBot; + let dependencies; let nextWaitTime; diff --git a/Indicator Bot Main Loop.js b/Indicator Bot Main Loop.js index 56b7b1129..484fcd81d 100644 --- a/Indicator Bot Main Loop.js +++ b/Indicator Bot Main Loop.js @@ -13,6 +13,7 @@ const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = bot; + logger.forceLoopSplit = true; let thisObject = { initialize: initialize, @@ -55,7 +56,7 @@ function loop() { try { - global.loopCointer++; + bot.loopCounter++; if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> Entering function."); } @@ -74,6 +75,7 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ let userBot; + let dependencies; let nextWaitTime; diff --git a/Run.js b/Run.js index f859c51a1..b3c17c8c7 100644 --- a/Run.js +++ b/Run.js @@ -117,11 +117,6 @@ global.dailyFilePeriods = global.dailyFilePeriods = JSON.parse(global.dailyFilePeriods); - -/* Loop Counter */ - -global.loopCointer = 0; - /* Small Function to fix numbers into strings in a cool way. */ function pad(str, max) { @@ -140,7 +135,7 @@ const EXTRACTION_BOT_MAIN_LOOP_MODULE = require('./Extraction Bot Main Loop'); let logger; -for (let p = 0; p < global.PLATFORM_CONFIG.executionList; p++) { +for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { let listItem = PLATFORM_CONFIG.executionList[p]; @@ -150,230 +145,282 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList; p++) { try { - botConfig = JSON.parse(fs.readFileSync(global.PLATFORM_CONFIG.bot.path + '/this.bot.config.json', 'utf8')); + botConfig = JSON.parse(fs.readFileSync(listItem.botPath + '/this.bot.config.json', 'utf8')); } catch (err) { console.log("[ERROR] 'readConfig' - ERROR : " + err.message); return; } + botConfig.process = listItem.process; + logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = botConfig; + /* Loop Counter */ + + botConfig.loopCounter = 0; + + if (FULL_LOG === true) { logger.write("[INFO] run -> Processing item from executionList -> p = " + p); } + if (FULL_LOG === true) { logger.write("[INFO] run -> listItem.botPath = " + listItem.botPath); } + /* File Path Root */ - bot.filePathRoot botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; + let botId = botConfig.devTeam + "." + botConfig.codeName + "." + botConfig.process; -} + if (FULL_LOG === true) { logger.write("[INFO] run -> listItem.process = " + listItem.process); } + /* Now we loop throug all the configured processes at each bots configuration until we find the one we are supposed to run at this Node.js process. */ -/* Now we will see which are the script Arguments. We expect the name of the process to run, since that is what it should be defined at the Task Scheduller. */ + let processFound = false; -let processToRun = process.argv[2]; + for (let i = 0; i < botConfig.processes.length; i++) { -for (let i = 0; i < botConfig.processes.length; i++) { + if (botConfig.processes[i].name === listItem.process) { - if (botConfig.processes[i].name === processToRun) { + processFound = true; + if (FULL_LOG === true) { logger.write("[INFO] run -> Process found at the bot configuration file. -> listItem.process = " + listItem.process); } - let processConfig = botConfig.processes[i]; + let processConfig = botConfig.processes[i]; - botConfig.process = processConfig.name; + try { - try { + /* We tesst each type of start Mode to get what to run and how. */ - /* We tesst each type of start Mode to get what to run and how. */ + if (processConfig.startMode.allMonths.run === "true") { - if (processConfig.startMode.allMonths.run === "true") { + if (FULL_LOG === true) { logger.write("[INFO] run -> allMonths start mode detected. "); } - for (let year = processConfig.startMode.allMonths.maxYear; year > processConfig.startMode.allMonths.minYear; year--) { + for (let year = processConfig.startMode.allMonths.maxYear; year > processConfig.startMode.allMonths.minYear; year--) { - for (let month = 12; month > 0; month--) { + for (let month = 12; month > 0; month--) { - let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine. - setTimeout(startProcess, timeDelay); + let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine. + setTimeout(startProcess, timeDelay); - function startProcess() { + function startProcess() { - const newIntervalExecutor = INTERVAL_EXECUTOR_MODULE.newIntervalExecutor(bot); + if (FULL_LOG === true) { logger.write("[INFO] run -> startProcess -> Ready to start process."); } - newIntervalExecutor.initialize(global.PLATFORM_CONFIG.bot.path, processConfig, year, month, onInitializeReady); - - function onInitializeReady() { - - newIntervalExecutor.start(); + switch (botConfig.type) { + case 'Extraction': { + runExtractionBot(processConfig, month, year); + break; + } + case 'Indicator': { + runIndicatorBot(processConfig, month, year); + break; + } + default: { + logger.write("[ERROR] run -> Unexpected bot type. -> botConfig.type = " + botConfig.type); + } + } } } } } - } + if (processConfig.startMode.oneMonth.run === "true") { - if (processConfig.startMode.oneMonth.run === "true") { + if (FULL_LOG === true) { logger.write("[INFO] run -> oneMonth start mode detected. "); } - startProcess(); + startProcess(); - function startProcess() { + function startProcess() { - const newIntervalExecutor = INTERVAL_EXECUTOR_MODULE.newIntervalExecutor(bot); + if (FULL_LOG === true) { logger.write("[INFO] run -> startProcess -> Ready to start process."); } - newIntervalExecutor.initialize(global.PLATFORM_CONFIG.bot.path, processConfig, processConfig.startMode.oneMonth.year, processConfig.startMode.oneMonth.month, onInitializeReady); + let month = pad(processConfig.startMode.oneMonth.month, 2); + let year = processConfig.startMode.oneMonth.year; - function onInitializeReady() { - newIntervalExecutor.start(); - } - } - } - - - if (processConfig.startMode.noTime.run === "true") { - - - let month = pad((new Date()).getUTCMonth() + 1, 2); - let year = (new Date()).getUTCFullYear(); - - switch (botConfig.type) { - case 'Extraction': { - runExtractionBot(processConfig, month, year); - return; - } - case 'Indicator': { - runIndicatorBot(processConfig, month, year); - return; - } - case 'Trading': { - runTradingBot(processConfig); - return; + switch (botConfig.type) { + case 'Extraction': { + runExtractionBot(processConfig, month, year); + break; + } + case 'Indicator': { + runIndicatorBot(processConfig, month, year); + break; + } + default: { + logger.write("[ERROR] run -> Unexpected bot type. -> botConfig.type = " + botConfig.type); + } + } } } - } + if (processConfig.startMode.noTime.run === "true") { - } catch (err) { - console.log(err.message); - logger.write(err.message); + let month = pad((new Date()).getUTCMonth() + 1, 2); + let year = (new Date()).getUTCFullYear(); + + switch (botConfig.type) { + case 'Extraction': { + runExtractionBot(processConfig, month, year); + break; + } + case 'Indicator': { + runIndicatorBot(processConfig, month, year); + break; + } + case 'Trading': { + runTradingBot(processConfig); + break; + } + } + } + + } catch (err) { + logger.write("[ERROR] run -> Unexpected exception. -> err.message = " + err.message); + } + } + } + + if (processFound === false) { + + logger.write("[ERROR] run -> Process listed at the configuration file of AACloud not found at the configuration file of the bot. -> listItem.process = " + listItem.process); + } + + function runExtractionBot(pProcessConfig, pMonth, pYear) { + + try { + if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> pMonth = " + pMonth); } + if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> pYear = " + pYear); } + + let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotMainLoop(botConfig); + extractionBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady); + + function onInitializeReady(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes); + + function whenRunFinishes(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + logger.write("[INFO] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); + logger.write("[INFO] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(botId + " Bot execution finished sucessfully. :-)"); + + } else { + + logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); + logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); + logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); + logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(botId + " Bot execution finished with errors. Please check the logs. :-("); + } + } + + } else { + logger.write("[ERROR] runExtractionBot -> onInitializeReady -> err = " + err.message); + logger.write("[ERROR] runExtractionBot -> onInitializeReady -> Bot will not be started. "); + } + } + } + catch (err) { + logger.write("[ERROR] runExtractionBot -> err = " + err.message); + } + } + + function runIndicatorBot(pProcessConfig, pMonth, pYear) { + + try { + if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> pMonth = " + pMonth); } + if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> pYear = " + pYear); } + + let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotMainLoop(botConfig); + indicatorBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady); + + function onInitializeReady(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes); + + function whenRunFinishes(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + logger.write("[INFO] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); + logger.write("[INFO] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(botId + " Bot execution finished sucessfully. :-)"); + + } else { + + logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); + logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); + logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); + logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(botId + " Bot execution finished with errors. Please check the logs. :-("); + } + } + + } else { + logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> err = " + err.message); + logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> Bot will not be started. "); + } + } + } + catch (err) { + logger.write("[ERROR] runIndicatorBot -> err = " + err.message); + } + } + + function runTradingBot(pProcessConfig) { + + try { + if (FULL_LOG === true) { logger.write("[INFO] runTradingBot -> Entering function."); } + + let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotMainLoop(botConfig); + tradingBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady); + + function onInitializeReady(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + tradingBotMainLoop.run(whenRunFinishes); + + function whenRunFinishes(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + logger.write("[INFO] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); + logger.write("[INFO] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(botId + " Bot execution finished sucessfully. :-)"); + + } else { + + logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); + logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); + logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); + logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(botId + " Bot execution finished with errors. Please check the logs. :-("); + } + } + + } else { + logger.write("[ERROR] runTradingBot -> onInitializeReady -> err = " + err.message); + logger.write("[ERROR] runTradingBot -> onInitializeReady -> Bot will not be started. "); + } + } + } + catch (err) { + logger.write("[ERROR] runTradingBot -> err = " + err.message); } } } -function runExtractionBot(pProcessConfig, pMonth, pYear) { - try { - if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> Entering function."); } - let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotMainLoop(botConfig); - extractionBotMainLoop.initialize(global.PLATFORM_CONFIG.bot.path, pProcessConfig, onInitializeReady); - function onInitializeReady(err) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes); - function whenRunFinishes(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - logger.write("[INFO] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); - console.log("Bot execution finished sucessfully. :-)"); - - } else { - - logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); - logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); - logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); - } - } - - } else { - logger.write("[ERROR] runExtractionBot -> onInitializeReady -> err = " + err.message); - logger.write("[ERROR] runExtractionBot -> onInitializeReady -> Bot will not be started. "); - } - } - } - catch (err) { - logger.write("[ERROR] runExtractionBot -> err = " + err.message); - } -} - -function runIndicatorBot(pProcessConfig, pMonth, pYear) { - - try { - if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> Entering function."); } - - let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotMainLoop(botConfig); - indicatorBotMainLoop.initialize(global.PLATFORM_CONFIG.bot.path, pProcessConfig, onInitializeReady); - - function onInitializeReady(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes); - - function whenRunFinishes(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - logger.write("[INFO] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); - console.log("Bot execution finished sucessfully. :-)"); - - } else { - - logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); - logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); - logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); - } - } - - } else { - logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> err = " + err.message); - logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> Bot will not be started. "); - } - } - } - catch (err) { - logger.write("[ERROR] runIndicatorBot -> err = " + err.message); - } -} - -function runTradingBot(pProcessConfig) { - - try { - if (FULL_LOG === true) { logger.write("[INFO] runTradingBot -> Entering function."); } - - let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotMainLoop(botConfig); - tradingBotMainLoop.initialize(global.PLATFORM_CONFIG.bot.path, pProcessConfig, onInitializeReady); - - function onInitializeReady(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - tradingBotMainLoop.run(whenRunFinishes); - - function whenRunFinishes(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - logger.write("[INFO] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); - console.log("Bot execution finished sucessfully. :-)"); - - } else { - - logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); - logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); - logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bye. :-("); - } - } - - } else { - logger.write("[ERROR] runTradingBot -> onInitializeReady -> err = " + err.message); - logger.write("[ERROR] runTradingBot -> onInitializeReady -> Bot will not be started. "); - } - } - } - catch (err) { - logger.write("[ERROR] runTradingBot -> err = " + err.message); - } -} \ No newline at end of file diff --git a/Status Report.js b/Status Report.js index 19a764726..9227fdf39 100644 --- a/Status Report.js +++ b/Status Report.js @@ -103,7 +103,10 @@ function onFileReceived(err, text) { - if (err.result === global.CUSTOM_FAIL_RESPONSE.result && err.message === 'Folder does not exist.') { + if ( + err.result === global.CUSTOM_FAIL_RESPONSE.result && + (err.message === 'Folder does not exist.' || err.message === 'File does not exist.') + ) { logger.write("[INFO] initialize -> load -> onFileReceived -> err = " + err.message); /* In this case we can assume that this is the first execution ever of this bot.*/ diff --git a/Trading Bot Main Loop.js b/Trading Bot Main Loop.js index 2781dda7a..acb803908 100644 --- a/Trading Bot Main Loop.js +++ b/Trading Bot Main Loop.js @@ -13,6 +13,7 @@ const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = bot; + logger.forceLoopSplit = true; let thisObject = { initialize: initialize, @@ -55,7 +56,7 @@ function loop() { try { - global.loopCointer++; + bot.loopCounter++; if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> Entering function."); } @@ -84,6 +85,7 @@ let exchangeAPI; let assistant; let userBot; + let dependencies; let nextWaitTime; diff --git a/this.config.json b/this.config.json index b347619d5..7ecbde81a 100644 --- a/this.config.json +++ b/this.config.json @@ -5,17 +5,18 @@ "minor": 1, "patch": 0 }, - "bot": { - "path": "../Bots/AAMasters/AAMariam-Trading-Bot" - }, "executionList": [ { "botPath": "../Bots/AAMasters/AAMariam-Trading-Bot", "process": "Trading-Process" + }, + { + "botPath": "../Bots/AAMasters/AAOlivia-Indicator-Bot", + "process": "Multi-Period-Market" } ], - "stopGracefully": "false", + "stopGracefully": "true", "exchangeSimulationMode": "false", - "storageConnStringFolder": "Production", + "storageConnStringFolder": "Mixed", "maxLogLoops": 10 } \ No newline at end of file