From 21192c971c0ff76c67670c19a62e186f263e1712 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Dec 2019 17:30:32 +0100 Subject: [PATCH 01/36] Announcements via Reference Parent --- Session.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Session.js b/Session.js index 23aeb4fe3..17788d20b 100644 --- a/Session.js +++ b/Session.js @@ -485,10 +485,7 @@ let socialBot = bot.SESSION.socialBots.bots[i] try { let code = JSON.parse(announcement.code) - if (code.botId === undefined) { - code.botId = socialBot.id - } - if (socialBot.type === code.botType && socialBot.id === code.botId) { + if (socialBot.id === announcement.referenceParent.id) { if (socialBot.type === "Telegram Bot") { if (announcement.formulaValue !== undefined) { socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, announcement.formulaValue).catch(err => parentLogger.write(MODULE_NAME, "[WARN] initialize -> setUpSocialBots -> announce -> Telegram API error -> err = " + err)) From 56e750b39f7575d5c19608b033c62ccb98b8a37f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Dec 2019 10:45:35 +0100 Subject: [PATCH 02/36] Data Mine Refactoring --- Assistant.js | 2 +- Commons.js | 8 ++++---- Context.js | 12 ++++++------ DataDependencies.js | 2 +- DataSet.js | 18 ++++++++--------- DebugLog.js | 10 +++++----- IndicatorBot.js | 2 +- IndicatorBotProcessMainLoop.js | 8 ++++---- Integrations/Ecosystem.js | 2 +- MultiPeriod.js | 10 +++++----- MultiPeriodDaily.js | 6 +++--- MultiPeriodMarket.js | 4 ++-- ProcessExecutionEvents.js | 2 +- ProcessOutput.js | 8 ++++---- Root.js | 16 +++++++-------- SensorBotProcessMainLoop.js | 8 ++++---- StatusDependencies.js | 4 ++-- StatusReport.js | 20 +++++++++---------- TradingBot.js | 36 +++++++++++++++++----------------- TradingBotProcessMainLoop.js | 8 ++++---- server.js | 4 ++-- 21 files changed, 95 insertions(+), 95 deletions(-) diff --git a/Assistant.js b/Assistant.js index 293a657fd..adf3bc209 100644 --- a/Assistant.js +++ b/Assistant.js @@ -133,7 +133,7 @@ /* Procedure to get the current market rate. */ let key = - bot.marketRateProvider.devTeam + "-" + + bot.marketRateProvider.dataMine + "-" + bot.marketRateProvider.bot + "-" + bot.marketRateProvider.product + "-" + bot.marketRateProvider.dataSet + "-" + diff --git a/Commons.js b/Commons.js index 63ed77f00..7b0a55340 100644 --- a/Commons.js +++ b/Commons.js @@ -104,13 +104,13 @@ } if (outputDatasetNode.referenceParent.parentNode.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Team. Bot = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } if (outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.code.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start -> Team witn no codeName defined. Team = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] start -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -476,11 +476,11 @@ dateForPath = "/" + currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); } - let filePathRoot = contextSummary.devTeam + "/" + contextSummary.bot + "." + contextSummary.botVersion.major + "." + contextSummary.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + contextSummary.dataSetVersion; + let filePathRoot = contextSummary.dataMine + "/" + contextSummary.bot + "." + contextSummary.botVersion.major + "." + contextSummary.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + contextSummary.dataSetVersion; let filePath = filePathRoot + "/Output/" + contextSummary.product + "/" + contextSummary.dataset + "/" + timePeriodLabel + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(contextSummary.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(contextSummary.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/Context.js b/Context.js index 5395ac2ca..caf859a1c 100644 --- a/Context.js +++ b/Context.js @@ -134,7 +134,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getStatusReport -> Entering function."); } - let key = bot.devTeam + "-" + bot.codeName + "-" + "Context" + "-" + bot.dataSetVersion; + let key = bot.dataMine + "-" + bot.codeName + "-" + "Context" + "-" + bot.dataSetVersion; statusReportModule = statusDependencies.statusReports.get(key); thisObject.statusReport = statusReportModule.file; @@ -168,7 +168,7 @@ let fileName = "Execution.History." + bot.startMode + "." + runIndex + ".json"; let filePath = bot.filePathRoot + "/Output/" + sessionPath + "Trading-Process/" + fileName; - fileStorage.getTextFile(bot.devTeam, filePath, onFileReceived); + fileStorage.getTextFile(bot.dataMine, filePath, onFileReceived); function onFileReceived(err, text) { @@ -229,7 +229,7 @@ let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); let filePath = bot.filePathRoot + "/Output/" + sessionPath + "Trading-Process/" + dateForPath + fileName; - fileStorage.getTextFile(bot.devTeam, filePath, onFileReceived); + fileStorage.getTextFile(bot.dataMine, filePath, onFileReceived); function onFileReceived(err, text) { @@ -411,7 +411,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { logger.write(MODULE_NAME, "[INFO] saveThemAll -> writeExecutionContext -> fileContent = " + fileContent); } - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -472,7 +472,7 @@ let fileContent = JSON.stringify(thisObject.executionHistory); - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -494,7 +494,7 @@ fileName = "Execution.History." + bot.startMode + "." + "Sequence" + ".json"; filePath = bot.filePathRoot + "/Output/" + sessionPath + "Trading-Process/" + fileName; - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onSequenceFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onSequenceFileCreated); function onSequenceFileCreated(err) { diff --git a/DataDependencies.js b/DataDependencies.js index ec7bbbb95..084d4704e 100644 --- a/DataDependencies.js +++ b/DataDependencies.js @@ -79,7 +79,7 @@ let key; - key = thisObject.nodeArray[i].devTeam + "-" + thisObject.nodeArray[i].bot + "-" + thisObject.nodeArray[i].product + "-" + thisObject.nodeArray[i].dataSet + "-" + thisObject.nodeArray[i].dataSetVersion; + key = thisObject.nodeArray[i].dataMine + "-" + thisObject.nodeArray[i].bot + "-" + thisObject.nodeArray[i].product + "-" + thisObject.nodeArray[i].dataSet + "-" + thisObject.nodeArray[i].dataSetVersion; thisObject.keys.push(key); thisObject.dataSets.set(key, dataSetModule); diff --git a/DataSet.js b/DataSet.js index 4d6a72bc4..f4ed6b59e 100644 --- a/DataSet.js +++ b/DataSet.js @@ -66,13 +66,13 @@ exports.newDataSet = function newDataSet(BOT, logger) { } if (dataDependencyNode.referenceParent.parentNode.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Bot not attached to a Team. Bot = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] initialize -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } if (dataDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Team witn no codeName defined. Team = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] initialize -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(dataDependencyNode.referenceParent.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -81,7 +81,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { dataDependencyNode.dataSet = dataDependencyNode.referenceParent.code.codeName dataDependencyNode.product = dataDependencyNode.referenceParent.parentNode.code.codeName dataDependencyNode.bot = dataDependencyNode.referenceParent.parentNode.parentNode.code.codeName - dataDependencyNode.devTeam = dataDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName + dataDependencyNode.dataMine = dataDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName /* This stuff is still hardcoded and unresolved. */ dataDependencyNode.botVersion = { @@ -104,11 +104,11 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTextFile -> Entering function."); } - let filePathRoot = dataDependencyNode.devTeam + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + dataDependencyNode.dataSetVersion; + let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + dataDependencyNode.dataSetVersion; let filePath = filePathRoot + "/Output/" + pFolderPath; filePath += '/' + pFileName - fileStorage.getTextFile(dataDependencyNode.devTeam, filePath, onFileReceived); + fileStorage.getTextFile(dataDependencyNode.dataMine, filePath, onFileReceived); function onFileReceived(err, text) { @@ -132,8 +132,8 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createTextFile -> pFolderPath = " + pFolderPath); } if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createTextFile -> pFileName = " + pFileName); } - let ownerId = dataDependencyNode.devTeam + "-" + dataDependencyNode.bot + "-" + dataDependencyNode.botVersion.major + "-" + dataDependencyNode.botVersion.minor + "-" + dataDependencyNode.dataSetVersion; - let botId = bot.devTeam + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.dataSetVersion; + let ownerId = dataDependencyNode.dataMine + "-" + dataDependencyNode.bot + "-" + dataDependencyNode.botVersion.major + "-" + dataDependencyNode.botVersion.minor + "-" + dataDependencyNode.dataSetVersion; + let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.dataSetVersion; if (ownerId !== botId) { @@ -146,10 +146,10 @@ exports.newDataSet = function newDataSet(BOT, logger) { return; } - let filePathRoot = dataDependencyNode.devTeam + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + dataDependencyNode.dataSetVersion; + let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + dataDependencyNode.dataSetVersion; let filePath = filePathRoot + "/Output/" + pFolderPath + '/' + pFileName; - fileStorage.createTextFile(dataDependencyNode.devTeam, filePath, pFileContent, onFileCreated); + fileStorage.createTextFile(dataDependencyNode.dataMine, filePath, pFileContent, onFileCreated); function onFileCreated(err) { diff --git a/DebugLog.js b/DebugLog.js index 6374eb201..22be40b3a 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -92,22 +92,22 @@ exports.newDebugLog = function newDebugLog() { let fileToDelete = thisObject.bot.LOGS_TO_DELETE_QUEUE[0] thisObject.bot.LOGS_TO_DELETE_QUEUE.splice(0, 1) /* Will delete this file only if it does not contains ERROR inside. */ - let fileContent = fileStorage.getTextFile(thisObject.bot.devTeam, fileToDelete, onGetFile, true) + let fileContent = fileStorage.getTextFile(thisObject.bot.dataMine, fileToDelete, onGetFile, true) function onGetFile(err, fileContent) { if (err.result === global.DEFAULT_OK_RESPONSE.result) { if (fileContent.indexOf("ERROR") < 0) { /* Logs will only be deleted when they contain no ERROR in them. */ - fileStorage.deleteTextFile(thisObject.bot.devTeam, fileToDelete); + fileStorage.deleteTextFile(thisObject.bot.dataMine, fileToDelete); } } else { - fileStorage.deleteTextFile(thisObject.bot.devTeam, fileToDelete); + fileStorage.deleteTextFile(thisObject.bot.dataMine, fileToDelete); } } } function writeLog() { - fileStorage.createTextFile(thisObject.bot.devTeam, filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); + fileStorage.createTextFile(thisObject.bot.dataMine, filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); function onFileCreated(err) { if (err.result !== global.DEFAULT_OK_RESPONSE.result) { console.log("[ERROR] DebugLog -> persist -> onInizialized -> onFileCreated -> err = "+ err.message); @@ -149,7 +149,7 @@ exports.newDebugLog = function newDebugLog() { if (process.env.CONSOLE_LOG === "true" || message.indexOf("ERROR") > 0) { let key = '' if (thisObject.bot) { - key = thisObject.bot.devTeam + '-' + thisObject.bot.codeName + '-' + thisObject.bot.process + key = thisObject.bot.dataMine + '-' + thisObject.bot.codeName + '-' + thisObject.bot.process } console.log('*********** ' + message + ' @ ' + key) } diff --git a/IndicatorBot.js b/IndicatorBot.js index e1c5b59e7..30f834dee 100644 --- a/IndicatorBot.js +++ b/IndicatorBot.js @@ -139,7 +139,7 @@ contextSummary.dataset = outputDatasetNode.referenceParent.code.codeName contextSummary.product = outputDatasetNode.referenceParent.parentNode.code.codeName contextSummary.bot = outputDatasetNode.referenceParent.parentNode.parentNode.code.codeName - contextSummary.devTeam = outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.code.codeName + contextSummary.dataMine = outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.code.codeName /* This stuff is still hardcoded and unresolved. */ contextSummary.botVersion = { diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index e29c7ac60..39e613201 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -43,10 +43,10 @@ /* This bot is not ready for taking its code from the UI, then we need to load it from its repo. */ - let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName + let filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" - fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.dataMine, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -61,10 +61,10 @@ USER_BOT_MODULE = {} USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function - filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; + filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.dataMine, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { diff --git a/Integrations/Ecosystem.js b/Integrations/Ecosystem.js index fcf1fd364..6c76069fe 100644 --- a/Integrations/Ecosystem.js +++ b/Integrations/Ecosystem.js @@ -21,7 +21,7 @@ exports.getEcosystem = async function () { query { web_GetEcosystem { id - devTeams { + dataMines { codeName displayName host { diff --git a/MultiPeriod.js b/MultiPeriod.js index 37ca1fff8..af432f083 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -48,7 +48,7 @@ let dataset; let dependency = dataDependencies.nodeArray[i]; - key = dependency.devTeam + "-" + + key = dependency.dataMine + "-" + dependency.bot + "-" + dependency.product + "-" + dependency.dataSet + "-" + @@ -995,7 +995,7 @@ let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + productCodeName + "/" + 'Multi-Period-Daily' + fileName; - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -1011,7 +1011,7 @@ logger.write(MODULE_NAME, "[INFO] start -> writeDataRange -> onFileCreated -> Content written = " + fileContent); } - let key = bot.devTeam + "-" + bot.codeName + "-" + productCodeName + "-" + currentOutputPeriodName + let key = bot.dataMine + "-" + bot.codeName + "-" + productCodeName + "-" + currentOutputPeriodName let event = { dateRange: dataRange } @@ -1034,7 +1034,7 @@ try { - let reportKey = bot.devTeam + "-" + bot.codeName + "-" + "Multi-Period" + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period" + "-" + "dataSet.V1"; let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.currentDaytime; @@ -1057,7 +1057,7 @@ try { - let reportKey = bot.devTeam + "-" + bot.codeName + "-" + "Multi-Period" + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period" + "-" + "dataSet.V1"; let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime; diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 30a89adb0..bd323dc57 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -48,7 +48,7 @@ let dataset; let dependency = dataDependencies.nodeArray[i]; - key = dependency.devTeam + "-" + + key = dependency.dataMine + "-" + dependency.bot + "-" + dependency.product + "-" + dependency.dataSet + "-" + @@ -729,7 +729,7 @@ let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; let filePath = bot.filePathRoot + "/Output/" + productCodeName + "/" + bot.process + fileName; - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -761,7 +761,7 @@ try { - let reportKey = bot.devTeam + "-" + bot.codeName + "-" + "Multi-Period-Daily" + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period-Daily" + "-" + "dataSet.V1"; let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.currentDaytime; diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 4ee15f3e8..efc98ddb3 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -42,7 +42,7 @@ let dataset; let dependency = dataDependencies.nodeArray[i]; - key = dependency.devTeam + "-" + + key = dependency.dataMine + "-" + dependency.bot + "-" + dependency.product + "-" + dependency.dataSet + "-" + @@ -332,7 +332,7 @@ try { - let reportKey = bot.devTeam + "-" + bot.codeName + "-" + "Multi-Period-Market" + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period-Market" + "-" + "dataSet.V1"; let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime; diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index fd04c2efc..64f45bda4 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -83,7 +83,7 @@ if (year) { extraCallerId = extraCallerId + '-' + year } let key = processThisDependsOn.name + "-" + processThisDependsOn.type + "-" + processThisDependsOn.id - let callerId = bot.devTeam + "-" + bot.codeName + "-" + bot.process + extraCallerId + let callerId = bot.dataMine + "-" + bot.codeName + "-" + bot.process + extraCallerId let subscriptionId diff --git a/ProcessOutput.js b/ProcessOutput.js index ef74e7305..6a07bbc34 100644 --- a/ProcessOutput.js +++ b/ProcessOutput.js @@ -49,12 +49,12 @@ } if (outputDataset.referenceParent.parentNode.parentNode.parentNode !== undefined) { if (outputDataset.referenceParent.parentNode.parentNode.parentNode.code.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Team not defined. Team = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> codeName at Data Mine not defined. Data Mine = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } } else { - logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Team. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(outputDataset.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -76,14 +76,14 @@ /* All good, lets emit the event. */ - let devTeam = outputDataset.referenceParent.parentNode.parentNode.parentNode.code.codeName + let dataMine = outputDataset.referenceParent.parentNode.parentNode.parentNode.code.codeName let botName = outputDataset.referenceParent.parentNode.parentNode.code.codeName let product = outputDataset.referenceParent.parentNode.code.codeName let dataset = outputDataset.referenceParent.code.codeName let statusReport = statusDependencies.reportsByMainUtility.get("Self Reference") - key = devTeam + "-" + botName + "-" + product + "-" + dataset + key = dataMine + "-" + botName + "-" + product + "-" + dataset let event = { lastFile: statusReport.file.lastFile } diff --git a/Root.js b/Root.js index 72781d834..e008574e0 100644 --- a/Root.js +++ b/Root.js @@ -173,7 +173,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> err = " + JSON.stringify(err)); console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> filePath = " + filePath); - console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> team = " + global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName); + console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> dataMine = " + global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName); return; } @@ -207,7 +207,7 @@ botConfig.DELETE_QUEUE_SIZE = 10 // This number represents how many log files can be at the queue at any point in time, which means how many logs are not still deleted. /* Simplifying the access to basic info */ - botConfig.devTeam = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName + botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName /* This stuff is still hardcoded and unresolved. */ botConfig.version = { @@ -220,7 +220,7 @@ botConfig.loopCounter = 0; /* File Path Root */ - botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; + botConfig.filePathRoot = botConfig.dataMine + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; /* Process Key */ botConfig.processKey = global.TASK_NODE.bot.processes[processIndex].name + '-' + global.TASK_NODE.bot.processes[processIndex].type + '-' + global.TASK_NODE.bot.processes[processIndex].id @@ -459,9 +459,9 @@ let botId; if (pYear !== undefined) { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; + botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; } else { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; } if (err.result === global.DEFAULT_OK_RESPONSE.result) { @@ -533,9 +533,9 @@ let botId; if (pYear !== undefined) { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; + botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; } else { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; } if (err.result === global.DEFAULT_OK_RESPONSE.result) { @@ -602,7 +602,7 @@ let botId; - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; if (err.result === global.DEFAULT_OK_RESPONSE.result) { diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 21c1c8fab..4adb52bd2 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -41,10 +41,10 @@ return } - let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName + let filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" - fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.dataMine, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -61,10 +61,10 @@ } USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function - filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; + filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.dataMine, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { diff --git a/StatusDependencies.js b/StatusDependencies.js index 542e25eec..65a888955 100644 --- a/StatusDependencies.js +++ b/StatusDependencies.js @@ -155,9 +155,9 @@ let key; if (statusDependency.dependency.processRunMonthly === true && statusDependency.month !== undefined && statusDependency.year !== undefined) { - key = statusDependency.dependency.devTeam + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion + "-" + statusDependency.year + "-" + statusDependency.month; + key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion + "-" + statusDependency.year + "-" + statusDependency.month; } else { - key = statusDependency.dependency.devTeam + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion; + key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion; } thisObject.keys.push(key); diff --git a/StatusReport.js b/StatusReport.js index 76e30eace..12c63ac16 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -83,13 +83,13 @@ } if (statusDependencyNode.referenceParent.parentNode.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Bot not attached to a Team. Bot = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] initialize -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } if (statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Team witn no codeName defined. Team = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode.parentNode)); + logger.write(MODULE_NAME, "[ERROR] initialize -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode.parentNode)); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -98,7 +98,7 @@ statusDependencyNode.bot = statusDependencyNode.referenceParent.parentNode.parentNode.code.codeName statusDependencyNode.process = statusDependencyNode.referenceParent.parentNode.code.codeName statusDependencyNode.bottype = statusDependencyNode.referenceParent.parentNode.parentNode.type - statusDependencyNode.devTeam = statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName + statusDependencyNode.dataMine = statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.code.codeName /* Let's see if the process is run monthly or not. */ if (statusDependencyNode.referenceParent.parentNode.code.startMode !== undefined) { @@ -151,11 +151,11 @@ let fileName = "Status.Report." + global.MARKET.assetA + '_' + global.MARKET.assetB + ".json"; let filePath; - let ownerId = statusDependencyNode.devTeam + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; - let botId = bot.devTeam + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; + let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; + let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; if (ownerId !== botId) { - let rootPath = statusDependencyNode.devTeam + "/" + statusDependencyNode.bot + "." + statusDependencyNode.botVersion.major + "." + statusDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + statusDependencyNode.dataSetVersion; + let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "." + statusDependencyNode.botVersion.major + "." + statusDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + statusDependencyNode.dataSetVersion; filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; } else { filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; @@ -163,7 +163,7 @@ filePath += '/' + fileName - fileStorage.getTextFile(statusDependencyNode.devTeam, filePath, onFileReceived); + fileStorage.getTextFile(statusDependencyNode.dataMine, filePath, onFileReceived); function onFileReceived(err, text) { @@ -231,8 +231,8 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] save -> Entering function."); } - let ownerId = statusDependencyNode.devTeam + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; - let botId = bot.devTeam + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; + let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; + let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; if (ownerId !== botId && statusDependencyNode.process !== "Context") { // Context is a special case where the report is created by the Context.js module itself. @@ -251,7 +251,7 @@ filePath += '/' + fileName let fileContent = JSON.stringify(thisObject.file); - fileStorage.createTextFile(statusDependencyNode.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(statusDependencyNode.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/TradingBot.js b/TradingBot.js index c04bad9d1..d8cf1766c 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -221,11 +221,11 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -299,11 +299,11 @@ fileContent = "[" + JSON.stringify(tradingSystem) + "," + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -369,11 +369,11 @@ fileContent = "[" + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -442,11 +442,11 @@ fileContent = "[" + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -568,11 +568,11 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -675,11 +675,11 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -763,11 +763,11 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -840,11 +840,11 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -920,11 +920,11 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index c4230dbde..9bf8b9926 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -53,10 +53,10 @@ bot.resumeExecution = processConfig.framework.startDate.resumeExecution // We are inherating this from root, but from here we need it at bot - let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName + let filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" - fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.dataMine, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -72,10 +72,10 @@ //USER_BOT_MODULE.newUserBot = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AAJason-Trading-Engine-Bot/Multi-Period/User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. USER_BOT_MODULE.newUserBot = eval(text); // Use this for production - filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; + filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.dataMine, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { diff --git a/server.js b/server.js index c5be5c422..2f7e669ff 100644 --- a/server.js +++ b/server.js @@ -187,7 +187,7 @@ function bootLoader() { } if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Bot Definition without parent Team. -> Bot Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode)); + console.log("[WARN] Task Server -> server -> bootLoader -> Bot Definition without parent Data Mine. -> Bot Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode)); continue } @@ -202,7 +202,7 @@ function bootLoader() { } if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Team without a codeName defined. -> Team Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode)); + console.log("[WARN] Task Server -> server -> bootLoader -> Data Mine without a codeName defined. -> Data Mine Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode)); continue } From a7de3ee5daad606d039ddd5b7d1b1bfd381fe304 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Dec 2019 13:26:35 +0100 Subject: [PATCH 03/36] Time Frame Refectoring --- Commons.js | 18 ++-- IndicatorBot.js | 12 +-- MultiPeriod.js | 192 +++++++++++++++++++++---------------------- MultiPeriodDaily.js | 110 ++++++++++++------------- MultiPeriodMarket.js | 62 +++++++------- Root.js | 2 +- Session.js | 14 ++-- TradingBot.js | 46 +++++------ TradingSimulation.js | 16 ++-- 9 files changed, 236 insertions(+), 236 deletions(-) diff --git a/Commons.js b/Commons.js index 7b0a55340..5a74a6fd9 100644 --- a/Commons.js +++ b/Commons.js @@ -118,7 +118,7 @@ return true } - function inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timePeriod) { + function inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timeFrame) { /* For each dataDependencyNode in our data dependencies, we should have a dataFile containing the records needed as an imput for this process. What we need to do first is transform those records into JSON objects that can be used by user-defined formulas. @@ -143,7 +143,7 @@ jsonData = jsonifyDataFile(dataFile, recordDefinition) /* Add the calculated properties */ if (dataDependencyNode.referenceParent.parentNode.calculations !== undefined) { - inputData = calculationsProcedure(jsonData, recordDefinition, dataDependencyNode.referenceParent.parentNode.calculations, singularVariableName, timePeriod) + inputData = calculationsProcedure(jsonData, recordDefinition, dataDependencyNode.referenceParent.parentNode.calculations, singularVariableName, timeFrame) } else { inputData = jsonData } @@ -184,7 +184,7 @@ return jsonifiedArray } - function calculationsProcedure(jsonArray, recordDefinition, calculationsProcedure, variableName, timePeriod) { + function calculationsProcedure(jsonArray, recordDefinition, calculationsProcedure, variableName, timeFrame) { /* This function has as an input an array of JSON objects, and it adds calculated properties to @@ -192,7 +192,7 @@ */ let system = { // These are the available system variables to be used in User Code and Formulas - timePeriod: timePeriod, + timeFrame: timeFrame, ONE_DAY_IN_MILISECONDS: ONE_DAY_IN_MILISECONDS } let variable = {} // This is the structure where the user will define its own variables that will be shared across different code blocks and formulas. @@ -265,8 +265,8 @@ dataBuildingProcedure, variableName, productName, - timePeriod, - timePeriodLabel, + timeFrame, + timeFrameLabel, resultsWithIrregularPeriods, interExecutionMemory, processingDailyFiles, @@ -283,7 +283,7 @@ let lastInstantOfTheDay let yesterday = {} let system = { // These are the available system variables to be used in User Code and Formulas - timePeriod: timePeriod, + timeFrame: timeFrame, ONE_DAY_IN_MILISECONDS: ONE_DAY_IN_MILISECONDS } let variable = {} // This is the structure where the user will define its own variables that will be shared across different code blocks and formulas. @@ -462,7 +462,7 @@ } } - function writeFile(contextSummary, fileContent, anotherFileWritten, processingDailyFiles, timePeriodLabel, currentDay, callBackFunction) { + function writeFile(contextSummary, fileContent, anotherFileWritten, processingDailyFiles, timeFrameLabel, currentDay, callBackFunction) { try { @@ -477,7 +477,7 @@ } let filePathRoot = contextSummary.dataMine + "/" + contextSummary.bot + "." + contextSummary.botVersion.major + "." + contextSummary.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + contextSummary.dataSetVersion; - let filePath = filePathRoot + "/Output/" + contextSummary.product + "/" + contextSummary.dataset + "/" + timePeriodLabel + dateForPath; + let filePath = filePathRoot + "/Output/" + contextSummary.product + "/" + contextSummary.dataset + "/" + timeFrameLabel + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(contextSummary.dataMine, filePath, fileContent + '\n', onFileCreated); diff --git a/IndicatorBot.js b/IndicatorBot.js index 30f834dee..004ed077f 100644 --- a/IndicatorBot.js +++ b/IndicatorBot.js @@ -44,7 +44,7 @@ } } - function start(dataFiles, timePeriod, timePeriodLabel, currentDay, interExecutionMemory, callBackFunction) { + function start(dataFiles, timeFrame, timeFrameLabel, currentDay, interExecutionMemory, callBackFunction) { try { @@ -68,7 +68,7 @@ if (commons.validateOutputDatasets(outputDatasets, callBackFunction) !== true) { return } /* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */ - commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timePeriod) + commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timeFrame) /* During the third phase, we need to generate the data of the different products this process produces an output */ for (let i = 0; i < outputDatasets.length; i++) { @@ -104,8 +104,8 @@ outputDatasetNode.referenceParent.parentNode.dataBuilding, singularVariableName, outputDatasetNode.referenceParent.parentNode.code.codeName, - timePeriod, - timePeriodLabel, + timeFrame, + timeFrameLabel, resultsWithIrregularPeriods, interExecutionMemory, processingDailyFiles, @@ -114,7 +114,7 @@ /* Add the calculated properties */ if (outputDatasetNode.referenceParent.parentNode.calculations !== undefined) { - outputData = commons.calculationsProcedure(jsonData, recordDefinition, outputDatasetNode.referenceParent.parentNode.calculations, singularVariableName, timePeriod) + outputData = commons.calculationsProcedure(jsonData, recordDefinition, outputDatasetNode.referenceParent.parentNode.calculations, singularVariableName, timeFrame) } else { outputData = jsonData } @@ -149,7 +149,7 @@ contextSummary.dataSetVersion = "dataSet.V1" let fileContent = commons.generateFileContent(outputData, outputDatasetNode.referenceParent.parentNode.record, resultsWithIrregularPeriods, processingDailyFiles, currentDay, callBackFunction) - commons.writeFile(contextSummary, fileContent, anotherFileWritten, processingDailyFiles, timePeriodLabel, currentDay, callBackFunction) + commons.writeFile(contextSummary, fileContent, anotherFileWritten, processingDailyFiles, timeFrameLabel, currentDay, callBackFunction) } diff --git a/MultiPeriod.js b/MultiPeriod.js index af432f083..52a7b427b 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -90,7 +90,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } - let currentTimePeriod + let currentTimeFrame let currentOutputPeriodName let market = global.MARKET; @@ -199,7 +199,7 @@ contextVariables.lastFile = new Date(thisReport.lastFile); interExecutionMemoryArray = thisReport.interExecutionMemoryArray; - processTimePeriodsMarketFiles(); + processTimeFramesMarketFiles(); return; } else { @@ -220,7 +220,7 @@ /* The first time the process is running is the right time to create the data structure that is going to be shared across different executions. - This data structure has one object per each timePeriod. + This data structure has one object per each timeFrame. */ interExecutionMemoryArray = []; @@ -230,7 +230,7 @@ interExecutionMemoryArray.push(emptyObject); } - processTimePeriodsMarketFiles(); + processTimeFramesMarketFiles(); } @@ -244,9 +244,9 @@ } } - function processTimePeriodsMarketFiles() { + function processTimeFramesMarketFiles() { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> Entering function."); } try { @@ -258,7 +258,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> periodsLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoop -> Entering function."); } /* @@ -272,7 +272,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> periodsLoop -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> periodsLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -281,16 +281,16 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoopBody -> Entering function."); } - const timePeriod = global.marketFilesPeriods[n][0]; - const timePeriodLabel = global.marketFilesPeriods[n][1]; + const timeFrame = global.marketFilesPeriods[n][0]; + const timeFrameLabel = global.marketFilesPeriods[n][1]; let dependencyIndex = 0; dataFiles = new Map(); - if (bot.VALUES_TO_USE.timePeriod === timePeriodLabel) { - currentTimePeriod = global.marketFilesPeriods[n][0]; + if (bot.VALUES_TO_USE.timeFrame === timeFrameLabel) { + currentTimeFrame = global.marketFilesPeriods[n][0]; currentOutputPeriodName = global.marketFilesPeriods[n][1]; } dependencyLoopBody(); @@ -299,7 +299,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } let dependency = dataDependencies.nodeArray[dependencyIndex]; let dataset = datasets[dependencyIndex]; @@ -310,7 +310,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } let fileName = market.assetA + '_' + market.assetB + ".json"; @@ -320,7 +320,7 @@ return } - let filePath = dependency.product + '/' + dependency.dataSet + "/" + timePeriodLabel; + let filePath = dependency.product + '/' + dependency.dataSet + "/" + timeFrameLabel; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -328,12 +328,12 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> Entering function."); } - if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> text = " + text); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> text = " + text); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = " + err.message); callBackFunction(err); return; } @@ -345,20 +345,20 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> periodsLoop -> dependencyLoopBody -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> periodsLoop -> dependencyLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -367,7 +367,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> dependencyControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> dependencyControlLoop -> Entering function."); } dependencyIndex++; @@ -385,13 +385,13 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> dependencyControlLoop -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> dependencyControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> periodsLoopBody -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> periodsLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -400,7 +400,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsMarketFiles -> periodsControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsControlLoop -> Entering function."); } n++; @@ -410,32 +410,32 @@ } else { - processTimePeriodsDailyFiles(); + processTimeFramesDailyFiles(); } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> periodsControlLoop -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> periodsControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsMarketFiles -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesMarketFiles -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } - function processTimePeriodsDailyFiles() { + function processTimeFramesDailyFiles() { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> Entering function."); } try { let n = 0; - if (currentTimePeriod) { + if (currentTimeFrame) { callTheBot() return } @@ -448,7 +448,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> advanceTime -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> Entering function."); } bot.multiPeriodProcessDatetime = new Date(bot.multiPeriodProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); @@ -459,15 +459,15 @@ logger.newInternalLoop(bot.codeName, bot.process); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> advanceTime -> bot.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> advanceTime -> previousDay = " + previousDay); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> bot.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> previousDay = " + previousDay); } /* Validation that we are not going past the user defined end date. */ if (bot.multiPeriodProcessDatetime.valueOf() >= bot.VALUES_TO_USE.timeRange.finalDatetime.valueOf()) { const logText = "User Defined End Datetime reached @ " + previousDay.getUTCFullYear() + "/" + (previousDay.getUTCMonth() + 1) + "/" + previousDay.getUTCDate() + "."; - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> advanceTime -> " + logText); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> " + logText); } bot.STOP_SESSION = true callBackFunction(global.DEFAULT_OK_RESPONSE); @@ -480,7 +480,7 @@ if (bot.multiPeriodProcessDatetime.valueOf() > contextVariables.dateEndOfMarket.valueOf()) { const logText = "Head of the market found @ " + previousDay.getUTCFullYear() + "/" + (previousDay.getUTCMonth() + 1) + "/" + previousDay.getUTCDate() + "."; - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> advanceTime -> " + logText); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> " + logText); } callBackFunction(global.DEFAULT_OK_RESPONSE); return; @@ -490,7 +490,7 @@ checkStopTaskGracefully(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> advanceTime -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> advanceTime -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -499,7 +499,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> checkStopTaskGracefully -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> checkStopTaskGracefully -> Entering function."); } /* Validation that we dont need to stop. */ @@ -513,7 +513,7 @@ checkStopProcessing(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> checkStopTaskGracefully -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> checkStopTaskGracefully -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -522,7 +522,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> checkStopProcessing -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> checkStopProcessing -> Entering function."); } /* Validation that we dont need to stop. */ @@ -536,7 +536,7 @@ periodsLoop(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> checkStopProcessing -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> checkStopProcessing -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -545,7 +545,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoop -> Entering function."); } /* Telling the world we are alive and doing well */ let processingDate = bot.multiPeriodProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCDate(), 2); @@ -563,7 +563,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoop -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -572,26 +572,26 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> Entering function."); } - const timePeriod = global.dailyFilePeriods[n][0]; - const timePeriodLabel = global.dailyFilePeriods[n][1]; + const timeFrame = global.dailyFilePeriods[n][0]; + const timeFrameLabel = global.dailyFilePeriods[n][1]; if (processConfig.framework.validPeriods !== undefined) { let validPeriod = false; for (let i = 0; i < processConfig.framework.validPeriods.length; i++) { let period = processConfig.framework.validPeriods[i]; - if (period === timePeriodLabel) { validPeriod = true } + if (period === timeFrameLabel) { validPeriod = true } } if (validPeriod === false) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> Discarding period for not being listed as a valid period. -> timePeriodLabel = " + timePeriodLabel); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> Discarding period for not being listed as a valid period. -> timeFrameLabel = " + timeFrameLabel); } periodsControlLoop(); return; } } - if (bot.VALUES_TO_USE.timePeriod === timePeriodLabel) { - currentTimePeriod = global.dailyFilePeriods[n][0]; + if (bot.VALUES_TO_USE.timeFrame === timeFrameLabel) { + currentTimeFrame = global.dailyFilePeriods[n][0]; currentOutputPeriodName = global.dailyFilePeriods[n][1]; } @@ -603,7 +603,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } let dependency = dataDependencies.nodeArray[dependencyIndex]; let dataset = datasets[dependencyIndex]; @@ -622,7 +622,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> Entering function."); } if (dependency.dataSet === "Multi-Period-Market") { @@ -634,7 +634,7 @@ let filePath if (dependency.dataSet === "Multi-Period-Daily") { - filePath = dependency.product + '/' + dependency.dataSet + "/" + timePeriodLabel + "/" + dateForPath; + filePath = dependency.product + '/' + dependency.dataSet + "/" + timeFrameLabel + "/" + dateForPath; } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } @@ -646,8 +646,8 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Entering function."); } - if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> text = " + text); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> text = " + text); } if ((err.message === "File does not exist." && botNeverRan === true) || err.code === 'The specified key does not exist.') { @@ -658,7 +658,7 @@ After that, we will not accept more missing files on any of the dependencies, and if any is missing we will abort the processing. */ - logger.write(MODULE_NAME, "[WARN] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Skipping day because file " + filePath + "/" + fileName + " was not found."); + logger.write(MODULE_NAME, "[WARN] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Skipping day because file " + filePath + "/" + fileName + " was not found."); advanceTime(); return; @@ -666,14 +666,14 @@ if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = " + err.stack); callBackFunction(err); return; } @@ -684,13 +684,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -699,7 +699,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Entering function."); } if (dependency.dataSet === "Multi-Period-Market") { @@ -710,7 +710,7 @@ let dateForPath = bot.multiPeriodProcessDatetime.getUTCFullYear() + '/' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCDate(), 2); let filePath if (dependency.dataSet === "Multi-Period-Daily") { - filePath = dependency.product + '/' + dependency.dataSet + "/" + timePeriodLabel + "/" + dateForPath; + filePath = dependency.product + '/' + dependency.dataSet + "/" + timeFrameLabel + "/" + dateForPath; } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } @@ -722,16 +722,16 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Entering function."); } - if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> text = " + text); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> text = " + text); } if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Fail Because -> err = " + err.message); - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> fileName = " + fileName); - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> You are trying to use data that does not exist. "); - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Check that your Datasets building processes are running well. "); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Fail Because -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> fileName = " + fileName); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> You are trying to use data that does not exist. "); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Check that your Datasets building processes are running well. "); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; @@ -739,7 +739,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Not Ok -> err = " + err.code); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Not Ok -> err = " + err.code); callBackFunction(err); return; } @@ -754,19 +754,19 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoop -> dependencyLoopBody -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoop -> dependencyLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -775,7 +775,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> dependencyControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> dependencyControlLoop -> Entering function."); } dependencyIndex++; @@ -793,14 +793,14 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> dependencyControlLoop -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> dependencyControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsLoopBody -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsLoopBody -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -809,7 +809,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> periodsControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> periodsControlLoop -> Entering function."); } n++; @@ -821,16 +821,16 @@ n = 0; - if (currentTimePeriod !== undefined) { + if (currentTimeFrame !== undefined) { callTheBot(); } else { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsControlLoop -> Time Period not Recognized. Can not continue." ); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsControlLoop -> Time Frame not Recognized. Can not continue." ); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsControlLoop -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> periodsControlLoop -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -839,11 +839,11 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> callTheBot -> Entering function."); } botInstance.start( multiPeriodDataFiles, - currentTimePeriod, + currentTimeFrame, currentOutputPeriodName, bot.multiPeriodProcessDatetime, interExecutionMemoryArray[n], @@ -853,7 +853,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { callBackFunction(err); @@ -862,7 +862,7 @@ botNeverRan = false; - if (currentTimePeriod > global.dailyFilePeriods[0][0]) { + if (currentTimeFrame > global.dailyFilePeriods[0][0]) { writeMarketStatusReport(onMarketStatusReport) } else { @@ -873,10 +873,10 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onWritten -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onWritten -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onWritten -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onWritten -> err = " + err.stack); callBackFunction(err); return; } @@ -884,7 +884,7 @@ writeDailyStatusReport(bot.multiPeriodProcessDatetime, onDailyStatusReport); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onWritten -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onWritten -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -892,21 +892,21 @@ function onDailyStatusReport() { try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> Entering function."); } /* The next run we need the process to continue at the date it finished. */ processConfig.framework.startDate.resumeExecution = true; advanceTime(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } function onMarketStatusReport() { try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> Entering function."); } /* This is where we check if we need reached the user defined end datetime. */ @@ -914,7 +914,7 @@ if (now.valueOf() >= bot.VALUES_TO_USE.timeRange.finalDatetime.valueOf()) { const logText = "User Defined End Datetime reached @ " + now.getUTCFullYear() + "/" + (now.getUTCMonth() + 1) + "/" + now.getUTCDate() + "."; - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> " + logText); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> " + logText); } bot.STOP_SESSION = true callBackFunction(global.DEFAULT_OK_RESPONSE); @@ -924,25 +924,25 @@ callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> callTheBot -> onBotFinished -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> callTheBot -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index bd323dc57..0fd6552f7 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -233,7 +233,7 @@ contextVariables.lastFile = new Date(thisReport.lastFile); interExecutionMemoryArray = thisReport.interExecutionMemoryArray; - processTimePeriods(); + processTimeFrames(); return; } else { @@ -254,7 +254,7 @@ /* The first time the process is running is the right time to create the data structure that is going to be shared across different executions. - This data structure has one object per each timePeriod. + This data structure has one object per each timeFrame. */ interExecutionMemoryArray = []; @@ -271,7 +271,7 @@ interExecutionMemoryArray.push(emptyObject); } - processTimePeriods(); + processTimeFrames(); } @@ -285,9 +285,9 @@ } } - function processTimePeriods() { + function processTimeFrames() { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> Entering function."); } try { @@ -302,7 +302,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> Entering function."); } bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); @@ -313,15 +313,15 @@ logger.newInternalLoop(bot.codeName, bot.process); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> previousDay = " + previousDay); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> previousDay = " + previousDay); } /* Validation that we are not going past the head of the market. */ if (bot.multiPeriodDailyProcessDatetime.valueOf() > contextVariables.dateEndOfMarket.valueOf()) { const logText = "Head of the market found @ " + previousDay.getUTCFullYear() + "/" + (previousDay.getUTCMonth() + 1) + "/" + previousDay.getUTCDate() + "."; - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> " + logText); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> " + logText); } callBackFunction(global.DEFAULT_OK_RESPONSE); return; @@ -331,7 +331,7 @@ periodsLoop(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> advanceTime -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> advanceTime -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -340,7 +340,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoop -> Entering function."); } /* Telling the world we are alive and doing well */ let processingDate = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); @@ -358,7 +358,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -367,19 +367,19 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> Entering function."); } - const timePeriod = global.dailyFilePeriods[n][0]; - const timePeriodLabel = global.dailyFilePeriods[n][1]; + const timeFrame = global.dailyFilePeriods[n][0]; + const timeFrameLabel = global.dailyFilePeriods[n][1]; if (processConfig.framework.validPeriods !== undefined) { let validPeriod = false; for (let i = 0; i < processConfig.framework.validPeriods.length; i++) { let period = processConfig.framework.validPeriods[i]; - if (period === timePeriodLabel) { validPeriod = true } + if (period === timeFrameLabel) { validPeriod = true } } if (validPeriod === false) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> Discarding period for not being listed as a valid period. -> timePeriodLabel = " + timePeriodLabel); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> Discarding period for not being listed as a valid period. -> timeFrameLabel = " + timeFrameLabel); } periodsControlLoop(); return; } @@ -394,7 +394,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } let dependency = dataDependencies.nodeArray[dependencyIndex]; let dataset = datasets[dependencyIndex]; @@ -413,12 +413,12 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> Entering function."); } let dateForPath = previousDay.getUTCFullYear() + '/' + utilities.pad(previousDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(previousDay.getUTCDate(), 2); let filePath if (dependency.dataSet === "Multi-Period-Daily") { - filePath = dependency.product + '/' + dependency.dataSet + "/" + timePeriodLabel + "/" + dateForPath; + filePath = dependency.product + '/' + dependency.dataSet + "/" + timeFrameLabel + "/" + dateForPath; } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } @@ -430,8 +430,8 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Entering function."); } - if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> text = " + text); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> text = " + text); } if ((err.message === "File does not exist." && botNeverRan === true) || err.code === 'The specified key does not exist.') { @@ -442,7 +442,7 @@ After that, we will not accept more missing files on any of the dependencies, and if any is missing we will abort the processing. */ - logger.write(MODULE_NAME, "[WARN] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Skipping day because file " + filePath + "/" + fileName + " was not found."); + logger.write(MODULE_NAME, "[WARN] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Skipping day because file " + filePath + "/" + fileName + " was not found."); advanceTime(); return; @@ -450,14 +450,14 @@ if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); callBackFunction(err); return; } @@ -468,13 +468,13 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -483,12 +483,12 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Entering function."); } let dateForPath = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); let filePath if (dependency.dataSet === "Multi-Period-Daily") { - filePath = dependency.product + '/' + dependency.dataSet + "/" + timePeriodLabel + "/" + dateForPath; + filePath = dependency.product + '/' + dependency.dataSet + "/" + timeFrameLabel + "/" + dateForPath; } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } @@ -500,8 +500,8 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Entering function."); } - if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> text = " + text); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> text = " + text); } if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { @@ -515,16 +515,16 @@ return } - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.code); - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> fileName = " + fileName); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.code); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> fileName = " + fileName); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Not OK -> onFileReceived -> err = " + err.code); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Not OK -> onFileReceived -> err = " + err.code); callBackFunction(err); return; } @@ -538,19 +538,19 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Catch Error -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Catch Error -> onFileReceived -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoop -> dependencyLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> dependencyLoopBody -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -559,7 +559,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> dependencyControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> dependencyControlLoop -> Entering function."); } dependencyIndex++; @@ -574,7 +574,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> dependencyControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> dependencyControlLoop -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -583,15 +583,15 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> Entering function."); } - const timePeriod = global.dailyFilePeriods[n][0]; - const timePeriodLabel = global.dailyFilePeriods[n][1]; + const timeFrame = global.dailyFilePeriods[n][0]; + const timeFrameLabel = global.dailyFilePeriods[n][1]; botInstance.start( dataFiles, - timePeriod, - timePeriodLabel, + timeFrame, + timeFrameLabel, bot.multiPeriodDailyProcessDatetime, interExecutionMemoryArray[n], onBotFinished); @@ -600,7 +600,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> onBotFinished -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { @@ -612,19 +612,19 @@ periodsControlLoop(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> onBotFinished -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -633,7 +633,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsControlLoop -> Entering function."); } n++; @@ -651,10 +651,10 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> controlLoop -> onWritten -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> controlLoop -> onWritten -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> controlLoop -> onWritten -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> controlLoop -> onWritten -> err = "+ err.stack); callBackFunction(err); return; } @@ -662,21 +662,21 @@ writeStatusReport(bot.multiPeriodDailyProcessDatetime, advanceTime); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> controlLoop -> onWritten -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> controlLoop -> onWritten -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsControlLoop -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index efc98ddb3..f4c056225 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -106,11 +106,11 @@ } - processTimePeriods(); + processTimeFrames(); - function processTimePeriods() { + function processTimeFrames() { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> Entering function."); } try { @@ -122,7 +122,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoop -> Entering function."); } /* @@ -136,7 +136,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -145,10 +145,10 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> Entering function."); } - const timePeriod = global.marketFilesPeriods[n][0]; - const timePeriodLabel = global.marketFilesPeriods[n][1]; + const timeFrame = global.marketFilesPeriods[n][0]; + const timeFrameLabel = global.marketFilesPeriods[n][1]; let dependencyIndex = 0; dataFiles = new Map; @@ -159,7 +159,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } let dependency = dataDependencies.nodeArray[dependencyIndex]; let dataset = datasets[dependencyIndex]; @@ -170,14 +170,14 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2); let fileName = market.assetA + '_' + market.assetB + ".json"; let filePath if (dependency.dataSet === "Multi-Period-Market") { - filePath = dependency.product + '/' + dependency.dataSet + "/" + timePeriodLabel; + filePath = dependency.product + '/' + dependency.dataSet + "/" + timeFrameLabel; } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } @@ -187,12 +187,12 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> Entering function."); } - if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> text = " + text); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> text = " + text); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = "+ err.stack); callBackFunction(err); return; } @@ -204,20 +204,20 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> onFileReceived -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getFile -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoop -> dependencyLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoop -> dependencyLoopBody -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -226,7 +226,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> dependencyControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> dependencyControlLoop -> Entering function."); } dependencyIndex++; @@ -241,7 +241,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> dependencyControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> dependencyControlLoop -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -250,15 +250,15 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> Entering function."); } - const timePeriod = global.marketFilesPeriods[n][0]; - const timePeriodLabel = global.marketFilesPeriods[n][1]; + const timeFrame = global.marketFilesPeriods[n][0]; + const timeFrameLabel = global.marketFilesPeriods[n][1]; botInstance.start( dataFiles, - timePeriod, - timePeriodLabel, + timeFrame, + timeFrameLabel, undefined, undefined, onBotFinished); @@ -267,7 +267,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> onBotFinished -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { @@ -278,19 +278,19 @@ periodsControlLoop(); } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> onBotFinished -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> onBotFinished -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch(err){ - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> callTheBot -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> callTheBot -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -299,7 +299,7 @@ try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsControlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsControlLoop -> Entering function."); } n++; @@ -314,14 +314,14 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsControlLoop -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsControlLoop -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/Root.js b/Root.js index e008574e0..167c52f6c 100644 --- a/Root.js +++ b/Root.js @@ -4,7 +4,7 @@ global.EXECUTION_DATETIME = new Date(); - /* Time Periods Definitions. */ + /* Time Frames Definitions. */ global.marketFilesPeriods = '[' + diff --git a/Session.js b/Session.js index 17788d20b..22e81f5cf 100644 --- a/Session.js +++ b/Session.js @@ -227,7 +227,7 @@ minimumBalanceB: 0, maximumBalanceA: 0.002, maximumBalanceB: 0, - timePeriod: bot.UI_CURRENT_VALUES.timePeriod, + timeFrame: bot.UI_CURRENT_VALUES.timeFrame, slippage: { positionRate: 0, stopLoss: 0, @@ -314,9 +314,9 @@ } } - /* Time Period */ - if (tradingSystem.parameters.timePeriod !== undefined) { - bot.VALUES_TO_USE.timePeriod = tradingSystem.parameters.timePeriod.code.value + /* Time Frame */ + if (tradingSystem.parameters.timeFrame !== undefined) { + bot.VALUES_TO_USE.timeFrame = tradingSystem.parameters.timeFrame.code.value } /* Slippage */ @@ -410,9 +410,9 @@ } } - /* Time Period */ - if (bot.SESSION.parameters.timePeriod !== undefined) { - bot.VALUES_TO_USE.timePeriod = bot.SESSION.parameters.timePeriod.code.value + /* Time Frame */ + if (bot.SESSION.parameters.timeFrame !== undefined) { + bot.VALUES_TO_USE.timeFrame = bot.SESSION.parameters.timeFrame.code.value } /* Slippage */ diff --git a/TradingBot.js b/TradingBot.js index d8cf1766c..426eded4b 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -47,7 +47,7 @@ } } - function start(multiPeriodDataFiles, timePeriod, timePeriodLabel, currentDay, interExecutionMemory, callBackFunction) { + function start(multiPeriodDataFiles, timeFrame, timeFrameLabel, currentDay, interExecutionMemory, callBackFunction) { try { @@ -73,32 +73,32 @@ /* The second phase is about transforming the inputs into a format that can be used to apply the user defined code. */ for (let j = 0; j < global.marketFilesPeriods.length; j++) { - let timePeriodLabel = marketFilesPeriods[j][1] - let dataFiles = multiPeriodDataFiles.get(timePeriodLabel) + let timeFrameLabel = marketFilesPeriods[j][1] + let dataFiles = multiPeriodDataFiles.get(timeFrameLabel) let products = {} - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Inflating Data Files for timePeriod = " + timePeriodLabel); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Inflating Data Files for timeFrame = " + timeFrameLabel); } if (dataFiles !== undefined) { - commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timePeriod) + commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timeFrame) - let propertyName = 'at' + timePeriodLabel.replace('-', ''); + let propertyName = 'at' + timeFrameLabel.replace('-', ''); chart[propertyName] = products } } for (let j = 0; j < global.dailyFilePeriods.length; j++) { - let timePeriodLabel = global.dailyFilePeriods[j][1] - let dataFiles = multiPeriodDataFiles.get(timePeriodLabel) + let timeFrameLabel = global.dailyFilePeriods[j][1] + let dataFiles = multiPeriodDataFiles.get(timeFrameLabel) let products = {} - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Inflating Data Files for timePeriod = " + timePeriodLabel); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Inflating Data Files for timeFrame = " + timeFrameLabel); } if (dataFiles !== undefined) { - commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timePeriod) + commons.inflateDatafiles(dataFiles, dataDependencies, products, mainDependency, timeFrame) - let propertyName = 'at' + timePeriodLabel.replace('-', ''); + let propertyName = 'at' + timeFrameLabel.replace('-', ''); chart[propertyName] = products } } @@ -126,8 +126,8 @@ tradingSimulation.runSimulation( chart, dataDependencies, - timePeriod, - timePeriodLabel, + timeFrame, + timeFrameLabel, currentDay, interExecutionMemory, assistant, @@ -142,7 +142,7 @@ strategiesArray = pStrategiesArray tradesArray = pTradesArray - if (timePeriod > global.dailyFilePeriods[0][0]) { + if (timeFrame > global.dailyFilePeriods[0][0]) { writeMarketFiles() } else { writeDailyFiles() @@ -222,7 +222,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -300,7 +300,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -370,7 +370,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -443,7 +443,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timePeriodLabel; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -569,7 +569,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -676,7 +676,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -764,7 +764,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -841,7 +841,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); @@ -921,7 +921,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timePeriodLabel + "/" + dateForPath; + let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); diff --git a/TradingSimulation.js b/TradingSimulation.js index c0a451e0d..b67b39a8c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -35,8 +35,8 @@ function runSimulation( chart, dataDependencies, - timePeriod, - timePeriodLabel, + timeFrame, + timeFrameLabel, currentDay, interExecutionMemory, assistant, @@ -47,7 +47,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> Entering function."); } let processingDailyFiles - if (timePeriod > global.dailyFilePeriods[0][0]) { + if (timeFrame > global.dailyFilePeriods[0][0]) { processingDailyFiles = false } else { processingDailyFiles = true @@ -456,7 +456,7 @@ /* Main Array and Maps */ - let propertyName = 'at' + timePeriodLabel.replace('-', ''); + let propertyName = 'at' + timeFrameLabel.replace('-', ''); let candles = chart[propertyName].candles let currentChart = chart[propertyName] @@ -480,7 +480,7 @@ let firstEnd = candles[0].end let targetEnd = bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() let diff = targetEnd - firstEnd - let amount = diff / timePeriod + let amount = diff / timeFrame currentCandleIndex = Math.trunc(amount) if (currentCandleIndex < 0) { currentCandleIndex = 0 } @@ -594,7 +594,7 @@ } periods++; - days = periods * timePeriod / ONE_DAY_IN_MILISECONDS; + days = periods * timeFrame / ONE_DAY_IN_MILISECONDS; if (processingDailyFiles) { if (positionedAtYesterday) { @@ -602,7 +602,7 @@ } /* We skip the candle at the head of the market because currentCandleIndex has not closed yet. */ - let candlesPerDay = ONE_DAY_IN_MILISECONDS / timePeriod + let candlesPerDay = ONE_DAY_IN_MILISECONDS / timeFrame if (currentCandleIndex === candles.length - 1) { if ((candles.length < candlesPerDay) || (candles.length > candlesPerDay && candles.length < candlesPerDay * 2)) { /*We are at the head of the market, thus we skip the last candle because it has not close yet. */ @@ -1593,7 +1593,7 @@ } positionPeriods++; - positionDays = positionPeriods * timePeriod / ONE_DAY_IN_MILISECONDS; + positionDays = positionPeriods * timeFrame / ONE_DAY_IN_MILISECONDS; if (processingDailyFiles) { if (positionedAtYesterday) { From 2d400c4bb71f7294bc729ce573936403c8ec9e11 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 5 Jan 2020 11:25:31 +0100 Subject: [PATCH 04/36] Exchange taken from UI --- Commons.js | 2 +- DataSet.js | 4 ++-- Root.js | 3 ++- SensorBotProcessMainLoop.js | 2 +- StatusReport.js | 2 +- TradingBot.js | 18 +++++++++--------- TradingBotProcessMainLoop.js | 2 +- server.js | 24 ++++++++++++++++++++++-- 8 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Commons.js b/Commons.js index 5a74a6fd9..3ff44b220 100644 --- a/Commons.js +++ b/Commons.js @@ -476,7 +476,7 @@ dateForPath = "/" + currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); } - let filePathRoot = contextSummary.dataMine + "/" + contextSummary.bot + "." + contextSummary.botVersion.major + "." + contextSummary.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + contextSummary.dataSetVersion; + let filePathRoot = contextSummary.dataMine + "/" + contextSummary.bot + "." + contextSummary.botVersion.major + "." + contextSummary.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + contextSummary.dataSetVersion; let filePath = filePathRoot + "/Output/" + contextSummary.product + "/" + contextSummary.dataset + "/" + timeFrameLabel + dateForPath; filePath += '/' + fileName diff --git a/DataSet.js b/DataSet.js index f4ed6b59e..e803faaeb 100644 --- a/DataSet.js +++ b/DataSet.js @@ -104,7 +104,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTextFile -> Entering function."); } - let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + dataDependencyNode.dataSetVersion; + let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + dataDependencyNode.dataSetVersion; let filePath = filePathRoot + "/Output/" + pFolderPath; filePath += '/' + pFileName @@ -146,7 +146,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { return; } - let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + dataDependencyNode.dataSetVersion; + let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + dataDependencyNode.dataSetVersion; let filePath = filePathRoot + "/Output/" + pFolderPath + '/' + pFileName; fileStorage.createTextFile(dataDependencyNode.dataMine, filePath, pFileContent, onFileCreated); diff --git a/Root.js b/Root.js index 167c52f6c..79715c6f5 100644 --- a/Root.js +++ b/Root.js @@ -208,6 +208,7 @@ /* Simplifying the access to basic info */ botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName + botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode.parentNode.code.codeName /* This stuff is still hardcoded and unresolved. */ botConfig.version = { @@ -220,7 +221,7 @@ botConfig.loopCounter = 0; /* File Path Root */ - botConfig.filePathRoot = botConfig.dataMine + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; + botConfig.filePathRoot = botConfig.dataMine + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + botConfig.exchange + "/" + botConfig.dataSetVersion; /* Process Key */ botConfig.processKey = global.TASK_NODE.bot.processes[processIndex].name + '-' + global.TASK_NODE.bot.processes[processIndex].type + '-' + global.TASK_NODE.bot.processes[processIndex].id diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 4adb52bd2..1ad7e8edd 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -390,7 +390,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeExchangeAPI -> Entering function."); } - exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, global.EXCHANGE_NAME); + exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, bot.exchange); exchangeAPI.initialize(onInizialized); diff --git a/StatusReport.js b/StatusReport.js index 12c63ac16..603c82d53 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -155,7 +155,7 @@ let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; if (ownerId !== botId) { - let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "." + statusDependencyNode.botVersion.major + "." + statusDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + statusDependencyNode.dataSetVersion; + let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "." + statusDependencyNode.botVersion.major + "." + statusDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + statusDependencyNode.dataSetVersion; filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; } else { filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; diff --git a/TradingBot.js b/TradingBot.js index 426eded4b..e1884d63b 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -221,7 +221,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -299,7 +299,7 @@ fileContent = "[" + JSON.stringify(tradingSystem) + "," + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -369,7 +369,7 @@ fileContent = "[" + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -442,7 +442,7 @@ fileContent = "[" + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -568,7 +568,7 @@ let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -675,7 +675,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName @@ -763,7 +763,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName @@ -840,7 +840,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName @@ -920,7 +920,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.assetA + '_' + market.assetB + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 9bf8b9926..0db6a9df3 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -581,7 +581,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeExchangeAPI -> Entering function."); } - exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, global.EXCHANGE_NAME); + exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, bot.exchange); exchangeAPI.initialize(onInizialized); diff --git a/server.js b/server.js index 2f7e669ff..917b86e01 100644 --- a/server.js +++ b/server.js @@ -91,7 +91,7 @@ require('dotenv').config(); global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES /* Default parameters can be changed by the execution configuration */ -global.EXCHANGE_NAME = 'Poloniex' + global.MARKET = { assetA: 'USDT', assetB: 'BTC' } global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' } // NOTE: To refactor the name of this variable you would need to go through the bots code that are using it. @@ -174,7 +174,27 @@ function bootLoader() { for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { let code = global.TASK_NODE.bot.processes[processIndex].code - /* Validate that the minimun amount of parameters required are defined. */ + /* Validate that the minimun amount of input required are defined. */ + + if (global.TASK_NODE.bot.processes[processIndex].marketInstance === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Process Instance without a Market Instance. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); + continue + } + + if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance)); + continue + } + + if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent)); + continue + } + + if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode.parentNode === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Exchange Markets without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode)); + continue + } if (global.TASK_NODE.bot.processes[processIndex].referenceParent === undefined) { console.log("[WARN] Task Server -> server -> bootLoader -> Process Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); From 7cab2852fa20bf03fec4aacaca146f4327df7488 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 5 Jan 2020 12:41:05 +0100 Subject: [PATCH 05/36] Market Base Asset --- server.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server.js b/server.js index 917b86e01..72a013ce4 100644 --- a/server.js +++ b/server.js @@ -196,6 +196,26 @@ function bootLoader() { continue } + if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Base Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent)); + continue + } + + if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Quoted Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent)); + continue + } + + if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset.referenceParent === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Base Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset)); + continue + } + + if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset.referenceParent === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Quoted Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset)); + continue + } + if (global.TASK_NODE.bot.processes[processIndex].referenceParent === undefined) { console.log("[WARN] Task Server -> server -> bootLoader -> Process Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); continue From da67471f0e3a9014c5661b9fbe57b7f9c8ef121a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 5 Jan 2020 14:27:15 +0100 Subject: [PATCH 06/36] market from UI --- Assistant.js | 12 ++++++------ Commons.js | 2 +- MultiPeriod.js | 2 +- MultiPeriodDaily.js | 2 +- MultiPeriodMarket.js | 2 +- Root.js | 4 ++++ StatusReport.js | 4 ++-- TradingBot.js | 2 +- server.js | 1 - 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Assistant.js b/Assistant.js index adf3bc209..4c2fe181a 100644 --- a/Assistant.js +++ b/Assistant.js @@ -87,7 +87,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getMarketRateFromExchange -> Entering function."); } - exchangeAPI.getTicker(global.MARKET, onTicker); + exchangeAPI.getTicker(bot.market, onTicker); return; @@ -144,7 +144,7 @@ let dataSet = thisObject.dataDependencies.dataSets.get(key); let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2); - let fileName = '' + global.MARKET.assetA + '_' + global.MARKET.assetB + '.json'; + let fileName = '' + bot.market.assetA + '_' + bot.market.assetB + '.json'; let filePath = bot.marketRateProvider.product + "/" + bot.marketRateProvider.dataSet + "/" + dateForPath; dataSet.getTextFile(filePath, fileName, onFileReceived); @@ -345,7 +345,7 @@ case "Live": { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> Live Mode Detected."); } - exchangeAPI.getOpenPositions(global.MARKET, onResponse); + exchangeAPI.getOpenPositions(bot.market, onResponse); break; } @@ -360,7 +360,7 @@ case "Competition": { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> Competition Mode Detected."); } - exchangeAPI.getOpenPositions(global.MARKET, onResponse); + exchangeAPI.getOpenPositions(bot.market, onResponse); break; } @@ -977,7 +977,7 @@ case "Live": { - exchangeAPI.putPosition(global.MARKET, pType, pRate, pAmountA, pAmountB, onResponse); + exchangeAPI.putPosition(bot.market, pType, pRate, pAmountA, pAmountB, onResponse); return; } @@ -997,7 +997,7 @@ case "Competition": { - exchangeAPI.putPosition(global.MARKET, pType, pRate, pAmountA, pAmountB, onResponse); + exchangeAPI.putPosition(bot.market, pType, pRate, pAmountA, pAmountB, onResponse); return; } diff --git a/Commons.js b/Commons.js index 3ff44b220..e08233d12 100644 --- a/Commons.js +++ b/Commons.js @@ -468,7 +468,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeFile -> Entering function."); } - let market = global.MARKET; + let market = bot.market; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; let dateForPath = '' diff --git a/MultiPeriod.js b/MultiPeriod.js index 52a7b427b..f0d3c59fa 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -93,7 +93,7 @@ let currentTimeFrame let currentOutputPeriodName - let market = global.MARKET; + let market = bot.market; let botNeverRan = true; /* Context Variables */ diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 0fd6552f7..4432f7247 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -88,7 +88,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } - let market = global.MARKET; + let market = bot.market; /* Context Variables */ diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index f4c056225..914ba0314 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -81,7 +81,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } - let market = global.MARKET; + let market = bot.market; /* Context Variables */ diff --git a/Root.js b/Root.js index 79715c6f5..6881da5a5 100644 --- a/Root.js +++ b/Root.js @@ -209,6 +209,10 @@ /* Simplifying the access to basic info */ botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode.parentNode.code.codeName + botConfig.market = { + assetA: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset.referenceParent.code.codeName, + assetB: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset.referenceParent.code.codeName + } /* This stuff is still hardcoded and unresolved. */ botConfig.version = { diff --git a/StatusReport.js b/StatusReport.js index 603c82d53..b5d26862c 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -148,7 +148,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] load -> Entering function."); } - let fileName = "Status.Report." + global.MARKET.assetA + '_' + global.MARKET.assetB + ".json"; + let fileName = "Status.Report." + bot.market.assetA + '_' + bot.market.assetB + ".json"; let filePath; let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; @@ -245,7 +245,7 @@ return; } - let fileName = "Status.Report." + global.MARKET.assetA + '_' + global.MARKET.assetB + ".json"; + let fileName = "Status.Report." + bot.market.assetA + '_' + bot.market.assetB + ".json"; let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; filePath += '/' + fileName diff --git a/TradingBot.js b/TradingBot.js index e1884d63b..cd3f71f92 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -107,7 +107,7 @@ const TRADING_SIMULATION = require('./TradingSimulation.js'); let tradingSimulation = TRADING_SIMULATION.newTradingSimulation(bot, logger, UTILITIES); - let market = global.MARKET; + let market = bot.market; const SIMULATED_RECORDS_FOLDER_NAME = "Trading-Simulation"; const CONDITIONS_FOLDER_NAME = "Simulation-Conditions"; diff --git a/server.js b/server.js index 72a013ce4..8e67c9460 100644 --- a/server.js +++ b/server.js @@ -92,7 +92,6 @@ global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES /* Default parameters can be changed by the execution configuration */ -global.MARKET = { assetA: 'USDT', assetB: 'BTC' } global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' } // NOTE: To refactor the name of this variable you would need to go through the bots code that are using it. /* From dad19f8278962a484a92af54a3c9953050ecdeab Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 5 Jan 2020 15:15:28 +0100 Subject: [PATCH 07/36] baseAsset and quotedAsset refactoring --- Assistant.js | 124 ++++++++++++++++----------------- Commons.js | 4 +- Context.js | 36 +++++----- MultiPeriod.js | 8 +-- MultiPeriodDaily.js | 6 +- MultiPeriodMarket.js | 2 +- Root.js | 4 +- StatusReport.js | 4 +- TradingBot.js | 36 +++++----- TradingSimulation.js | 160 +++++++++++++++++++++---------------------- 10 files changed, 192 insertions(+), 192 deletions(-) diff --git a/Assistant.js b/Assistant.js index 4c2fe181a..00d3176bb 100644 --- a/Assistant.js +++ b/Assistant.js @@ -144,7 +144,7 @@ let dataSet = thisObject.dataDependencies.dataSets.get(key); let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2); - let fileName = '' + bot.market.assetA + '_' + bot.market.assetB + '.json'; + let fileName = '' + bot.market.baseAsset + '_' + bot.market.quotedAsset + '.json'; let filePath = bot.marketRateProvider.product + "/" + bot.marketRateProvider.dataSet + "/" + dateForPath; dataSet.getTextFile(filePath, fileName, onFileReceived); @@ -273,43 +273,43 @@ /* Calculate Profits */ - if (context.executionContext.initialBalance.assetA > 0) { + if (context.executionContext.initialBalance.baseAsset > 0) { - context.executionContext.profits.assetA = (thisObject.truncDecimals(context.executionContext.balance.assetA) - thisObject.truncDecimals(context.executionContext.initialBalance.assetA)) / thisObject.truncDecimals(context.executionContext.initialBalance.assetA); - context.executionContext.profits.assetA = thisObject.truncDecimals(context.executionContext.profits.assetA); + context.executionContext.profits.baseAsset = (thisObject.truncDecimals(context.executionContext.balance.baseAsset) - thisObject.truncDecimals(context.executionContext.initialBalance.baseAsset)) / thisObject.truncDecimals(context.executionContext.initialBalance.baseAsset); + context.executionContext.profits.baseAsset = thisObject.truncDecimals(context.executionContext.profits.baseAsset); } - if (context.executionContext.initialBalance.assetB > 0) { + if (context.executionContext.initialBalance.quotedAsset > 0) { - context.executionContext.profits.assetB = (thisObject.truncDecimals(context.executionContext.balance.assetB) - thisObject.truncDecimals(context.executionContext.initialBalance.assetB)) / thisObject.truncDecimals(context.executionContext.initialBalance.assetB); - context.executionContext.profits.assetB = thisObject.truncDecimals(context.executionContext.profits.assetB); + context.executionContext.profits.quotedAsset = (thisObject.truncDecimals(context.executionContext.balance.quotedAsset) - thisObject.truncDecimals(context.executionContext.initialBalance.quotedAsset)) / thisObject.truncDecimals(context.executionContext.initialBalance.quotedAsset); + context.executionContext.profits.quotedAsset = thisObject.truncDecimals(context.executionContext.profits.quotedAsset); } - context.newHistoryRecord.profitsAssetA = context.executionContext.profits.assetA; - context.newHistoryRecord.profitsAssetB = context.executionContext.profits.assetB; + context.newHistoryRecord.profitsBaseAsset = context.executionContext.profits.baseAsset; + context.newHistoryRecord.profitsQuotedAsset = context.executionContext.profits.quotedAsset; /* Calculate Combined Profits */ - if (context.executionContext.initialBalance.assetA > 0) { + if (context.executionContext.initialBalance.baseAsset > 0) { - let convertedAssetsB = (thisObject.truncDecimals(context.executionContext.balance.assetB) - thisObject.truncDecimals(context.executionContext.initialBalance.assetB)) * marketRate; + let convertedAssetsB = (thisObject.truncDecimals(context.executionContext.balance.quotedAsset) - thisObject.truncDecimals(context.executionContext.initialBalance.quotedAsset)) * marketRate; convertedAssetsB = thisObject.truncDecimals(convertedAssetsB); - context.executionContext.combinedProfits.assetA = (thisObject.truncDecimals(context.executionContext.balance.assetA) + convertedAssetsB - thisObject.truncDecimals(context.executionContext.initialBalance.assetA)) / thisObject.truncDecimals(context.executionContext.initialBalance.assetA) * 100; - context.executionContext.combinedProfits.assetA = thisObject.truncDecimals(context.executionContext.combinedProfits.assetA); + context.executionContext.combinedProfits.baseAsset = (thisObject.truncDecimals(context.executionContext.balance.baseAsset) + convertedAssetsB - thisObject.truncDecimals(context.executionContext.initialBalance.baseAsset)) / thisObject.truncDecimals(context.executionContext.initialBalance.baseAsset) * 100; + context.executionContext.combinedProfits.baseAsset = thisObject.truncDecimals(context.executionContext.combinedProfits.baseAsset); } - if (context.executionContext.initialBalance.assetB > 0) { + if (context.executionContext.initialBalance.quotedAsset > 0) { - let convertedAssetsA = (thisObject.truncDecimals(context.executionContext.balance.assetA) - thisObject.truncDecimals(context.executionContext.initialBalance.assetA)) / marketRate; + let convertedAssetsA = (thisObject.truncDecimals(context.executionContext.balance.baseAsset) - thisObject.truncDecimals(context.executionContext.initialBalance.baseAsset)) / marketRate; convertedAssetsA = thisObject.truncDecimals(convertedAssetsA); - context.executionContext.combinedProfits.assetB = (thisObject.truncDecimals(context.executionContext.balance.assetB) + convertedAssetsA - thisObject.truncDecimals(context.executionContext.initialBalance.assetB)) / thisObject.truncDecimals(context.executionContext.initialBalance.assetB) * 100; - context.executionContext.combinedProfits.assetB = thisObject.truncDecimals(context.executionContext.combinedProfits.assetB); + context.executionContext.combinedProfits.quotedAsset = (thisObject.truncDecimals(context.executionContext.balance.quotedAsset) + convertedAssetsA - thisObject.truncDecimals(context.executionContext.initialBalance.quotedAsset)) / thisObject.truncDecimals(context.executionContext.initialBalance.quotedAsset) * 100; + context.executionContext.combinedProfits.quotedAsset = thisObject.truncDecimals(context.executionContext.combinedProfits.quotedAsset); } - context.newHistoryRecord.combinedProfitsA = context.executionContext.combinedProfits.assetA; - context.newHistoryRecord.combinedProfitsB = context.executionContext.combinedProfits.assetB; + context.newHistoryRecord.combinedProfitsA = context.executionContext.combinedProfits.baseAsset; + context.newHistoryRecord.combinedProfitsB = context.executionContext.combinedProfits.quotedAsset; callBackFunction(global.DEFAULT_OK_RESPONSE); @@ -652,23 +652,23 @@ */ - let sumAssetA = 0; - let sumAssetB = 0; + let sumBaseAsset = 0; + let sumQuotedAsset = 0; let sumRate = 0; for (let k = 0; k < pTrades.length; k++) { let trade = pTrades[k]; - sumAssetA = sumAssetA + thisObject.truncDecimals(trade.amountA); - sumAssetB = sumAssetB + thisObject.truncDecimals(trade.amountB); + sumBaseAsset = sumBaseAsset + thisObject.truncDecimals(trade.amountA); + sumQuotedAsset = sumQuotedAsset + thisObject.truncDecimals(trade.amountB); sumRate = sumRate + thisObject.truncDecimals(trade.rate); } - sumAssetA = thisObject.truncDecimals(sumAssetA); - sumAssetB = thisObject.truncDecimals(sumAssetB); + sumBaseAsset = thisObject.truncDecimals(sumBaseAsset); + sumQuotedAsset = thisObject.truncDecimals(sumQuotedAsset); - if (position.amountB !== sumAssetB) { + if (position.amountB !== sumQuotedAsset) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> position.amountB = " + position.amountB); - logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> sumAssetB = " + sumAssetB); + logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> sumQuotedAsset = " + sumQuotedAsset); logger.write(MODULE_NAME, "[INFO] 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(MODULE_NAME, "[HINT] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> If the process was abruptally cancelled and then restarted, it is possible that now is not sincronized with the exchange."); @@ -724,22 +724,22 @@ */ - let sumAssetA = 0; - let sumAssetB = 0; + let sumBaseAsset = 0; + let sumQuotedAsset = 0; for (let k = 0; k < pTrades.length; k++) { let trade = pTrades[k]; - sumAssetA = sumAssetA + thisObject.truncDecimals(trade.amountA); - sumAssetB = sumAssetB + thisObject.truncDecimals(trade.amountB); + sumBaseAsset = sumBaseAsset + thisObject.truncDecimals(trade.amountA); + sumQuotedAsset = sumQuotedAsset + thisObject.truncDecimals(trade.amountB); } /* To this we add the current position amounts. */ - sumAssetA = sumAssetA + thisObject.truncDecimals(exchangePosition.amountA); - sumAssetB = sumAssetB + thisObject.truncDecimals(exchangePosition.amountB); + sumBaseAsset = sumBaseAsset + thisObject.truncDecimals(exchangePosition.amountA); + sumQuotedAsset = sumQuotedAsset + thisObject.truncDecimals(exchangePosition.amountB); - sumAssetA = thisObject.truncDecimals(sumAssetA); - sumAssetB = thisObject.truncDecimals(sumAssetB); + sumBaseAsset = thisObject.truncDecimals(sumBaseAsset); + sumQuotedAsset = thisObject.truncDecimals(sumQuotedAsset); /* * Next let's get the max decimal positions for the pair being trade returned by the exchange and validate that at least @@ -753,12 +753,12 @@ let minValue = '0.' + (1).toPrecision(exchangeParam - 1).split('.').reverse().join(''); let exchangePrecision = parseFloat(parseFloat(minValue).toFixed(exchangeParam)); - if (Math.abs(position.amountA - sumAssetA) > exchangePrecision || Math.abs(position.amountB - sumAssetB) > exchangePrecision) { + if (Math.abs(position.amountA - sumBaseAsset) > exchangePrecision || Math.abs(position.amountB - sumQuotedAsset) > exchangePrecision) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> position.amountA = " + position.amountA); - logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> sumAssetA = " + sumAssetA); + logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> sumBaseAsset = " + sumBaseAsset); logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> position.amountB = " + position.amountB); - logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> sumAssetB = " + sumAssetB); + logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> sumQuotedAsset = " + sumQuotedAsset); logger.write(MODULE_NAME, "[ERROR] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> Cannot confirm that a partial execution was done well."); @@ -815,8 +815,8 @@ /* Calculate Balances */ - let assetA = 0; - let assetB = 0; + let baseAsset = 0; + let quotedAsset = 0; if (trade.type === 'buy') { @@ -829,13 +829,13 @@ let feeAmount = thisObject.truncDecimals(Number(trade.fee) * Number(trade.amountB)); - assetA = Number(trade.amountA); - assetB = Number(trade.amountB) - feeAmount; + baseAsset = Number(trade.amountA); + quotedAsset = Number(trade.amountB) - feeAmount; - context.executionContext.balance.assetA = thisObject.truncDecimals(context.executionContext.balance.assetA - assetA); - context.executionContext.balance.assetB = thisObject.truncDecimals(context.executionContext.balance.assetB + assetB); + context.executionContext.balance.baseAsset = thisObject.truncDecimals(context.executionContext.balance.baseAsset - baseAsset); + context.executionContext.balance.quotedAsset = thisObject.truncDecimals(context.executionContext.balance.quotedAsset + quotedAsset); - context.executionContext.availableBalance.assetB = thisObject.truncDecimals(context.executionContext.availableBalance.assetB + assetB); + context.executionContext.availableBalance.quotedAsset = thisObject.truncDecimals(context.executionContext.availableBalance.quotedAsset + quotedAsset); /* Not the available balance for asset A is not affected since it was already reduced when the order was placed. */ @@ -852,13 +852,13 @@ let feeAmount = thisObject.truncDecimals(Number(trade.fee) * Number(trade.amountA)); - assetA = Number(trade.amountA) - feeAmount; - assetB = Number(trade.amountB); + baseAsset = Number(trade.amountA) - feeAmount; + quotedAsset = Number(trade.amountB); - context.executionContext.balance.assetA = thisObject.truncDecimals(context.executionContext.balance.assetA + assetA); - context.executionContext.balance.assetB = thisObject.truncDecimals(context.executionContext.balance.assetB - assetB); + context.executionContext.balance.baseAsset = thisObject.truncDecimals(context.executionContext.balance.baseAsset + baseAsset); + context.executionContext.balance.quotedAsset = thisObject.truncDecimals(context.executionContext.balance.quotedAsset - quotedAsset); - context.executionContext.availableBalance.assetA = thisObject.truncDecimals(context.executionContext.availableBalance.assetA + assetA); + context.executionContext.availableBalance.baseAsset = thisObject.truncDecimals(context.executionContext.availableBalance.baseAsset + baseAsset); /* Not the available balance for asset B is not affected since it was already reduced when the order was placed. */ @@ -937,11 +937,11 @@ if (pType === 'buy') { - if (pAmountA > thisObject.truncDecimals(context.executionContext.availableBalance.assetA)) { + if (pAmountA > thisObject.truncDecimals(context.executionContext.availableBalance.baseAsset)) { logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountA is grater than the Available Balance."); logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountA = " + pAmountA); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.assetA)); + logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.baseAsset)); let err = { result: global.DEFAULT_FAIL_RESPONSE.result, @@ -955,11 +955,11 @@ if (pType === 'sell') { - if (pAmountB > thisObject.truncDecimals(context.executionContext.availableBalance.assetB)) { + if (pAmountB > thisObject.truncDecimals(context.executionContext.availableBalance.quotedAsset)) { logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountB is grater than the Available Balance."); logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountB = " + pAmountB); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.assetB)); + logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.quotedAsset)); let err = { result: global.DEFAULT_FAIL_RESPONSE.result, @@ -1048,13 +1048,13 @@ if (position.type === 'buy') { - context.executionContext.availableBalance.assetA = thisObject.truncDecimals(context.executionContext.availableBalance.assetA - pAmountA); + context.executionContext.availableBalance.baseAsset = thisObject.truncDecimals(context.executionContext.availableBalance.baseAsset - pAmountA); context.newHistoryRecord.lastBuyRate = pRate; } if (position.type === 'sell') { - context.executionContext.availableBalance.assetB = thisObject.truncDecimals(context.executionContext.availableBalance.assetB - pAmountB); + context.executionContext.availableBalance.quotedAsset = thisObject.truncDecimals(context.executionContext.availableBalance.quotedAsset - pAmountB); context.newHistoryRecord.lastSellRate = pRate; } @@ -1210,11 +1210,11 @@ } } - function getPublicTradeHistory(assetA, assetB, startTime, endTime, callback) { + function getPublicTradeHistory(baseAsset, quotedAsset, startTime, endTime, callback) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTradeHistory -> Entering function."); } - exchangeAPI.getPublicTradeHistory(assetA, assetB, startTime, endTime, callback); + exchangeAPI.getPublicTradeHistory(baseAsset, quotedAsset, startTime, endTime, callback); } function recalculateRateAverages() { @@ -1296,8 +1296,8 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getCombinedProfits -> Entering function."); } let combinedProfits = { - assetA: context.newHistoryRecord.combinedProfitsA, - assetB: context.newHistoryRecord.combinedProfitsB + baseAsset: context.newHistoryRecord.combinedProfitsA, + quotedAsset: context.newHistoryRecord.combinedProfitsB } if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getCombinedProfits -> JSON.stringify(combinedProfits) = " + JSON.stringify(combinedProfits)); } @@ -1310,8 +1310,8 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getROI -> Entering function."); } let ROI = { - assetA: (context.executionContext.balance.assetA - context.executionContext.initialBalance.assetA) / context.executionContext.initialBalance.assetA * 100, - assetB: (context.executionContext.balance.assetB - context.executionContext.initialBalance.assetB) / context.executionContext.initialBalance.assetB * 100 + baseAsset: (context.executionContext.balance.baseAsset - context.executionContext.initialBalance.baseAsset) / context.executionContext.initialBalance.baseAsset * 100, + quotedAsset: (context.executionContext.balance.quotedAsset - context.executionContext.initialBalance.quotedAsset) / context.executionContext.initialBalance.quotedAsset * 100 } if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getROI -> JSON.stringify(ROI) = " + JSON.stringify(ROI)); } diff --git a/Commons.js b/Commons.js index e08233d12..9465fa5f7 100644 --- a/Commons.js +++ b/Commons.js @@ -469,7 +469,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeFile -> Entering function."); } let market = bot.market; - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let dateForPath = '' if (processingDailyFiles === true) { @@ -493,7 +493,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; diff --git a/Context.js b/Context.js index caf859a1c..deb8305db 100644 --- a/Context.js +++ b/Context.js @@ -36,8 +36,8 @@ newPositions: 0, newTrades: 0, movedPositions: 0, - profitsAssetA: 0, - profitsAssetB: 0, + profitsBaseAsset: 0, + profitsQuotedAsset: 0, combinedProfitsA: 0, combinedProfitsB: 0, messageRelevance: 0, @@ -250,11 +250,11 @@ /* Update the new History Record, in case there are no trades during this execution that updates it. */ - thisObject.newHistoryRecord.profitsAssetA = thisObject.executionContext.profits.assetA; - thisObject.newHistoryRecord.profitsAssetB = thisObject.executionContext.profits.assetB; + thisObject.newHistoryRecord.profitsBaseAsset = thisObject.executionContext.profits.baseAsset; + thisObject.newHistoryRecord.profitsQuotedAsset = thisObject.executionContext.profits.quotedAsset; - thisObject.newHistoryRecord.combinedProfitsA = thisObject.executionContext.combinedProfits.assetA; - thisObject.newHistoryRecord.combinedProfitsB = thisObject.executionContext.combinedProfits.assetB; + thisObject.newHistoryRecord.combinedProfitsA = thisObject.executionContext.combinedProfits.baseAsset; + thisObject.newHistoryRecord.combinedProfitsB = thisObject.executionContext.combinedProfits.quotedAsset; callBack(global.DEFAULT_OK_RESPONSE); @@ -315,24 +315,24 @@ thisObject.executionContext = { initialBalance: { // This is used to calculate profits. - assetA: INITIAL_BALANCE_A, - assetB: INITIAL_BALANCE_B + baseAsset: INITIAL_BALANCE_A, + quotedAsset: INITIAL_BALANCE_B }, balance: { // This is the total balance that includes positions at the order book + funds available to be traded. - assetA: INITIAL_BALANCE_A, - assetB: INITIAL_BALANCE_B // It starts with the initial initialBalance. + baseAsset: INITIAL_BALANCE_A, + quotedAsset: INITIAL_BALANCE_B // It starts with the initial initialBalance. }, availableBalance: { // This is the balance the bot has at any moment in time available to be traded (not in positions at the order book). - assetA: INITIAL_BALANCE_A, - assetB: INITIAL_BALANCE_B // It starts with the initial initialBalance. + baseAsset: INITIAL_BALANCE_A, + quotedAsset: INITIAL_BALANCE_B // It starts with the initial initialBalance. }, profits: { - assetA: 0, - assetB: 0 + baseAsset: 0, + quotedAsset: 0 }, combinedProfits: { - assetA: 0, - assetB: 0 + baseAsset: 0, + quotedAsset: 0 }, positions: [], transactions: [] @@ -457,8 +457,8 @@ thisObject.newHistoryRecord.newPositions, thisObject.newHistoryRecord.newTrades, thisObject.newHistoryRecord.movedPositions, - thisObject.newHistoryRecord.profitsAssetA, - thisObject.newHistoryRecord.profitsAssetB, + thisObject.newHistoryRecord.profitsBaseAsset, + thisObject.newHistoryRecord.profitsQuotedAsset, thisObject.newHistoryRecord.combinedProfitsA, thisObject.newHistoryRecord.combinedProfitsB, diff --git a/MultiPeriod.js b/MultiPeriod.js index f0d3c59fa..4db5534d0 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -312,7 +312,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } - let fileName = market.assetA + '_' + market.assetB + ".json"; + let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; if (dependency.dataSet !== "Multi-Period-Market") { @@ -638,7 +638,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.assetA + '_' + market.assetB + ".json"; + let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -714,7 +714,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.assetA + '_' + market.assetB + ".json"; + let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -992,7 +992,7 @@ let fileContent = JSON.stringify(dataRange); - let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '/Data.Range.' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + productCodeName + "/" + 'Multi-Period-Daily' + fileName; fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 4432f7247..ad50e23ca 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -422,7 +422,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.assetA + '_' + market.assetB + ".json"; + let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -492,7 +492,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.assetA + '_' + market.assetB + ".json"; + let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -726,7 +726,7 @@ let fileContent = JSON.stringify(dataRange); - let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '/Data.Range.' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePath = bot.filePathRoot + "/Output/" + productCodeName + "/" + bot.process + fileName; fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 914ba0314..9ba755bb1 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -173,7 +173,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2); - let fileName = market.assetA + '_' + market.assetB + ".json"; + let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; let filePath if (dependency.dataSet === "Multi-Period-Market") { diff --git a/Root.js b/Root.js index 6881da5a5..6d2c714db 100644 --- a/Root.js +++ b/Root.js @@ -210,8 +210,8 @@ botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode.parentNode.code.codeName botConfig.market = { - assetA: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset.referenceParent.code.codeName, - assetB: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset.referenceParent.code.codeName + baseAsset: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset.referenceParent.code.codeName, + quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset.referenceParent.code.codeName } /* This stuff is still hardcoded and unresolved. */ diff --git a/StatusReport.js b/StatusReport.js index b5d26862c..16c680ea1 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -148,7 +148,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] load -> Entering function."); } - let fileName = "Status.Report." + bot.market.assetA + '_' + bot.market.assetB + ".json"; + let fileName = "Status.Report." + bot.market.baseAsset + '_' + bot.market.quotedAsset + ".json"; let filePath; let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; @@ -245,7 +245,7 @@ return; } - let fileName = "Status.Report." + bot.market.assetA + '_' + bot.market.assetB + ".json"; + let fileName = "Status.Report." + bot.market.baseAsset + '_' + bot.market.quotedAsset + ".json"; let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; filePath += '/' + fileName diff --git a/TradingBot.js b/TradingBot.js index cd3f71f92..19a14a7e8 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -219,7 +219,7 @@ fileContent = "[" + fileContent + "]"; - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; @@ -238,7 +238,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeRecordsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeRecordsFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeRecordsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeRecordsFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -297,7 +297,7 @@ fileContent = "[" + fileContent + "]"; fileContent = "[" + JSON.stringify(tradingSystem) + "," + fileContent + "]"; - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; @@ -316,7 +316,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeConditionsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeConditionsFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeConditionsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeConditionsFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -367,7 +367,7 @@ } fileContent = "[" + fileContent + "]"; - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; @@ -386,7 +386,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeStrategiesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeStrategiesFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -440,7 +440,7 @@ } fileContent = "[" + fileContent + "]"; - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; @@ -459,7 +459,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeTradesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeTradesFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeMarketFiles -> writeTradesFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -566,7 +566,7 @@ fileContent = "[" + fileContent + "]"; - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel; @@ -585,7 +585,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeFinalResults -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeFinalResults -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeFinalResults -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeFinalResults -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -673,7 +673,7 @@ fileContent = "[" + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; @@ -692,7 +692,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeRecordsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeRecordsFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeRecordsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeRecordsFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -761,7 +761,7 @@ fileContent = "[" + JSON.stringify(tradingSystem) + "," + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; @@ -780,7 +780,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeConditionsFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeConditionsFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeConditionsFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeConditionsFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -838,7 +838,7 @@ fileContent = "[" + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; @@ -857,7 +857,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeStrategiesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeStrategiesFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeStrategiesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeStrategiesFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; @@ -918,7 +918,7 @@ fileContent = "[" + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; @@ -937,7 +937,7 @@ logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeTradesFile -> onFileCreated -> err = " + err.stack); logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeTradesFile -> onFileCreated -> filePath = " + filePath); - logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeTradesFile -> onFileCreated -> market = " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[ERROR] start -> writeDailyFiles -> writeTradesFile -> onFileCreated -> market = " + market.baseAsset + "_" + market.quotedAsset); callBackFunction(err); return; diff --git a/TradingSimulation.js b/TradingSimulation.js index b67b39a8c..87ba1a5b2 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -117,8 +117,8 @@ */ /*Needed for statistics */ - let previousBalanceAssetA = 0; - let previousBalanceAssetB = 0; + let previousBalanceBaseAsset = 0; + let previousBalanceQuotedAsset = 0; /* Position Management */ let tradePositionRate = 0; @@ -155,8 +155,8 @@ endRate: 0 } - let balanceAssetA = bot.VALUES_TO_USE.initialBalanceA; - let balanceAssetB = bot.VALUES_TO_USE.initialBalanceB; + let balanceBaseAsset = bot.VALUES_TO_USE.initialBalanceA; + let balanceQuotedAsset = bot.VALUES_TO_USE.initialBalanceB; let lastTradeProfitLoss = 0; let profit = 0; @@ -189,8 +189,8 @@ yesterday.stopLoss = 0 yesterday.takeProfit = 0 - yesterday.previousBalanceAssetA = previousBalanceAssetA - yesterday.previousBalanceAssetB = previousBalanceAssetB + yesterday.previousBalanceBaseAsset = previousBalanceBaseAsset + yesterday.previousBalanceQuotedAsset = previousBalanceQuotedAsset yesterday.tradePositionRate = tradePositionRate yesterday.tradePositionSize = tradePositionSize @@ -223,8 +223,8 @@ endRate: 0 } - yesterday.balanceAssetA = balanceAssetA; - yesterday.balanceAssetB = balanceAssetB; + yesterday.balanceBaseAsset = balanceBaseAsset; + yesterday.balanceQuotedAsset = balanceQuotedAsset; yesterday.lastTradeProfitLoss = 0; yesterday.profit = 0; @@ -257,8 +257,8 @@ interExecutionMemory.stopLoss = 0 interExecutionMemory.takeProfit = 0 - interExecutionMemory.previousBalanceAssetA = previousBalanceAssetA - interExecutionMemory.previousBalanceAssetB = previousBalanceAssetB + interExecutionMemory.previousBalanceBaseAsset = previousBalanceBaseAsset + interExecutionMemory.previousBalanceQuotedAsset = previousBalanceQuotedAsset interExecutionMemory.tradePositionRate = tradePositionRate interExecutionMemory.tradePositionSize = tradePositionSize @@ -291,8 +291,8 @@ endRate: 0 } - interExecutionMemory.balanceAssetA = balanceAssetA; - interExecutionMemory.balanceAssetB = balanceAssetB; + interExecutionMemory.balanceBaseAsset = balanceBaseAsset; + interExecutionMemory.balanceQuotedAsset = balanceQuotedAsset; interExecutionMemory.lastTradeProfitLoss = lastTradeProfitLoss; interExecutionMemory.profit = profit; @@ -327,8 +327,8 @@ stopLoss = interExecutionMemory.stopLoss takeProfit = interExecutionMemory.takeProfit - previousBalanceAssetA = interExecutionMemory.previousBalanceAssetA - previousBalanceAssetB = interExecutionMemory.previousBalanceAssetB + previousBalanceBaseAsset = interExecutionMemory.previousBalanceBaseAsset + previousBalanceQuotedAsset = interExecutionMemory.previousBalanceQuotedAsset tradePositionRate = interExecutionMemory.tradePositionRate tradePositionSize = interExecutionMemory.tradePositionSize @@ -364,11 +364,11 @@ if (currentDay) { if (currentDay.valueOf() >= bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() + ONE_DAY_IN_MILISECONDS) { // Only after the first day we start grabbing the balance from this memory. - balanceAssetA = interExecutionMemory.balanceAssetA; - balanceAssetB = interExecutionMemory.balanceAssetB; + balanceBaseAsset = interExecutionMemory.balanceBaseAsset; + balanceQuotedAsset = interExecutionMemory.balanceQuotedAsset; - yesterday.balanceAssetA = balanceAssetA; - yesterday.balanceAssetB = balanceAssetB; + yesterday.balanceBaseAsset = balanceBaseAsset; + yesterday.balanceQuotedAsset = balanceQuotedAsset; } } @@ -400,8 +400,8 @@ yesterday.stopLoss = stopLoss yesterday.takeProfit = takeProfit - yesterday.previousBalanceAssetA = previousBalanceAssetA - yesterday.previousBalanceAssetB = previousBalanceAssetB + yesterday.previousBalanceBaseAsset = previousBalanceBaseAsset + yesterday.previousBalanceQuotedAsset = previousBalanceQuotedAsset yesterday.tradePositionRate = tradePositionRate yesterday.tradePositionSize = tradePositionSize @@ -708,10 +708,10 @@ /* Default Values*/ if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - positionSize = balanceAssetA; + positionSize = balanceBaseAsset; positionRate = candle.close; } else { - positionSize = balanceAssetB; + positionSize = balanceQuotedAsset; positionRate = candle.close; } @@ -731,15 +731,15 @@ } if (isNaN(positionSize)) { if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - positionSize = balanceAssetA; + positionSize = balanceBaseAsset; } else { - positionSize = balanceAssetB; + positionSize = balanceQuotedAsset; } } else { if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - if (positionSize > balanceAssetA) { positionSize = balanceAssetA } + if (positionSize > balanceBaseAsset) { positionSize = balanceBaseAsset } } else { - if (positionSize > balanceAssetB) { positionSize = balanceAssetB } + if (positionSize > balanceQuotedAsset) { positionSize = balanceQuotedAsset } } } } @@ -1095,11 +1095,11 @@ let balance if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - balance = balanceAssetA + balance = balanceBaseAsset minimumBalance = bot.VALUES_TO_USE.minimumBalanceA maximumBalance = bot.VALUES_TO_USE.maximumBalanceA } else { - balance = balanceAssetB + balance = balanceQuotedAsset minimumBalance = bot.VALUES_TO_USE.minimumBalanceB maximumBalance = bot.VALUES_TO_USE.maximumBalanceB } @@ -1718,27 +1718,27 @@ let feePaid = 0 if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - strategy.positionSize = balanceAssetB / finalStopLoss; + strategy.positionSize = balanceQuotedAsset / finalStopLoss; strategy.positionRate = finalStopLoss; - feePaid = balanceAssetB / finalStopLoss * bot.VALUES_TO_USE.feeStructure.taker / 100 + feePaid = balanceQuotedAsset / finalStopLoss * bot.VALUES_TO_USE.feeStructure.taker / 100 - balanceAssetA = balanceAssetA + balanceAssetB / finalStopLoss - feePaid; - balanceAssetB = 0; + balanceBaseAsset = balanceBaseAsset + balanceQuotedAsset / finalStopLoss - feePaid; + balanceQuotedAsset = 0; } else { - strategy.positionSize = balanceAssetA * finalStopLoss; + strategy.positionSize = balanceBaseAsset * finalStopLoss; strategy.positionRate = finalStopLoss; - feePaid = balanceAssetA * finalStopLoss * bot.VALUES_TO_USE.feeStructure.taker / 100 + feePaid = balanceBaseAsset * finalStopLoss * bot.VALUES_TO_USE.feeStructure.taker / 100 - balanceAssetB = balanceAssetB + balanceAssetA * finalStopLoss - feePaid; - balanceAssetA = 0; + balanceQuotedAsset = balanceQuotedAsset + balanceBaseAsset * finalStopLoss - feePaid; + balanceBaseAsset = 0; } if (processingDailyFiles) { if (positionedAtYesterday) { - yesterday.balanceAssetA = balanceAssetA; - yesterday.balanceAssetB = balanceAssetB; + yesterday.balanceBaseAsset = balanceBaseAsset; + yesterday.balanceQuotedAsset = balanceQuotedAsset; } } @@ -1814,27 +1814,27 @@ let feePaid = 0 if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - strategy.positionSize = balanceAssetB / finalTakeProfit; + strategy.positionSize = balanceQuotedAsset / finalTakeProfit; strategy.positionRate = finalTakeProfit; - feePaid = balanceAssetB / finalTakeProfit * bot.VALUES_TO_USE.feeStructure.taker / 100 + feePaid = balanceQuotedAsset / finalTakeProfit * bot.VALUES_TO_USE.feeStructure.taker / 100 - balanceAssetA = balanceAssetA + balanceAssetB / finalTakeProfit - feePaid; - balanceAssetB = 0; + balanceBaseAsset = balanceBaseAsset + balanceQuotedAsset / finalTakeProfit - feePaid; + balanceQuotedAsset = 0; } else { - strategy.positionSize = balanceAssetA * finalTakeProfit; + strategy.positionSize = balanceBaseAsset * finalTakeProfit; strategy.positionRate = finalTakeProfit; - feePaid = balanceAssetA * finalTakeProfit * bot.VALUES_TO_USE.feeStructure.taker / 100 + feePaid = balanceBaseAsset * finalTakeProfit * bot.VALUES_TO_USE.feeStructure.taker / 100 - balanceAssetB = balanceAssetB + balanceAssetA * finalTakeProfit - feePaid; - balanceAssetA = 0; + balanceQuotedAsset = balanceQuotedAsset + balanceBaseAsset * finalTakeProfit - feePaid; + balanceBaseAsset = 0; } if (processingDailyFiles) { if (positionedAtYesterday) { - yesterday.balanceAssetA = balanceAssetA; - yesterday.balanceAssetB = balanceAssetB; + yesterday.balanceBaseAsset = balanceBaseAsset; + yesterday.balanceQuotedAsset = balanceQuotedAsset; } } @@ -2041,8 +2041,8 @@ amountA = tradePositionSize * openPositionRate amountB = tradePositionSize - if (amountB > availableBalance.assetB) { // The assistant know what fees were paid. - amountB = availableBalance.assetB + if (amountB > availableBalance.quotedAsset) { // The assistant know what fees were paid. + amountB = availableBalance.quotedAsset } } else { positionDirection = "buy" @@ -2052,8 +2052,8 @@ amountA = tradePositionSize amountB = tradePositionSize / openPositionRate - if (amountA > availableBalance.assetA) { // The assistant know what fees were paid. - amountA = availableBalance.assetA + if (amountA > availableBalance.baseAsset) { // The assistant know what fees were paid. + amountA = availableBalance.baseAsset } } @@ -2117,13 +2117,13 @@ marketRate = candle.close; - previousBalanceAssetA = balanceAssetA; - previousBalanceAssetB = balanceAssetB; + previousBalanceBaseAsset = balanceBaseAsset; + previousBalanceQuotedAsset = balanceQuotedAsset; if (processingDailyFiles) { if (positionedAtYesterday) { - yesterday.previousBalanceAssetA = previousBalanceAssetA; - yesterday.previousBalanceAssetB = previousBalanceAssetB; + yesterday.previousBalanceBaseAsset = previousBalanceBaseAsset; + yesterday.previousBalanceQuotedAsset = previousBalanceQuotedAsset; } } @@ -2136,20 +2136,20 @@ feePaid = tradePositionSize * tradePositionRate * bot.VALUES_TO_USE.feeStructure.taker / 100 - balanceAssetB = balanceAssetB + tradePositionSize * tradePositionRate - feePaid; - balanceAssetA = balanceAssetA - tradePositionSize; + balanceQuotedAsset = balanceQuotedAsset + tradePositionSize * tradePositionRate - feePaid; + balanceBaseAsset = balanceBaseAsset - tradePositionSize; } else { feePaid = tradePositionSize / tradePositionRate * bot.VALUES_TO_USE.feeStructure.taker / 100 - balanceAssetA = balanceAssetA + tradePositionSize / tradePositionRate - feePaid; - balanceAssetB = balanceAssetB - tradePositionSize; + balanceBaseAsset = balanceBaseAsset + tradePositionSize / tradePositionRate - feePaid; + balanceQuotedAsset = balanceQuotedAsset - tradePositionSize; } if (processingDailyFiles) { if (positionedAtYesterday) { - yesterday.balanceAssetA = balanceAssetA; - yesterday.balanceAssetB = balanceAssetB; + yesterday.balanceBaseAsset = balanceBaseAsset; + yesterday.balanceQuotedAsset = balanceQuotedAsset; yesterday.lastTradeProfitLoss = lastTradeProfitLoss; yesterday.lastTradeROI = lastTradeROI; @@ -2262,16 +2262,16 @@ closePositionRate = ticker.last + 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. - amountA = availableBalance.assetA - amountB = availableBalance.assetA / closePositionRate + amountA = availableBalance.baseAsset + amountB = availableBalance.baseAsset / closePositionRate } else { positionDirection = "sell" closePositionRate = ticker.last - 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. - amountA = availableBalance.assetB * closePositionRate - amountB = availableBalance.assetB + amountA = availableBalance.quotedAsset * closePositionRate + amountB = availableBalance.quotedAsset } @@ -2337,15 +2337,15 @@ } if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - lastTradeProfitLoss = balanceAssetA - previousBalanceAssetA; + lastTradeProfitLoss = balanceBaseAsset - previousBalanceBaseAsset; lastTradeROI = lastTradeProfitLoss * 100 / tradePositionSize; if (isNaN(lastTradeROI)) { lastTradeROI = 0; } - profit = balanceAssetA - bot.VALUES_TO_USE.initialBalanceA; + profit = balanceBaseAsset - bot.VALUES_TO_USE.initialBalanceA; } else { - lastTradeProfitLoss = balanceAssetB - previousBalanceAssetB; + lastTradeProfitLoss = balanceQuotedAsset - previousBalanceQuotedAsset; lastTradeROI = lastTradeProfitLoss * 100 / tradePositionSize; if (isNaN(lastTradeROI)) { lastTradeROI = 0; } - profit = balanceAssetB - bot.VALUES_TO_USE.initialBalanceB; + profit = balanceQuotedAsset - bot.VALUES_TO_USE.initialBalanceB; } if (processingDailyFiles) { @@ -2533,12 +2533,12 @@ } } - if (balanceAssetA === Infinity) { - balanceAssetA = Number.MAX_SAFE_INTEGER + if (balanceBaseAsset === Infinity) { + balanceBaseAsset = Number.MAX_SAFE_INTEGER } - if (balanceAssetB === Infinity) { - balanceAssetB = Number.MAX_SAFE_INTEGER + if (balanceQuotedAsset === Infinity) { + balanceQuotedAsset = Number.MAX_SAFE_INTEGER } let quotedBaseAsset = '"' + bot.VALUES_TO_USE.baseAsset + '"' @@ -2549,8 +2549,8 @@ type: type, marketRate: marketRate, amount: 1, - balanceA: balanceAssetA, - balanceB: balanceAssetB, + balanceA: balanceBaseAsset, + balanceB: balanceQuotedAsset, profit: profit, lastTradeProfitLoss: lastTradeProfitLoss, stopLoss: stopLoss, @@ -2814,8 +2814,8 @@ interExecutionMemory.stopLoss = yesterday.stopLoss interExecutionMemory.takeProfit = yesterday.takeProfit - interExecutionMemory.previousBalanceAssetA = yesterday.previousBalanceAssetA - interExecutionMemory.previousBalanceAssetB = yesterday.previousBalanceAssetB + interExecutionMemory.previousBalanceBaseAsset = yesterday.previousBalanceBaseAsset + interExecutionMemory.previousBalanceQuotedAsset = yesterday.previousBalanceQuotedAsset interExecutionMemory.tradePositionRate = yesterday.tradePositionRate interExecutionMemory.tradePositionSize = yesterday.tradePositionSize @@ -2848,8 +2848,8 @@ endRate: yesterday.currentTrade.endRate } - interExecutionMemory.balanceAssetA = yesterday.balanceAssetA; - interExecutionMemory.balanceAssetB = yesterday.balanceAssetB; + interExecutionMemory.balanceBaseAsset = yesterday.balanceBaseAsset; + interExecutionMemory.balanceQuotedAsset = yesterday.balanceQuotedAsset; interExecutionMemory.lastTradeProfitLoss = yesterday.lastTradeProfitLoss; interExecutionMemory.profit = yesterday.profit; interExecutionMemory.lastTradeROI = yesterday.lastTradeROI; From c1c732e4bfa9591180e5586181cd18a350d87491 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 6 Jan 2020 13:47:10 +0100 Subject: [PATCH 08/36] Base asset from reference parent --- Session.js | 126 +++++++++++++++++++++++-------------------- TradingSimulation.js | 125 +++++++++++++++++++++--------------------- 2 files changed, 132 insertions(+), 119 deletions(-) diff --git a/Session.js b/Session.js index 22e81f5cf..33fcf1e11 100644 --- a/Session.js +++ b/Session.js @@ -278,37 +278,42 @@ /* Base Asset and Initial Balances. */ { if (tradingSystem.parameters.baseAsset !== undefined) { - let code = tradingSystem.parameters.baseAsset.code + if (tradingSystem.parameters.baseAsset.referenceParent !== undefined) { + if (tradingSystem.parameters.baseAsset.referenceParent.referenceParent !== undefined) { - if (code.name !== undefined) { - bot.VALUES_TO_USE.baseAsset = code.name; - } + let code = tradingSystem.parameters.baseAsset.referenceParent.referenceParent.code - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceB = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceB = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceB = 0 - } - } else { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceA = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceA = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceA = 0 + if (code.codeName !== undefined) { + bot.VALUES_TO_USE.baseAsset = code.codeName; + } + + if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceB = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceB = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceB = 0 + } + } else { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceA = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceA = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceA = 0 + } + } } } } @@ -374,37 +379,42 @@ /* Base Asset and Initial Balances. */ { if (bot.SESSION.parameters.baseAsset !== undefined) { - let code = bot.SESSION.parameters.baseAsset.code + if (tradingSystem.parameters.baseAsset.referenceParent !== undefined) { + if (tradingSystem.parameters.baseAsset.referenceParent.referenceParent !== undefined) { - if (code.name !== undefined) { - bot.VALUES_TO_USE.baseAsset = code.name; - } + let code = tradingSystem.parameters.baseAsset.referenceParent.referenceParent.code - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceB = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceB = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceB = 0 - } - } else { - if (code.initialBalance !== undefined) { - bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; - bot.VALUES_TO_USE.initialBalanceA = 0 - } - if (code.minimumBalance !== undefined) { - bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; - bot.VALUES_TO_USE.minimumBalanceA = 0 - } - if (code.maximumBalance !== undefined) { - bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; - bot.VALUES_TO_USE.maximumBalanceA = 0 + if (code.codeName !== undefined) { + bot.VALUES_TO_USE.baseAsset = code.codeName; + } + + if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceB = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceB = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceB = 0 + } + } else { + if (code.initialBalance !== undefined) { + bot.VALUES_TO_USE.initialBalanceB = code.initialBalance; + bot.VALUES_TO_USE.initialBalanceA = 0 + } + if (code.minimumBalance !== undefined) { + bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance; + bot.VALUES_TO_USE.minimumBalanceA = 0 + } + if (code.maximumBalance !== undefined) { + bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance; + bot.VALUES_TO_USE.maximumBalanceA = 0 + } + } } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index 87ba1a5b2..12e65ef22 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -44,7 +44,6 @@ callBackFunction) { try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> Entering function."); } let processingDailyFiles if (timeFrame > global.dailyFilePeriods[0][0]) { @@ -1361,45 +1360,47 @@ } } - let phase = parentNode.stopLoss.phases[p]; + if (parentNode !== undefined) { + let phase = parentNode.stopLoss.phases[p]; - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - let situation = nextPhaseEvent.situations[k]; - let passed = true; + let situation = nextPhaseEvent.situations[k]; + let passed = true; - for (let m = 0; m < situation.conditions.length; m++) { + for (let m = 0; m < situation.conditions.length; m++) { - let condition = situation.conditions[m]; - let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; + let condition = situation.conditions[m]; + let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; - let value = false - if (conditions.get(key) !== undefined) { - value = conditions.get(key).value; - } - - if (value === false) { passed = false; } - } - - if (passed) { - - stopLossPhase++; - stopLossStage = 'Manage Stage' - if (takeProfitPhase > 0) { strategyStage = 'Manage Stage' } - - if (processingDailyFiles) { - if (positionedAtYesterday) { - yesterday.stopLossPhase = stopLossPhase; - yesterday.stopLossStage = stopLossStage; - yesterday.strategyStage = strategyStage; + let value = false + if (conditions.get(key) !== undefined) { + value = conditions.get(key).value; } + + if (value === false) { passed = false; } } - checkAnnouncements(nextPhaseEvent) - return; + if (passed) { + + stopLossPhase++; + stopLossStage = 'Manage Stage' + if (takeProfitPhase > 0) { strategyStage = 'Manage Stage' } + + if (processingDailyFiles) { + if (positionedAtYesterday) { + yesterday.stopLossPhase = stopLossPhase; + yesterday.stopLossStage = stopLossStage; + yesterday.strategyStage = strategyStage; + } + } + + checkAnnouncements(nextPhaseEvent) + return; + } } } } @@ -1490,45 +1491,47 @@ } } - let phase = parentNode.takeProfit.phases[p]; + if (parentNode !== undefined) { + let phase = parentNode.takeProfit.phases[p]; - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - let situation = nextPhaseEvent.situations[k]; - let passed = true; + let situation = nextPhaseEvent.situations[k]; + let passed = true; - for (let m = 0; m < situation.conditions.length; m++) { + for (let m = 0; m < situation.conditions.length; m++) { - let condition = situation.conditions[m]; - let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; + let condition = situation.conditions[m]; + let key = j + '-' + stageKey + initialDefinitionKey + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; - let value = false - if (conditions.get(key) !== undefined) { - value = conditions.get(key).value; - } - - if (value === false) { passed = false; } - } - - if (passed) { - - takeProfitPhase++; - takeProfitStage = 'Manage Stage' - if (stopLossPhase > 0) { strategyStage = 'Manage Stage' } - - if (processingDailyFiles) { - if (positionedAtYesterday) { - yesterday.takeProfitPhase = takeProfitPhase; - yesterday.takeProfitStage = takeProfitStage; - yesterday.strategyStage = strategyStage; + let value = false + if (conditions.get(key) !== undefined) { + value = conditions.get(key).value; } + + if (value === false) { passed = false; } } - checkAnnouncements(nextPhaseEvent) - return; + if (passed) { + + takeProfitPhase++; + takeProfitStage = 'Manage Stage' + if (stopLossPhase > 0) { strategyStage = 'Manage Stage' } + + if (processingDailyFiles) { + if (positionedAtYesterday) { + yesterday.takeProfitPhase = takeProfitPhase; + yesterday.takeProfitStage = takeProfitStage; + yesterday.strategyStage = strategyStage; + } + } + + checkAnnouncements(nextPhaseEvent) + return; + } } } } From cc0dccc9deb5c32058d6c78dc201df23617dc83e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 Jan 2020 14:44:47 +0100 Subject: [PATCH 09/36] refactoring --- Root.js | 6 +++--- server.js | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Root.js b/Root.js index 6d2c714db..505a8a8a9 100644 --- a/Root.js +++ b/Root.js @@ -208,10 +208,10 @@ /* Simplifying the access to basic info */ botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName - botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode.parentNode.code.codeName + botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode.code.codeName botConfig.market = { - baseAsset: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset.referenceParent.code.codeName, - quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset.referenceParent.code.codeName + baseAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset.referenceParent.code.codeName, + quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset.referenceParent.code.codeName } /* This stuff is still hardcoded and unresolved. */ diff --git a/server.js b/server.js index 8e67c9460..d0c2e7f0c 100644 --- a/server.js +++ b/server.js @@ -175,43 +175,43 @@ function bootLoader() { /* Validate that the minimun amount of input required are defined. */ - if (global.TASK_NODE.bot.processes[processIndex].marketInstance === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Process Instance without a Market Instance. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); + if (global.TASK_NODE.bot.processes[processIndex].marketReference === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Process Instance without a Market Reference. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); continue } - if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Market Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance)); + if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market Reference without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference)); continue } - if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent)); + if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent)); continue } - if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode.parentNode === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Exchange Markets without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.parentNode)); + if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Exchange Markets without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode)); continue } - if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Base Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent)); + if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Base Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent)); continue } - if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Quoted Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent)); + if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Market without a Quoted Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent)); continue } - if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset.referenceParent === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Base Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.baseAsset)); + if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset.referenceParent === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Base Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset)); continue } - if (global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset.referenceParent === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Quoted Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketInstance.referenceParent.quotedAsset)); + if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset.referenceParent === undefined) { + console.log("[WARN] Task Server -> server -> bootLoader -> Quoted Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset)); continue } From ca1032b14a56f674fe2af87761ffda5189a5cd3e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 Jan 2020 16:22:32 +0100 Subject: [PATCH 10/36] Removing Definition node --- Session.js | 29 ++++++----------------------- TradingSimulation.js | 2 +- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Session.js b/Session.js index 33fcf1e11..5fb7b4c8d 100644 --- a/Session.js +++ b/Session.js @@ -46,7 +46,7 @@ function runSession(message) { /* We are going to run the Definition comming at the event. */ - bot.DEFINITION = JSON.parse(message.event.definition) + bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem) bot.SESSION = JSON.parse(message.event.session) bot.UI_CURRENT_VALUES = message.event.uiCurrentValues @@ -171,29 +171,12 @@ } function setKeyToUse() { - /* The last place where we can find a key to use is the key pool at the exchange account. */ - if (bot.DEFINITION.personalData) { - if (bot.DEFINITION.personalData.exchangeAccounts) { - if (bot.DEFINITION.personalData.exchangeAccounts.length > 0) { - let exchangeAccount = bot.DEFINITION.personalData.exchangeAccounts[0] - if (exchangeAccount.keys) { - if (exchangeAccount.keys.length > 0) { - let key = exchangeAccount.keys[0] - - process.env.KEY = key.code.name - process.env.SECRET = key.code.secret - - } - } - } - } - } /* This is the primary fallback, when there is no key defined at the parameters at the session level. */ - if (bot.DEFINITION.tradingSystem) { - if (bot.DEFINITION.tradingSystem.parameters) { - if (bot.DEFINITION.tradingSystem.parameters.key !== undefined) { - let key = bot.DEFINITION.tradingSystem.parameters.key + if (bot.TRADING_SYSTEM) { + if (bot.TRADING_SYSTEM.parameters) { + if (bot.TRADING_SYSTEM.parameters.key !== undefined) { + let key = bot.TRADING_SYSTEM.parameters.key process.env.KEY = key.code.name process.env.SECRET = key.code.secret @@ -268,7 +251,7 @@ } } - let tradingSystem = bot.DEFINITION.tradingSystem + let tradingSystem = bot.TRADING_SYSTEM if (tradingSystem !== undefined) { diff --git a/TradingSimulation.js b/TradingSimulation.js index 12e65ef22..0573fe091 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -57,7 +57,7 @@ let strategiesArray = []; let tradesArray = []; - let tradingSystem = bot.DEFINITION.tradingSystem; + let tradingSystem = bot.TRADING_SYSTEM /* Initial Default Values */ From e5bddcf418cd300c4b532f37d943211aca5301c9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 Jan 2020 17:40:03 +0100 Subject: [PATCH 11/36] Key path fixed --- Session.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Session.js b/Session.js index 5fb7b4c8d..9305df9fc 100644 --- a/Session.js +++ b/Session.js @@ -175,11 +175,13 @@ /* This is the primary fallback, when there is no key defined at the parameters at the session level. */ if (bot.TRADING_SYSTEM) { if (bot.TRADING_SYSTEM.parameters) { - if (bot.TRADING_SYSTEM.parameters.key !== undefined) { - let key = bot.TRADING_SYSTEM.parameters.key + if (bot.TRADING_SYSTEM.parameters.keyInstance !== undefined) { + if (bot.TRADING_SYSTEM.parameters.keyInstance.referenceParent !== undefined) { + let key = bot.TRADING_SYSTEM.parameters.keyInstance.referenceParent - process.env.KEY = key.code.name - process.env.SECRET = key.code.secret + process.env.KEY = key.code.codeName + process.env.SECRET = key.code.secret + } } } } From 42a87942cbeab7c0dfe69497e8c968642ccf1f8d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 Jan 2020 18:37:38 +0100 Subject: [PATCH 12/36] Keys arriving well --- Session.js | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Session.js b/Session.js index 9305df9fc..a22b1dae8 100644 --- a/Session.js +++ b/Session.js @@ -49,11 +49,10 @@ bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem) bot.SESSION = JSON.parse(message.event.session) bot.UI_CURRENT_VALUES = message.event.uiCurrentValues - + /* Set the folderName for logging, reports, context and data output */ let code if (bot.SESSION.code !== undefined) { - code = bot.SESSION.code if (code.folderName === undefined) { bot.SESSION.folderName = bot.SESSION.id @@ -67,27 +66,31 @@ /* Extract values from different sources and consolidate them under one structure that is going to be used later on. */ setValuesToUse(message) - + let allGood switch (bot.SESSION.type) { case 'Backtesting Session': { - startBackTesting(message) + allGood = startBackTesting(message) break } case 'Live Trading Session': { - startLiveTrading(message) + allGood = startLiveTrading(message) break } case 'Fordward Testing Session': { - startFordwardTesting(message) + allGood = startFordwardTesting(message) break } case 'Paper Trading Session': { - startPaperTrading(message) + allGood = startPaperTrading(message) break } } - bot.SESSION_STATUS = 'Idle' - bot.STOP_SESSION = false + if (allGood === true) { + bot.SESSION_STATUS = 'Idle' + bot.STOP_SESSION = false + } else { + bot.STOP_SESSION = true + } } function stopSession(message) { @@ -102,14 +105,14 @@ bot.resumeExecution = false; bot.hasTheBotJustStarted = true bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) + return true } function startLiveTrading(message) { - setKeyToUse() - if (process.env.KEY === undefined || process.env.SECRET === undefined) { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Live mode."); } + console.log("Key 'codeName' or 'secret' not provided. Plese check that and try again.") return } @@ -120,7 +123,7 @@ bot.resumeExecution = false; bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) bot.hasTheBotJustStarted = true - + return true } function startFordwardTesting(message) { @@ -129,6 +132,7 @@ if (process.env.KEY === undefined || process.env.SECRET === undefined) { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Forward Testing mode."); } + console.log("Key 'codeName' or 'secret' not provided. Plese check that and try again.") return } @@ -156,18 +160,19 @@ bot.VALUES_TO_USE.maximumBalanceA = bot.VALUES_TO_USE.maximumBalanceA * balancePercentage / 100 bot.VALUES_TO_USE.maximumBalanceB = bot.VALUES_TO_USE.maximumBalanceB * balancePercentage / 100 + return true } function startPaperTrading(message) { bot.startMode = "Backtest" - console.log("startPaperTrading") + if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) { bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() } bot.resumeExecution = false; bot.hasTheBotJustStarted = true bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) - + return true } function setKeyToUse() { @@ -188,11 +193,12 @@ /* Key defined at the parameters at the session level. */ if (bot.SESSION.parameters) { - if (bot.SESSION.parameters.key !== undefined) { - let key = bot.SESSION.parameters.key - - process.env.KEY = key.code.name - process.env.SECRET = key.code.secret + if (bot.SESSION.parameters.keyInstance !== undefined) { + if (bot.SESSION.parameters.keyInstance.referenceParent !== undefined) { + let key = bot.SESSION.parameters.keyInstance.referenceParent + process.env.KEY = key.code.codeName + process.env.SECRET = key.code.secret + } } } } From 474b85048c38e037f2b51c7e728e71ffcc753399 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 Jan 2020 13:33:44 +0100 Subject: [PATCH 13/36] CCXT implementation in Sensors --- Root.js | 1 + SensorBotProcessMainLoop.js | 78 +------------------------------------ package-lock.json | 5 +++ package.json | 1 + 4 files changed, 8 insertions(+), 77 deletions(-) diff --git a/Root.js b/Root.js index 505a8a8a9..14535c574 100644 --- a/Root.js +++ b/Root.js @@ -213,6 +213,7 @@ baseAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset.referenceParent.code.codeName, quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset.referenceParent.code.codeName } + botConfig.uiStartDate = global.TASK_NODE.bot.code.startDate /* This stuff is still hardcoded and unresolved. */ botConfig.version = { diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 1ad7e8edd..45d7ebed2 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -135,7 +135,6 @@ const UTILITIES = require(ROOT_DIR + 'CloudUtilities'); const STATUS_REPORT = require(ROOT_DIR + 'StatusReport'); - const EXCHANGE_API = require('@superalgos/exchange-gateway'); const STATUS_DEPENDENCIES = require(ROOT_DIR + 'StatusDependencies'); const PROCESS_EXECUTION_EVENTS = require(ROOT_DIR + 'ProcessExecutionEvents'); const PROCESS_OUTPUT = require(ROOT_DIR + 'ProcessOutput'); @@ -328,7 +327,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeStatusDependencies -> onInizialized -> Execution finished well."); - initializeExchangeAPI(); + initializeUserBot(); return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -384,81 +383,6 @@ } } - function initializeExchangeAPI() { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeExchangeAPI -> Entering function."); } - - exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, bot.exchange); - - exchangeAPI.initialize(onInizialized); - - function onInizialized(err) { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeContext -> onInizialized -> onInizialized -> Entering function."); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeExchangeAPI -> onInizialized -> Execution finished well."); } - initializeUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeExchangeAPI -> onInizialized -> Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - processStopped() - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Operation Failed. Aborting the process."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err = " + err.message); - - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> onInizialized -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - function initializeUserBot() { try { diff --git a/package-lock.json b/package-lock.json index 8d6660151..e576ae33f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -98,6 +98,11 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, + "ccxt": { + "version": "1.21.82", + "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.21.82.tgz", + "integrity": "sha512-+HX/6WK8BM5c9OwhALl9zzMKvueZfHDXVmfrKNmQ4005hc+BtNuNe47XEs6dAylY+ll7n9JpzaoIZhy6Lipiew==" + }, "color": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz", diff --git a/package.json b/package.json index a32ca9fda..f50ec7979 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@superalgos/exchange-gateway": "0.0.10", "@superalgos/mqservice": "^0.0.17", "axios": "^0.19.0", + "ccxt": "^1.21.82", "dotenv": "^8.0.0", "node-ipc": "^9.1.1", "telegraf": "^3.32.0", From d093b10b84bc39d1fb2f5a1c2fb0778178564216 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 25 Jan 2020 12:49:09 +0100 Subject: [PATCH 14/36] adaptations for charly historic trades --- MultiPeriodDaily.js | 4 ++-- Root.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index ad50e23ca..505dd2247 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -143,7 +143,7 @@ thisReport = statusReport.file; - if (thisReport.lastFile === undefined) { + if (thisReport.beginingOfMarket === 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 trade history of the market is not there yet."); @@ -156,7 +156,7 @@ return; } - contextVariables.dateBeginOfMarket = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); + contextVariables.dateBeginOfMarket = new Date(thisReport.beginingOfMarket.year + "-" + thisReport.beginingOfMarket.month + "-" + thisReport.beginingOfMarket.days + " " + thisReport.beginingOfMarket.hours + ":" + thisReport.beginingOfMarket.minutes + GMT_SECONDS); } diff --git a/Root.js b/Root.js index 14535c574..9118749f1 100644 --- a/Root.js +++ b/Root.js @@ -209,6 +209,7 @@ /* Simplifying the access to basic info */ botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode.code.codeName + botConfig.exchangeNode = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode botConfig.market = { baseAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset.referenceParent.code.codeName, quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset.referenceParent.code.codeName From 2350dc0b234b8fb98babb5034b6d4970b629ddfa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 27 Jan 2020 21:16:51 +0100 Subject: [PATCH 15/36] key instance changed --- Root.js | 17 +++++++++++++++++ SensorBotProcessMainLoop.js | 7 ++++++- Session.js | 32 +------------------------------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/Root.js b/Root.js index 9118749f1..1f6344366 100644 --- a/Root.js +++ b/Root.js @@ -235,6 +235,23 @@ /* Bot Type */ botConfig.type = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type + /* Setting the Key to use */ + process.env.KEY = undefined + process.env.SECRET = undefined + + if (botConfig.processNode) { + if (botConfig.processNode.marketReference) { + if (botConfig.processNode.marketReference.keyInstance !== undefined) { + if (botConfig.processNode.marketReference.keyInstance.referenceParent !== undefined) { + let key = botConfig.processNode.marketReference.keyInstance.referenceParent + + process.env.KEY = key.code.codeName + process.env.SECRET = key.code.secret + } + } + } + } + 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); } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 45d7ebed2..e63b2c6cf 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -59,7 +59,12 @@ if (bot.process === "Hole-Fixing") { //USER_BOT_MODULE.newUserBot = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AACharly-Sensor-Bot/Hole-Fixing/User.Bot').newUserBot } - USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function + try { + USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function + } catch (err) { + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onBotDownloaded -> err = " + err.stack); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" diff --git a/Session.js b/Session.js index a22b1dae8..920dcde9f 100644 --- a/Session.js +++ b/Session.js @@ -109,7 +109,7 @@ } function startLiveTrading(message) { - setKeyToUse() + if (process.env.KEY === undefined || process.env.SECRET === undefined) { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Live mode."); } console.log("Key 'codeName' or 'secret' not provided. Plese check that and try again.") @@ -128,8 +128,6 @@ function startFordwardTesting(message) { - setKeyToUse() - if (process.env.KEY === undefined || process.env.SECRET === undefined) { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Forward Testing mode."); } console.log("Key 'codeName' or 'secret' not provided. Plese check that and try again.") @@ -175,34 +173,6 @@ return true } - function setKeyToUse() { - - /* This is the primary fallback, when there is no key defined at the parameters at the session level. */ - if (bot.TRADING_SYSTEM) { - if (bot.TRADING_SYSTEM.parameters) { - if (bot.TRADING_SYSTEM.parameters.keyInstance !== undefined) { - if (bot.TRADING_SYSTEM.parameters.keyInstance.referenceParent !== undefined) { - let key = bot.TRADING_SYSTEM.parameters.keyInstance.referenceParent - - process.env.KEY = key.code.codeName - process.env.SECRET = key.code.secret - } - } - } - } - - /* Key defined at the parameters at the session level. */ - if (bot.SESSION.parameters) { - if (bot.SESSION.parameters.keyInstance !== undefined) { - if (bot.SESSION.parameters.keyInstance.referenceParent !== undefined) { - let key = bot.SESSION.parameters.keyInstance.referenceParent - process.env.KEY = key.code.codeName - process.env.SECRET = key.code.secret - } - } - } - } - function setValuesToUse(message) { /* Base on the information received we will determined which values ultimatelly are going to be used, From e88f3eba99e2f66c10873e203abdb4f328bc8af5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 28 Jan 2020 12:41:00 +0100 Subject: [PATCH 16/36] Cleaning File Paths --- Commons.js | 2 +- DataSet.js | 4 ++-- Root.js | 2 +- StatusReport.js | 2 +- TradingBot.js | 18 +++++++++--------- server.js | 4 ---- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Commons.js b/Commons.js index 9465fa5f7..6b850d879 100644 --- a/Commons.js +++ b/Commons.js @@ -476,7 +476,7 @@ dateForPath = "/" + currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); } - let filePathRoot = contextSummary.dataMine + "/" + contextSummary.bot + "." + contextSummary.botVersion.major + "." + contextSummary.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + contextSummary.dataSetVersion; + let filePathRoot = contextSummary.dataMine + "/" + contextSummary.bot + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + contextSummary.product + "/" + contextSummary.dataset + "/" + timeFrameLabel + dateForPath; filePath += '/' + fileName diff --git a/DataSet.js b/DataSet.js index e803faaeb..5110f2301 100644 --- a/DataSet.js +++ b/DataSet.js @@ -104,7 +104,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTextFile -> Entering function."); } - let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + dataDependencyNode.dataSetVersion; + let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + pFolderPath; filePath += '/' + pFileName @@ -146,7 +146,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { return; } - let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "." + dataDependencyNode.botVersion.major + "." + dataDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + dataDependencyNode.dataSetVersion; + let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + pFolderPath + '/' + pFileName; fileStorage.createTextFile(dataDependencyNode.dataMine, filePath, pFileContent, onFileCreated); diff --git a/Root.js b/Root.js index 1f6344366..68f372a6e 100644 --- a/Root.js +++ b/Root.js @@ -227,7 +227,7 @@ botConfig.loopCounter = 0; /* File Path Root */ - botConfig.filePathRoot = botConfig.dataMine + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + botConfig.exchange + "/" + botConfig.dataSetVersion; + botConfig.filePathRoot = botConfig.dataMine + "/" + botConfig.codeName + "/" + botConfig.exchange; /* Process Key */ botConfig.processKey = global.TASK_NODE.bot.processes[processIndex].name + '-' + global.TASK_NODE.bot.processes[processIndex].type + '-' + global.TASK_NODE.bot.processes[processIndex].id diff --git a/StatusReport.js b/StatusReport.js index 16c680ea1..90de88b4d 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -155,7 +155,7 @@ let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; if (ownerId !== botId) { - let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "." + statusDependencyNode.botVersion.major + "." + statusDependencyNode.botVersion.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + statusDependencyNode.dataSetVersion; + let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "/" + bot.exchange; filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; } else { filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; diff --git a/TradingBot.js b/TradingBot.js index 19a14a7e8..357e6bc93 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -221,7 +221,7 @@ let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -299,7 +299,7 @@ fileContent = "[" + JSON.stringify(tradingSystem) + "," + fileContent + "]"; let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -369,7 +369,7 @@ fileContent = "[" + fileContent + "]"; let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -442,7 +442,7 @@ fileContent = "[" + fileContent + "]"; let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -568,7 +568,7 @@ let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel; filePath += '/' + fileName @@ -675,7 +675,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName @@ -763,7 +763,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName @@ -840,7 +840,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName @@ -920,7 +920,7 @@ let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + bot.exchange + "/" + bot.dataSetVersion; + let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName diff --git a/server.js b/server.js index d0c2e7f0c..49a63094f 100644 --- a/server.js +++ b/server.js @@ -90,10 +90,6 @@ require('dotenv').config(); global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES -/* Default parameters can be changed by the execution configuration */ - -global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' } // NOTE: To refactor the name of this variable you would need to go through the bots code that are using it. - /* We need to count how many process instances we deployd and how many of them have already finished their job, either because they just finished or because there was a request to stop the proceses. In this way, once we reach the From 566b0331c0233e47eff3731fcc0e8e79990cd734 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 28 Jan 2020 13:28:30 +0100 Subject: [PATCH 17/36] Removing Container Name from Paths --- Commons.js | 2 +- Context.js | 10 +++++----- DataSet.js | 4 ++-- DebugLog.js | 8 ++++---- FileStorage.js | 31 ++++++++++++------------------- IndicatorBotProcessMainLoop.js | 4 ++-- MultiPeriod.js | 2 +- MultiPeriodDaily.js | 2 +- Root.js | 2 +- SensorBotProcessMainLoop.js | 4 ++-- StatusReport.js | 4 ++-- TradingBot.js | 18 +++++++++--------- TradingBotProcessMainLoop.js | 4 ++-- 13 files changed, 44 insertions(+), 51 deletions(-) diff --git a/Commons.js b/Commons.js index 6b850d879..aaf3d3dcf 100644 --- a/Commons.js +++ b/Commons.js @@ -480,7 +480,7 @@ let filePath = filePathRoot + "/Output/" + contextSummary.product + "/" + contextSummary.dataset + "/" + timeFrameLabel + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(contextSummary.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/Context.js b/Context.js index deb8305db..bc347977b 100644 --- a/Context.js +++ b/Context.js @@ -168,7 +168,7 @@ let fileName = "Execution.History." + bot.startMode + "." + runIndex + ".json"; let filePath = bot.filePathRoot + "/Output/" + sessionPath + "Trading-Process/" + fileName; - fileStorage.getTextFile(bot.dataMine, filePath, onFileReceived); + fileStorage.getTextFile(filePath, onFileReceived); function onFileReceived(err, text) { @@ -229,7 +229,7 @@ let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); let filePath = bot.filePathRoot + "/Output/" + sessionPath + "Trading-Process/" + dateForPath + fileName; - fileStorage.getTextFile(bot.dataMine, filePath, onFileReceived); + fileStorage.getTextFile(filePath, onFileReceived); function onFileReceived(err, text) { @@ -411,7 +411,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { logger.write(MODULE_NAME, "[INFO] saveThemAll -> writeExecutionContext -> fileContent = " + fileContent); } - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -472,7 +472,7 @@ let fileContent = JSON.stringify(thisObject.executionHistory); - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -494,7 +494,7 @@ fileName = "Execution.History." + bot.startMode + "." + "Sequence" + ".json"; filePath = bot.filePathRoot + "/Output/" + sessionPath + "Trading-Process/" + fileName; - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onSequenceFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onSequenceFileCreated); function onSequenceFileCreated(err) { diff --git a/DataSet.js b/DataSet.js index 5110f2301..4ecbbb6b3 100644 --- a/DataSet.js +++ b/DataSet.js @@ -108,7 +108,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { let filePath = filePathRoot + "/Output/" + pFolderPath; filePath += '/' + pFileName - fileStorage.getTextFile(dataDependencyNode.dataMine, filePath, onFileReceived); + fileStorage.getTextFile(filePath, onFileReceived); function onFileReceived(err, text) { @@ -149,7 +149,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "/" + bot.exchange; let filePath = filePathRoot + "/Output/" + pFolderPath + '/' + pFileName; - fileStorage.createTextFile(dataDependencyNode.dataMine, filePath, pFileContent, onFileCreated); + fileStorage.createTextFile(filePath, pFileContent, onFileCreated); function onFileCreated(err) { diff --git a/DebugLog.js b/DebugLog.js index 22be40b3a..ebc3e6d39 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -92,22 +92,22 @@ exports.newDebugLog = function newDebugLog() { let fileToDelete = thisObject.bot.LOGS_TO_DELETE_QUEUE[0] thisObject.bot.LOGS_TO_DELETE_QUEUE.splice(0, 1) /* Will delete this file only if it does not contains ERROR inside. */ - let fileContent = fileStorage.getTextFile(thisObject.bot.dataMine, fileToDelete, onGetFile, true) + let fileContent = fileStorage.getTextFile(fileToDelete, onGetFile, true) function onGetFile(err, fileContent) { if (err.result === global.DEFAULT_OK_RESPONSE.result) { if (fileContent.indexOf("ERROR") < 0) { /* Logs will only be deleted when they contain no ERROR in them. */ - fileStorage.deleteTextFile(thisObject.bot.dataMine, fileToDelete); + fileStorage.deleteTextFile(fileToDelete); } } else { - fileStorage.deleteTextFile(thisObject.bot.dataMine, fileToDelete); + fileStorage.deleteTextFile(fileToDelete); } } } function writeLog() { - fileStorage.createTextFile(thisObject.bot.dataMine, filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); + fileStorage.createTextFile(filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); function onFileCreated(err) { if (err.result !== global.DEFAULT_OK_RESPONSE.result) { console.log("[ERROR] DebugLog -> persist -> onInizialized -> onFileCreated -> err = "+ err.message); diff --git a/FileStorage.js b/FileStorage.js index ee784f5fa..8bca500eb 100644 --- a/FileStorage.js +++ b/FileStorage.js @@ -25,20 +25,18 @@ exports.newFileStorage = function newFileStorage(logger) { return thisObject - function getTextFile(container, filePath, callBackFunction, noRetry) { + function getTextFile(filePath, callBackFunction, noRetry) { logger.write(MODULE_NAME, '[INFO] FileStorage -> getTextFile -> Entering Function.') let fileDoesNotExist = false - container = container.toLowerCase() - /* Choose path for either bots or data */ let fileLocation if (filePath.indexOf("/bots/") > 0) { - fileLocation = process.env.BOTS_PATH + '/' + container + '/' + filePath + fileLocation = process.env.BOTS_PATH + '/' + filePath } else { - fileLocation = process.env.STORAGE_PATH + '/' + container + '/' + filePath + fileLocation = process.env.STORAGE_PATH + '/' + filePath } try { @@ -71,7 +69,6 @@ exports.newFileStorage = function newFileStorage(logger) { } logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Error reading file -> err = ' + err.stack) - logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Error reading file -> container = ' + container) logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Error reading file -> filePath = ' + filePath) logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Error reading file -> err = ' + err.stack) setTimeout(retry, RETRY_TIME_IN_MILISECONDS) @@ -97,7 +94,7 @@ exports.newFileStorage = function newFileStorage(logger) { if (currentRetryGetTextFile < MAX_RETRY) { currentRetryGetTextFile++ logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> retry -> Will try to read the file again -> Retry #: ' + currentRetryGetTextFile) - getTextFile(container, filePath, callBackFunction) + getTextFile(filePath, callBackFunction) } else { currentRetryGetTextFile = 0 @@ -119,18 +116,16 @@ exports.newFileStorage = function newFileStorage(logger) { } } - function createTextFile(container, filePath, fileContent, callBackFunction) { + function createTextFile(filePath, fileContent, callBackFunction) { logger.write(MODULE_NAME, '[INFO] FileStorage -> createTextFile -> Entering Function.') - container = container.toLowerCase() - /* Choose path for either logs or data */ let fileLocation if (filePath.indexOf("/Logs/") > 0) { - fileLocation = process.env.LOG_PATH + '/' + container + '/' + filePath + fileLocation = process.env.LOG_PATH + '/' + filePath } else { - fileLocation = process.env.STORAGE_PATH + '/' + container + '/' + filePath + fileLocation = process.env.STORAGE_PATH + '/' + filePath } try { @@ -198,7 +193,7 @@ exports.newFileStorage = function newFileStorage(logger) { if (currentRetryWriteTextFile < MAX_RETRY) { currentRetryWriteTextFile++ logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> retry -> Will try to write the file again -> Retry #: ' + currentRetryWriteTextFile) - createTextFile(container, filePath, fileContent, callBackFunction) + createTextFile(filePath, fileContent, callBackFunction) } else { currentRetryWriteTextFile = 0 logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> retry -> Max retries reached writting a file. Giving up.') @@ -208,18 +203,16 @@ exports.newFileStorage = function newFileStorage(logger) { } } - function deleteTextFile(container, filePath, callBackFunction) { + function deleteTextFile(filePath, callBackFunction) { logger.write(MODULE_NAME, '[INFO] FileStorage -> deleteTextFile -> Entering Function.') - container = container.toLowerCase() - /* Choose path for either logs or data */ let fileLocation if (filePath.indexOf("/Logs/") > 0) { - fileLocation = process.env.LOG_PATH + '/' + container + '/' + filePath + fileLocation = process.env.LOG_PATH + '/' + filePath } else { - fileLocation = process.env.STORAGE_PATH + '/' + container + '/' + filePath + fileLocation = process.env.STORAGE_PATH + '/' + filePath } try { @@ -252,7 +245,7 @@ exports.newFileStorage = function newFileStorage(logger) { if (currentRetryWriteTextFile < MAX_RETRY) { currentRetryWriteTextFile++ logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> retry -> Will try to write the file again -> Retry #: ' + currentRetryWriteTextFile) - createTextFile(container, filePath, fileContent, callBackFunction) + createTextFile(filePath, fileContent, callBackFunction) } else { currentRetryWriteTextFile = 0 logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> retry -> Max retries reached writting a file. Giving up.') diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 39e613201..0e46ea1e7 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -46,7 +46,7 @@ let filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" - fileStorage.getTextFile(bot.dataMine, filePath, onBotDownloaded); + fileStorage.getTextFile(filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -64,7 +64,7 @@ filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(bot.dataMine, filePath, onCommonsDownloaded); + fileStorage.getTextFile(filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { diff --git a/MultiPeriod.js b/MultiPeriod.js index 4db5534d0..62141ce01 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -995,7 +995,7 @@ let fileName = '/Data.Range.' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + productCodeName + "/" + 'Multi-Period-Daily' + fileName; - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 505dd2247..b50e975c0 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -729,7 +729,7 @@ let fileName = '/Data.Range.' + market.baseAsset + '_' + market.quotedAsset + '.json'; let filePath = bot.filePathRoot + "/Output/" + productCodeName + "/" + bot.process + fileName; - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/Root.js b/Root.js index 68f372a6e..9e9019f79 100644 --- a/Root.js +++ b/Root.js @@ -166,7 +166,7 @@ let filePath = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName + '/bots/' + global.TASK_NODE.bot.code.repo + '/this.bot.config.json'; - fileStorage.getTextFile(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName, filePath, onFileReceived); + fileStorage.getTextFile(filePath, onFileReceived); function onFileReceived(err, text) { diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index e63b2c6cf..98053dbb7 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -44,7 +44,7 @@ let filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" - fileStorage.getTextFile(bot.dataMine, filePath, onBotDownloaded); + fileStorage.getTextFile(filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -69,7 +69,7 @@ filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(bot.dataMine, filePath, onCommonsDownloaded); + fileStorage.getTextFile(filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { diff --git a/StatusReport.js b/StatusReport.js index 90de88b4d..89ff5dca7 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -163,7 +163,7 @@ filePath += '/' + fileName - fileStorage.getTextFile(statusDependencyNode.dataMine, filePath, onFileReceived); + fileStorage.getTextFile(filePath, onFileReceived); function onFileReceived(err, text) { @@ -251,7 +251,7 @@ filePath += '/' + fileName let fileContent = JSON.stringify(thisObject.file); - fileStorage.createTextFile(statusDependencyNode.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/TradingBot.js b/TradingBot.js index 357e6bc93..e969a90fc 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -225,7 +225,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -303,7 +303,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -373,7 +373,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -446,7 +446,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -572,7 +572,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -679,7 +679,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -767,7 +767,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -844,7 +844,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -924,7 +924,7 @@ let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName - fileStorage.createTextFile(bot.dataMine, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 0db6a9df3..7f7124abe 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -56,7 +56,7 @@ let filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js" - fileStorage.getTextFile(bot.dataMine, filePath, onBotDownloaded); + fileStorage.getTextFile(filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -75,7 +75,7 @@ filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(bot.dataMine, filePath, onCommonsDownloaded); + fileStorage.getTextFile(filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { From 9651ccf15d3a3f24dfefe1e17e123f75f144fa49 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 3 Feb 2020 17:58:41 +0100 Subject: [PATCH 18/36] Concept of Multiple Instances of a Process Removed --- IndicatorBotProcessMainLoop.js | 94 +----------- ProcessExecutionEvents.js | 27 ++-- Root.js | 127 ++------------- SensorBotProcessMainLoop.js | 60 +------- StatusDependencies.js | 30 +--- StatusReport.js | 271 +-------------------------------- TradingBotProcessMainLoop.js | 42 ----- 7 files changed, 38 insertions(+), 613 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 0e46ea1e7..00c6974dc 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -85,7 +85,7 @@ } } - function run(pMonth, pYear, callBackFunction) { + function run(callBackFunction) { try { @@ -145,7 +145,7 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4) + console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " 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(); diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index 64f45bda4..3aa7486ee 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -19,25 +19,15 @@ 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) { @@ -51,9 +41,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,8 +69,6 @@ /* 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 callerId = bot.dataMine + "-" + bot.codeName + "-" + bot.process + extraCallerId @@ -92,6 +80,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> callerId = " + callerId); } global.SYSTEM_EVENT_HANDLER.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack) + console.log("LISTENING TO EVENT:", 'Process Execution Finished', key) function responseCallBack(message) { if (message.result !== global.DEFAULT_OK_RESPONSE.result) { @@ -120,7 +109,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 +123,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 +146,9 @@ 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); } + console.log("RAISING EVENT:", 'Process Execution Finished', currentProcessKey) + + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " ); } callBackFunction(global.DEFAULT_OK_RESPONSE); diff --git a/Root.js b/Root.js index 9e9019f79..c960da47f 100644 --- a/Root.js +++ b/Root.js @@ -281,97 +281,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 +293,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 +318,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: { @@ -427,9 +337,6 @@ 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; } else { @@ -453,7 +360,7 @@ } - function runSensorBot(pBotConfig, pProcessConfig, pMonth, pYear) { + function runSensorBot(pBotConfig, pProcessConfig) { try { global.TOTAL_PROCESS_INSTANCES_CREATED++ @@ -465,8 +372,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,18 +380,13 @@ 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) { @@ -527,7 +427,7 @@ } } - function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) { + function runIndicatorBot(pBotConfig, pProcessConfig) { try { global.TOTAL_PROCESS_INSTANCES_CREATED++ @@ -539,8 +439,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,19 +447,14 @@ 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."); diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 98053dbb7..0a443faf9 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -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."); } @@ -150,7 +150,7 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4) + console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) + " bot.processDatetime = " + bot.processDatetime.toISOString()); /* 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(); diff --git a/StatusDependencies.js b/StatusDependencies.js index 65a888955..176188c16 100644 --- a/StatusDependencies.js +++ b/StatusDependencies.js @@ -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); diff --git a/StatusReport.js b/StatusReport.js index 89ff5dca7..d6cd7210e 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -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; - } - } }; diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 7f7124abe..e83ff955d 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -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(); From 3d69e7abcbad45e6756965cca402aaf8072243d7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 4 Feb 2020 09:29:10 +0100 Subject: [PATCH 19/36] Improving console logging plus bug fixes --- DebugLog.js | 6 ++++-- IndicatorBotProcessMainLoop.js | 4 ++-- MultiPeriod.js | 2 -- MultiPeriodDaily.js | 4 +--- ProcessExecutionEvents.js | 8 ++++---- Root.js | 11 +---------- SensorBotProcessMainLoop.js | 6 +++--- TradingBotProcessMainLoop.js | 4 ++-- server.js | 15 ++++++++------- 9 files changed, 25 insertions(+), 35 deletions(-) diff --git a/DebugLog.js b/DebugLog.js index ebc3e6d39..ba2c83788 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -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(); diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 00c6974dc..aa2cd6ac2 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -145,8 +145,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) - + " 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. */ diff --git a/MultiPeriod.js b/MultiPeriod.js index 62141ce01..94a1cd318 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -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); } diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index b50e975c0..1e87a91a5 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -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); } diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index 3aa7486ee..ed79e1be7 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -32,7 +32,8 @@ 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) { @@ -70,7 +71,8 @@ let extraCallerId = '-' + Math.trunc(Math.random() * 10000) + '-' - 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 @@ -80,7 +82,6 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> callerId = " + callerId); } global.SYSTEM_EVENT_HANDLER.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack) - console.log("LISTENING TO EVENT:", 'Process Execution Finished', key) function responseCallBack(message) { if (message.result !== global.DEFAULT_OK_RESPONSE.result) { @@ -146,7 +147,6 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Finished') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Finished', event) - console.log("RAISING EVENT:", 'Process Execution Finished', currentProcessKey) if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " ); } diff --git a/Root.js b/Root.js index c960da47f..41e18541b 100644 --- a/Root.js +++ b/Root.js @@ -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) { @@ -335,7 +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); if (processConfig.startMode.userDefined.resumeExecution === true) { botConfig.hasTheBotJustStarted = false; @@ -393,7 +386,6 @@ 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(); @@ -404,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(); } @@ -460,7 +451,7 @@ 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(); diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 0a443faf9..b8e2c49fc 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -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) + " " - + " 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. */ diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index e83ff955d..01a0ce2dc 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -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 */ diff --git a/server.js b/server.js index 49a63094f..700940611 100644 --- a/server.js +++ b/server.js @@ -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) } } From 3af9b559dfb367ff796601020bccb9b7e607b435 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 4 Feb 2020 18:21:27 +0100 Subject: [PATCH 20/36] Restarting Sessions --- Session.js | 1 + TradingBotProcessMainLoop.js | 4 ++-- server.js | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Session.js b/Session.js index 920dcde9f..fc6f295d2 100644 --- a/Session.js +++ b/Session.js @@ -44,6 +44,7 @@ return function runSession(message) { + if (bot.SESSION_STATUS === 'Idle' || bot.SESSION_STATUS === 'Running') { return } // This happens when the UI is reloaded, the session was running and tries to run it again. /* We are going to run the Definition comming at the event. */ bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem) diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 01a0ce2dc..e2ef012a6 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -208,7 +208,7 @@ processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger) - processExecutionEvents.initialize(undefined, undefined, onInizialized); + processExecutionEvents.initialize(onInizialized); function onInizialized(err) { @@ -356,7 +356,7 @@ statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES); - statusDependencies.initialize(undefined, undefined, onInizialized); + statusDependencies.initialize(onInizialized); function onInizialized(err) { diff --git a/server.js b/server.js index 700940611..8d5c2d432 100644 --- a/server.js +++ b/server.js @@ -40,9 +40,8 @@ process.on('unhandledRejection', (reason, p) => { }) process.on('exit', function (code) { - + /* We send an event signaling that the Task is being terminated. */ - let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') // Meaning Task Stopped From d236287c82459fa00be023afeefaab04c8b427ed Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 09:28:47 +0100 Subject: [PATCH 21/36] Removing concept current values --- Session.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Session.js b/Session.js index fc6f295d2..d6c6f6c92 100644 --- a/Session.js +++ b/Session.js @@ -49,7 +49,6 @@ /* We are going to run the Definition comming at the event. */ bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem) bot.SESSION = JSON.parse(message.event.session) - bot.UI_CURRENT_VALUES = message.event.uiCurrentValues /* Set the folderName for logging, reports, context and data output */ let code @@ -189,7 +188,6 @@ minimumBalanceB: 0, maximumBalanceA: 0.002, maximumBalanceB: 0, - timeFrame: bot.UI_CURRENT_VALUES.timeFrame, slippage: { positionRate: 0, stopLoss: 0, @@ -209,7 +207,7 @@ const ONE_YEAR_IN_MILISECONDS = 365 * 24 * 60 * 60 * 1000 switch (bot.SESSION.type) { case 'Backtesting Session': { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(bot.UI_CURRENT_VALUES.initialDatetime) + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date((new Date()).valueOf() - ONE_YEAR_IN_MILISECONDS) bot.VALUES_TO_USE.timeRange.finalDatetime = new Date() break } From 354e512f8868f111491578aff3aa534e5fc9d42e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 09:53:31 +0100 Subject: [PATCH 22/36] Dates validation --- Session.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Session.js b/Session.js index d6c6f6c92..0aaf44d55 100644 --- a/Session.js +++ b/Session.js @@ -323,10 +323,18 @@ let code = tradingSystem.parameters.timeRange.code if (code.initialDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) + if (isNaN(Date.parse(code.initialDatetime)) === true) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> runSession -> setValuesToUse -> Cannot use initialDatatime provided at Trading System Parameters because it is not a valid Date."); + } else { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) + } } if (code.finalDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) + if (isNaN(Date.parse(code.finalDatetime)) === true) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> runSession -> setValuesToUse -> Cannot use finalDatetime provided at Trading System Parameters because it is not a valid Date."); + } else { + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) + } } } } @@ -424,10 +432,18 @@ let code = bot.SESSION.parameters.timeRange.code if (code.initialDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) + if (isNaN(Date.parse(code.initialDatetime)) === true) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> runSession -> setValuesToUse -> Cannot use initialDatatime provided at Session Parameters because it is not a valid Date."); + } else { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) + } } if (code.finalDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) + if (isNaN(Date.parse(code.finalDatetime)) === true) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> runSession -> setValuesToUse -> Cannot use finalDatetime provided at Session Parameters because it is not a valid Date."); + } else { + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) + } } } } From 53697644294ced824984d5c66f8296604f5566fe Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 13:38:45 +0100 Subject: [PATCH 23/36] cleaning unused dependencies --- ExchangeAPI.js | 197 ++++++++++ Integrations/Ecosystem.js | 88 ----- Project.njsproj | 7 +- TradingBotProcessMainLoop.js | 2 +- package-lock.json | 740 +---------------------------------- package.json | 16 +- utils/logger.js | 39 -- 7 files changed, 209 insertions(+), 880 deletions(-) create mode 100644 ExchangeAPI.js delete mode 100644 Integrations/Ecosystem.js delete mode 100644 utils/logger.js diff --git a/ExchangeAPI.js b/ExchangeAPI.js new file mode 100644 index 000000000..64413f7f7 --- /dev/null +++ b/ExchangeAPI.js @@ -0,0 +1,197 @@ +exports.newExchangeAPI = function newExchangeAPI(logger, exchangeName) { + + let MODULE_NAME = "Exchange API"; + let LOG_INFO = true; + let apiClient; + + let thisObject = { + initialize: initialize, + getTicker: getTicker, + getOpenPositions: getOpenPositions, + getExecutedTrades: getExecutedTrades, + putPosition: putPosition, + movePosition: movePosition, + getPublicTradeHistory: getPublicTradeHistory, + getExchangeProperties: getExchangeProperties, + getMaxDecimalPositions: getMaxDecimalPositions + }; + + return thisObject; + + function initialize(callBackFunction) { + try { + logInfo("Initialize -> Entering function."); + + + + callBackFunction(global.DEFAULT_OK_RESPONSE); + } catch (err) { + logError("Initialize -> err = " + err.stack); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + + /* + * Fixing decimal positions to exchange configuration. + */ + function truncDecimals(pFloatValue) { + let decimals = getMaxDecimalPositions(); + return parseFloat(parseFloat(pFloatValue).toFixed(decimals)); + } + + /* + * Return number of decimals for the current market + */ + function getMaxDecimalPositions() { + return getMarketConfig().maxDecimals; + } + + /* + * Return number of decimals for the current market + */ + function getMarketConfig() { + let markets = getExchangeProperties().markets + for (let i = 0; i < markets.length; i++) { + const market = markets[i]; + if (market.pair[0] === global.MARKET.assetA.toUpperCase() && market.pair[1] === global.MARKET.assetB.toUpperCase()) { + return market; + } + } + } + + /* + * Return number of decimals for the current market + */ + function getExchangeProperties() { + return apiClient.getExchangeProperties(); + } + + /* + * Returns the price for a given pair of assets. + * The object returned is an array of trades: + * ticker = { + * bid, Number + * ask, Number + * last Number + * }; + */ + function getTicker(pMarket, callBack) { + try { + logInfo("getTicker -> Entering function."); + apiClient.getTicker(pMarket, callBack); + } catch (err) { + logError("getTicker -> err = " + err.message); + callBack(global.DEFAULT_FAIL_RESPONSE); + } + } + + /* + * Returns the open positions ath the exchange for a given market and user account. + * The object returned is an array of positions + * + */ + function getOpenPositions(pMarket, callBack) { + try { + logInfo("getOpenPositions -> Entering function. pMarket = " + JSON.stringify(pMarket)); + apiClient.getOpenPositions(pMarket, callBack); + } catch (err) { + logError("getOpenPositions -> Error = " + err.message); + callBack(global.DEFAULT_FAIL_RESPONSE); + } + } + + /* + * Returns the trades for a given order number. + * The object returned is an array of positions + */ + function getExecutedTrades(pPositionId, callBack) { + try { + logInfo("getExecutedTrades -> Entering function. pPositionId = " + pPositionId); + apiClient.getExecutedTrades(pPositionId, callBack); + } catch (err) { + logError("getExecutedTrades -> Error = " + err.message); + callBack(global.DEFAULT_FAIL_RESPONSE); + } + } + + /* + * Creates a new buy or sell order. + * The orderNumber is returned. String + */ + function putPosition(pMarket, pType, pRate, pAmountA, pAmountB, callBack) { + try { + logInfo("putPosition -> Entering function."); + + let rate = truncDecimals(pRate); + let amountA = truncDecimals(pAmountA); + let amountB = truncDecimals(pAmountB); + + logInfo("putPosition -> pMarket = " + pMarket.assetA + "_" + pMarket.assetB); + logInfo("putPosition -> pType = " + pType); + logInfo("putPosition -> pRate = " + rate); + logInfo("putPosition -> pAmountA = " + amountA); + logInfo("putPosition -> pAmountB = " + amountB); + + if (pType === "buy") { + apiClient.buy(pMarket.assetA, pMarket.assetB, rate, amountB, callBack); + } else if (pType === "sell") { + apiClient.sell(pMarket.assetA, pMarket.assetB, rate, amountB, callBack); + } else { + logError("putPosition -> pType must be either 'buy' or 'sell'."); + callBack(global.DEFAULT_FAIL_RESPONSE); + } + } catch (err) { + logError("putPosition -> err = " + JSON.stringify(err.stack) || err.message); + callBack(global.DEFAULT_FAIL_RESPONSE); + } + } + + /* + * Move an existing position to the new rate. + * The new orderNumber is returned. + */ + function movePosition(pPosition, pNewRate, pNewAmountB, callBack) { + try { + logInfo("movePosition -> Entering function."); + logInfo("movePosition -> pPosition = " + JSON.stringify(pPosition)); + logInfo("movePosition -> pNewRate = " + truncDecimals(pNewRate)); + + apiClient.movePosition(pPosition, truncDecimals(pNewRate), truncDecimals(pNewAmountB), callBack); + } catch (err) { + logError("movePosition -> err = " + err.message); + callBack(global.DEFAULT_FAIL_RESPONSE); + } + } + + /* + * Returns all the trade history from the Exchange since startTime to endTime orderd by tradeId. + * It's possible that the exchange doesn't support this method. + * The object returned is an array of trades: + * trade = { + * tradeID, String + * globalTradeID, String + * type, String + * rate, Number + * amountA, Number + * amountB, Number + * date Date + * }; + */ + function getPublicTradeHistory(assetA, assetB, startTime, endTime, callBack) { + try { + logInfo("getTradeHistory -> Entering function."); + apiClient.getPublicTradeHistory(assetA, assetB, startTime, endTime, callBack); + } catch (err) { + logError("getTradeHistory -> err = " + err.message); + callBack(global.DEFAULT_FAIL_RESPONSE); + } + } + + function logInfo(message) { + if (LOG_INFO === true) { logger.write(MODULE_NAME, '[INFO] ' + message) } + } + + function logError(message) { + logger.write(MODULE_NAME, '[ERROR] ' + message) + } +}; diff --git a/Integrations/Ecosystem.js b/Integrations/Ecosystem.js deleted file mode 100644 index 6c76069fe..000000000 --- a/Integrations/Ecosystem.js +++ /dev/null @@ -1,88 +0,0 @@ -const axios = require('axios') -let fs = require('fs') -const { promisify } = require('util') -const readFileAsync = promisify(fs.readFile); - -exports.getEcosystem = async function () { - try { - if (!global.ECOSYSTEM) { - - let executionOnCloud = false - if (process.env.ON_CLOUD !== undefined) { - executionOnCloud = JSON.parse(process.env.ON_CLOUD) - } - - if (executionOnCloud) { - const ecosystemResponse = await axios({ - url: process.env.GATEWAY_ENDPOINT_K8S, - method: 'post', - data: { - query: ` - query { - web_GetEcosystem { - id - dataMines { - codeName - displayName - host { - url - storage - container - accessKey - ownerKey - } - bots { - codeName - displayName - type - profilePicture - repo - configFile - products{ - codeName - displayName - description - dataSets{ - codeName - type - validPeriods - filePath - fileName - dataRange{ - filePath - fileName - } - } - exchangeList{ - name - } - } - } - } - } - } - ` - }, - headers: { - authorization: process.env.AUTHORIZATION - } - }) - //TODO Competition hosts not retrieved currently - - if (ecosystemResponse.data.errors) - throw new Error(ecosystemResponse.data.errors[0].message) - - global.ECOSYSTEM = ecosystemResponse.data.data.web_GetEcosystem - } else { - let fileLocation = process.env.INTER_PROCESS_FILES_PATH + '/ecosystem.json' - let ecosystem = await readFileAsync(fileLocation, { encoding: 'utf8' }) - global.ECOSYSTEM = JSON.parse(ecosystem) - } - } - - return global.ECOSYSTEM - - } catch (error) { - throw new Error('There has been an error getting the Ecosystem: ', error) - } -} diff --git a/Project.njsproj b/Project.njsproj index 22992fbc9..265decdd9 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -28,6 +28,9 @@ Code + + Code + @@ -58,9 +61,6 @@ Code - - Code - Code @@ -95,7 +95,6 @@ - diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index e2ef012a6..ca5bda4aa 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -145,7 +145,7 @@ /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ const UTILITIES = require(ROOT_DIR + 'CloudUtilities'); - const EXCHANGE_API = require('@superalgos/exchange-gateway'); + const EXCHANGE_API = require('ExchangeAPI'); const CONTEXT = require(ROOT_DIR + 'Context'); const ASSISTANT = require(ROOT_DIR + 'Assistant'); const STATUS_REPORT = require(ROOT_DIR + 'StatusReport'); diff --git a/package-lock.json b/package-lock.json index e576ae33f..fbf97a4f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,212 +1,19 @@ { - "name": "@superalgos/clone-executor", - "version": "1.0.51", + "name": "@superalgos/taskserver", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { - "@superalgos/exchange-gateway": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/@superalgos/exchange-gateway/-/exchange-gateway-0.0.10.tgz", - "integrity": "sha512-VsiGeEyqD7NXvn2tFoqqz036WRBtzy6HvpbXqhl/+xG4SMbo2w9hb6AdAeH4KxuU2S7l/oO8zI9d15f30Q191Q==", - "requires": { - "axios": "0.19.0", - "dotenv": "8.0.0", - "nonce": "1.0.4", - "querystring": "0.2.0", - "request": "2.88.0", - "retry": "0.12.0", - "superagent": "5.1.0", - "underscore": "1.9.1" - } - }, - "@superalgos/mqservice": { - "version": "0.0.17", - "resolved": "https://registry.npmjs.org/@superalgos/mqservice/-/mqservice-0.0.17.tgz", - "integrity": "sha512-mxg2AtfFJ78n/p+JK/o6nTrnR+ZPlBNcq7k+6Epnl1t63ldrcm98WOgIQZaNezPPf0E7gSjVX3p+uZO1Ass0kA==" - }, "@types/node": { "version": "12.7.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz", "integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ==" }, - "ajv": { - "version": "6.10.2", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz", - "integrity": "sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==", - "requires": { - "fast-deep-equal": "2.0.1", - "fast-json-stable-stringify": "2.0.0", - "json-schema-traverse": "0.4.1", - "uri-js": "4.2.2" - } - }, - "asn1": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", - "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", - "requires": { - "safer-buffer": "2.1.2" - } - }, - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - }, - "async": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz", - "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==", - "requires": { - "lodash": "4.17.11" - } - }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, - "aws-sign2": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", - "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" - }, - "aws4": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", - "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" - }, - "axios": { - "version": "0.19.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz", - "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", - "requires": { - "follow-redirects": "1.5.10", - "is-buffer": "2.0.3" - } - }, - "bcrypt-pbkdf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", - "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", - "requires": { - "tweetnacl": "0.14.5" - } - }, - "caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" - }, "ccxt": { "version": "1.21.82", "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.21.82.tgz", "integrity": "sha512-+HX/6WK8BM5c9OwhALl9zzMKvueZfHDXVmfrKNmQ4005hc+BtNuNe47XEs6dAylY+ll7n9JpzaoIZhy6Lipiew==" }, - "color": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz", - "integrity": "sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==", - "requires": { - "color-convert": "1.9.3", - "color-string": "1.5.3" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" - }, - "color-string": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.3.tgz", - "integrity": "sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw==", - "requires": { - "color-name": "1.1.3", - "simple-swizzle": "0.2.2" - } - }, - "colornames": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/colornames/-/colornames-1.1.1.tgz", - "integrity": "sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y=" - }, - "colors": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", - "integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==" - }, - "colorspace": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.2.tgz", - "integrity": "sha512-vt+OoIP2d76xLhjwbBaucYlNSpPsrJWPlBTtwCpQKIu6/CSMutyzX93O/Do0qzpH3YoHEes8YEFXyZ797rEhzQ==", - "requires": { - "color": "3.0.0", - "text-hex": "1.0.0" - } - }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "requires": { - "delayed-stream": "1.0.0" - } - }, - "component-emitter": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", - "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==" - }, - "cookiejar": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz", - "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==" - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, - "dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", - "requires": { - "assert-plus": "1.0.0" - } - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, - "diagnostics": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/diagnostics/-/diagnostics-1.1.1.tgz", - "integrity": "sha512-8wn1PmdunLJ9Tqbx+Fx/ZEuHfJf4NKSN2ZBj7SJC/OWRWha843+WsTjqMe1B5E3p28jqBlp+mJ2fPVxPyNgYKQ==", - "requires": { - "colorspace": "1.1.2", - "enabled": "1.0.2", - "kuler": "1.0.1" - } - }, "dotenv": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz", @@ -217,153 +24,11 @@ "resolved": "https://registry.npmjs.org/easy-stack/-/easy-stack-1.0.0.tgz", "integrity": "sha1-EskbMIWjfwuqM26UhurEv5Tj54g=" }, - "ecc-jsbn": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", - "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", - "requires": { - "jsbn": "0.1.1", - "safer-buffer": "2.1.2" - } - }, - "enabled": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz", - "integrity": "sha1-ll9lE9LC0cX0ZStkouM5ZGf8L5M=", - "requires": { - "env-variable": "0.0.5" - } - }, - "env-variable": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz", - "integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA==" - }, "event-pubsub": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/event-pubsub/-/event-pubsub-4.3.0.tgz", "integrity": "sha512-z7IyloorXvKbFx9Bpie2+vMJKKx1fH1EN5yiTfp8CiLOTptSYy1g8H4yDpGlEdshL1PBiFtBHepF2cNsqeEeFQ==" }, - "extend": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" - }, - "extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" - }, - "fast-deep-equal": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", - "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" - }, - "fast-json-stable-stringify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" - }, - "fast-safe-stringify": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.6.tgz", - "integrity": "sha512-q8BZ89jjc+mz08rSxROs8VsrBBcn1SIw1kq9NjolL509tkABRk9io01RAjSaEv1Xb2uFLt8VtRiZbGp5H8iDtg==" - }, - "fecha": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fecha/-/fecha-2.3.3.tgz", - "integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg==" - }, - "follow-redirects": { - "version": "1.5.10", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", - "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", - "requires": { - "debug": "3.1.0" - } - }, - "forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" - }, - "form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.8", - "mime-types": "2.1.24" - } - }, - "formidable": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz", - "integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg==" - }, - "getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "requires": { - "assert-plus": "1.0.0" - } - }, - "har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" - }, - "har-validator": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", - "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", - "requires": { - "ajv": "6.10.2", - "har-schema": "2.0.0" - } - }, - "http-signature": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", - "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", - "requires": { - "assert-plus": "1.0.0", - "jsprim": "1.4.1", - "sshpk": "1.16.1" - } - }, - "is-arrayish": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", - "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" - }, - "is-buffer": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", - "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==" - }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" - }, - "is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" - }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, "js-message": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz", @@ -377,97 +42,6 @@ "easy-stack": "1.0.0" } }, - "jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" - }, - "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" - }, - "json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" - }, - "json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" - }, - "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.3.0", - "json-schema": "0.2.3", - "verror": "1.10.0" - } - }, - "kuler": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz", - "integrity": "sha512-J9nVUucG1p/skKul6DU3PUZrhs0LPulNaeUOox0IyXDi8S4CztTHs1gQphhuZmzXG7VOQSf6NJfKuzteQLv9gQ==", - "requires": { - "colornames": "1.1.1" - } - }, - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" - }, - "logform": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/logform/-/logform-2.1.2.tgz", - "integrity": "sha512-+lZh4OpERDBLqjiwDLpAWNQu6KMjnlXH2ByZwCuSqVPJletw0kTWJf5CgSNAUKn1KUkv3m2cUz/LK8zyEy7wzQ==", - "requires": { - "colors": "1.3.3", - "fast-safe-stringify": "2.0.6", - "fecha": "2.3.3", - "ms": "2.1.1", - "triple-beam": "1.3.0" - }, - "dependencies": { - "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" - } - } - }, - "methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" - }, - "mime": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", - "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" - }, - "mime-db": { - "version": "1.40.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", - "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==" - }, - "mime-types": { - "version": "2.1.24", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz", - "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", - "requires": { - "mime-db": "1.40.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -483,195 +57,11 @@ "js-queue": "2.0.0" } }, - "nonce": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/nonce/-/nonce-1.0.4.tgz", - "integrity": "sha1-7nMCrejBvvR28wG4yR9cxRpIdhI=" - }, - "oauth-sign": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", - "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" - }, - "one-time": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz", - "integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4=" - }, - "performance-now": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", - "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" - }, - "process-nextick-args": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" - }, - "psl": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.2.0.tgz", - "integrity": "sha512-GEn74ZffufCmkDDLNcl3uuyF/aSD6exEyh1v/ZSdAomB82t6G9hzJVRx0jBmLDW+VfZqks3aScmMw9DszwUalA==" - }, - "punycode": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" - }, - "qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" - }, - "querystring": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", - "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=" - }, - "readable-stream": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz", - "integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==", - "requires": { - "inherits": "2.0.3", - "string_decoder": "1.2.0", - "util-deprecate": "1.0.2" - }, - "dependencies": { - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - } - } - }, - "request": { - "version": "2.88.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", - "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", - "requires": { - "aws-sign2": "0.7.0", - "aws4": "1.8.0", - "caseless": "0.12.0", - "combined-stream": "1.0.8", - "extend": "3.0.2", - "forever-agent": "0.6.1", - "form-data": "2.3.3", - "har-validator": "5.1.3", - "http-signature": "1.2.0", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.24", - "oauth-sign": "0.9.0", - "performance-now": "2.1.0", - "qs": "6.5.2", - "safe-buffer": "5.1.2", - "tough-cookie": "2.4.3", - "tunnel-agent": "0.6.0", - "uuid": "3.3.2" - } - }, - "retry": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", - "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=" - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, - "safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" - }, "sandwich-stream": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/sandwich-stream/-/sandwich-stream-2.0.2.tgz", "integrity": "sha512-jLYV0DORrzY3xaz/S9ydJL6Iz7essZeAfnAavsJ+zsJGZ1MOnsS52yRjU3uF3pJa/lla7+wisp//fxOwOH8SKQ==" }, - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" - }, - "simple-swizzle": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", - "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=", - "requires": { - "is-arrayish": "0.3.2" - } - }, - "sshpk": { - "version": "1.16.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", - "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", - "requires": { - "asn1": "0.2.4", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.2", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.2", - "getpass": "0.1.7", - "jsbn": "0.1.1", - "safer-buffer": "2.1.2", - "tweetnacl": "0.14.5" - } - }, - "stack-trace": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", - "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=" - }, - "string_decoder": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.2.0.tgz", - "integrity": "sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==", - "requires": { - "safe-buffer": "5.1.2" - } - }, - "superagent": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.1.0.tgz", - "integrity": "sha512-7V6JVx5N+eTL1MMqRBX0v0bG04UjrjAvvZJTF/VDH/SH2GjSLqlrcYepFlpTrXpm37aSY6h3GGVWGxXl/98TKA==", - "requires": { - "component-emitter": "1.3.0", - "cookiejar": "2.1.2", - "debug": "4.1.1", - "fast-safe-stringify": "2.0.6", - "form-data": "2.3.3", - "formidable": "1.2.1", - "methods": "1.1.2", - "mime": "2.4.4", - "qs": "6.7.0", - "readable-stream": "3.4.0", - "semver": "6.3.0" - }, - "dependencies": { - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "requires": { - "ms": "2.1.2" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, - "qs": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", - "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" - } - } - }, "telegraf": { "version": "3.32.0", "resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.32.0.tgz", @@ -703,132 +93,6 @@ "version": "3.6.1", "resolved": "https://registry.npmjs.org/telegram-typings/-/telegram-typings-3.6.1.tgz", "integrity": "sha512-njVv1EAhIZnmQVLocZEADYUyqA1WIXuVcDYlsp+mXua/XB0pxx+PKtMSPeZ/EE4wPWTw9h/hA9ASTT6yQelkiw==" - }, - "text-hex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", - "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==" - }, - "tough-cookie": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", - "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", - "requires": { - "psl": "1.2.0", - "punycode": "1.4.1" - }, - "dependencies": { - "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" - } - } - }, - "triple-beam": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", - "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" - }, - "tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "requires": { - "safe-buffer": "5.1.2" - } - }, - "tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" - }, - "underscore": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz", - "integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==" - }, - "uri-js": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", - "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", - "requires": { - "punycode": "2.1.1" - } - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" - }, - "uuid": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", - "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" - }, - "verror": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", - "requires": { - "assert-plus": "1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "1.3.0" - } - }, - "winston": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/winston/-/winston-3.2.1.tgz", - "integrity": "sha512-zU6vgnS9dAWCEKg/QYigd6cgMVVNwyTzKs81XZtTFuRwJOcDdBg7AU0mXVyNbs7O5RH2zdv+BdNZUlx7mXPuOw==", - "requires": { - "async": "2.6.2", - "diagnostics": "1.1.1", - "is-stream": "1.1.0", - "logform": "2.1.2", - "one-time": "0.0.4", - "readable-stream": "3.4.0", - "stack-trace": "0.0.10", - "triple-beam": "1.3.0", - "winston-transport": "4.3.0" - } - }, - "winston-transport": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.3.0.tgz", - "integrity": "sha512-B2wPuwUi3vhzn/51Uukcao4dIduEiPOcOt9HJ3QeaXgkJ5Z7UwpBzxS4ZGNHtrxrUvTwemsQiSys0ihOf8Mp1A==", - "requires": { - "readable-stream": "2.3.6", - "triple-beam": "1.3.0" - }, - "dependencies": { - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", - "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "2.0.0", - "safe-buffer": "5.1.2", - "string_decoder": "1.1.1", - "util-deprecate": "1.0.2" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "requires": { - "safe-buffer": "5.1.2" - } - } - } } } } diff --git a/package.json b/package.json index f50ec7979..e9977e889 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,21 @@ { - "name": "@superalgos/clone-executor", - "version": "1.0.51", - "description": "Module responsible for executing the bots on the cloud.", - "author": "Superalgos, ltd.", + "name": "@superalgos/taskserver", + "version": "2.0.0", + "description": "Executes Tasks.", + "author": "Superalgos.org", "license": "Apache-2.0", "repository": { "type": "git", - "url": "https://github.com/Superalgos/CloneExecutor.git" + "url": "https://github.com/Superalgos/TaskServer.git" }, "main": "Run.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@superalgos/exchange-gateway": "0.0.10", - "@superalgos/mqservice": "^0.0.17", - "axios": "^0.19.0", "ccxt": "^1.21.82", "dotenv": "^8.0.0", "node-ipc": "^9.1.1", - "telegraf": "^3.32.0", - "winston": "^3.2.1" + "telegraf": "^3.32.0" } } diff --git a/utils/logger.js b/utils/logger.js deleted file mode 100644 index da3df770b..000000000 --- a/utils/logger.js +++ /dev/null @@ -1,39 +0,0 @@ -const winston = require('winston') -const util = require('util') - -const options = { - file: { - level: 'info', - filename: '../logs/app.log', - handleExceptions: true, - json: true, - maxsize: 5242880, // 5MB - maxFiles: 5, - colorize: false, - timestamp: true - }, - console: { - level: 'debug', - handleExceptions: true, - json: false, - colorize: true, - timestamp: true - } -} - -exports.logger = winston.createLogger({ - level: 'info', - format: winston.format.combine( - winston.format.colorize(), - winston.format.splat(), - winston.format.timestamp({ format: 'YY/MM/DD HH:mm' }), - winston.format.printf( - info => `${info.timestamp} - ${info.level}: ${JSON.parse(JSON.stringify(util.inspect(info.message)))}` - ) - ), - transports: [ - new winston.transports.File(options.file), - new winston.transports.Console(options.console) - ], - exitOnError: false // do not exit on handled exceptions -}) \ No newline at end of file From 6ee36b0687ec31a98449d74febb0dfc1eddd1a69 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 14:59:42 +0100 Subject: [PATCH 24/36] cleaning competition concept --- Assistant.js | 31 ----------------------- ExchangeAPI.js | 66 +------------------------------------------------ Project.njsproj | 4 --- 3 files changed, 1 insertion(+), 100 deletions(-) diff --git a/Assistant.js b/Assistant.js index 00d3176bb..f7661e768 100644 --- a/Assistant.js +++ b/Assistant.js @@ -68,11 +68,6 @@ break; } - case 'Competition': { - getMarketRateFromExchange(); - break; - } - default: { logger.write(MODULE_NAME, "[ERROR] initialize -> Unexpected bot.startMode."); logger.write(MODULE_NAME, "[ERROR] initialize -> bot.startMode = " + bot.startMode); @@ -357,13 +352,6 @@ break; } - case "Competition": { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> Competition Mode Detected."); } - exchangeAPI.getOpenPositions(bot.market, onResponse); - break; - } - default: { logger.write(MODULE_NAME, "[ERROR] getPositionsAtExchange -> Unexpected bot.startMode."); logger.write(MODULE_NAME, "[ERROR] getPositionsAtExchange -> bot.startMode = " + bot.startMode); @@ -587,13 +575,6 @@ return; } - case "Competition": { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> Competition Mode Detected."); } - exchangeAPI.getExecutedTrades(pPositionId, onResponse); - return; - } - default: { logger.write(MODULE_NAME, "[ERROR] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> Unexpected bot.startMode."); logger.write(MODULE_NAME, "[ERROR] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> bot.startMode = " + bot.startMode); @@ -995,12 +976,6 @@ return; } - case "Competition": { - - exchangeAPI.putPosition(bot.market, pType, pRate, pAmountA, pAmountB, onResponse); - return; - } - default: { logger.write(MODULE_NAME, "[ERROR] putPosition -> Unexpected bot.startMode."); logger.write(MODULE_NAME, "[ERROR] putPosition -> bot.startMode = " + bot.startMode); @@ -1121,12 +1096,6 @@ return; } - case "Competition": { - - exchangeAPI.movePosition(pPosition, pNewRate, newAmountB, onResponse); - return; - } - default: { logger.write(MODULE_NAME, "[ERROR] movePosition -> Unexpected bot.startMode."); logger.write(MODULE_NAME, "[ERROR] movePosition -> bot.startMode = " + bot.startMode); diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 64413f7f7..23996337c 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -11,59 +11,18 @@ getExecutedTrades: getExecutedTrades, putPosition: putPosition, movePosition: movePosition, - getPublicTradeHistory: getPublicTradeHistory, - getExchangeProperties: getExchangeProperties, getMaxDecimalPositions: getMaxDecimalPositions }; return thisObject; function initialize(callBackFunction) { - try { - logInfo("Initialize -> Entering function."); - - - callBackFunction(global.DEFAULT_OK_RESPONSE); - } catch (err) { - logError("Initialize -> err = " + err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } + callBackFunction(global.DEFAULT_OK_RESPONSE); } - /* - * Fixing decimal positions to exchange configuration. - */ - function truncDecimals(pFloatValue) { - let decimals = getMaxDecimalPositions(); - return parseFloat(parseFloat(pFloatValue).toFixed(decimals)); - } - - /* - * Return number of decimals for the current market - */ function getMaxDecimalPositions() { - return getMarketConfig().maxDecimals; - } - /* - * Return number of decimals for the current market - */ - function getMarketConfig() { - let markets = getExchangeProperties().markets - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - if (market.pair[0] === global.MARKET.assetA.toUpperCase() && market.pair[1] === global.MARKET.assetB.toUpperCase()) { - return market; - } - } - } - - /* - * Return number of decimals for the current market - */ - function getExchangeProperties() { - return apiClient.getExchangeProperties(); } /* @@ -163,29 +122,6 @@ } } - /* - * Returns all the trade history from the Exchange since startTime to endTime orderd by tradeId. - * It's possible that the exchange doesn't support this method. - * The object returned is an array of trades: - * trade = { - * tradeID, String - * globalTradeID, String - * type, String - * rate, Number - * amountA, Number - * amountB, Number - * date Date - * }; - */ - function getPublicTradeHistory(assetA, assetB, startTime, endTime, callBack) { - try { - logInfo("getTradeHistory -> Entering function."); - apiClient.getPublicTradeHistory(assetA, assetB, startTime, endTime, callBack); - } catch (err) { - logError("getTradeHistory -> err = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); - } - } function logInfo(message) { if (LOG_INFO === true) { logger.write(MODULE_NAME, '[INFO] ' + message) } diff --git a/Project.njsproj b/Project.njsproj index 265decdd9..826e92943 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -32,7 +32,6 @@ Code - Code @@ -93,9 +92,6 @@ - - - From 1dc1e8b676dc1c9a9995bb7db62757aa3befbc25 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 16:06:22 +0100 Subject: [PATCH 25/36] get ticker working with ccxt --- Assistant.js | 94 ------------------------------------ ExchangeAPI.js | 50 +++++++++++++++++-- TradingBotProcessMainLoop.js | 4 +- 3 files changed, 47 insertions(+), 101 deletions(-) diff --git a/Assistant.js b/Assistant.js index f7661e768..b7cc33f6b 100644 --- a/Assistant.js +++ b/Assistant.js @@ -63,7 +63,6 @@ } case 'Backtest': { - // getMarketRateFromIndicator(); NOTE: This path is disabled since for now we do not allow ticker in simulation. Also it allow us to ship a dataset without bruce validateExchangeSyncronicity(); break; } @@ -119,99 +118,6 @@ } } - function getMarketRateFromIndicator() { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getMarketRateFromIndicator -> Entering function."); } - - /* Procedure to get the current market rate. */ - - let key = - bot.marketRateProvider.dataMine + "-" + - bot.marketRateProvider.bot + "-" + - bot.marketRateProvider.product + "-" + - bot.marketRateProvider.dataSet + "-" + - bot.marketRateProvider.dataSetVersion; - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getMarketRateFromIndicator -> key = " + key); } - - let dataSet = thisObject.dataDependencies.dataSets.get(key); - - let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2); - let fileName = '' + bot.market.baseAsset + '_' + bot.market.quotedAsset + '.json'; - let filePath = bot.marketRateProvider.product + "/" + bot.marketRateProvider.dataSet + "/" + dateForPath; - - dataSet.getTextFile(filePath, fileName, onFileReceived); - - function onFileReceived(err, text) { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getMarketRateFromIndicator -> onFileReceived -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getMarketRateFromIndicator -> onFileReceived -> text = " + text); } - - let candleArray; - - if (err.result === global.CUSTOM_FAIL_RESPONSE.result || err.code === "The specified key does not exist." || err.message === "File does not exist.") { // Just past midnight, this file will not exist for a couple of minutes. - - logger.write(MODULE_NAME, "[WARN] initialize -> getMarketRateFromIndicator -> onFileReceived -> err = " + JSON.stringify(err)); - logger.write(MODULE_NAME, "[WARN] initialize -> getMarketRateFromIndicator -> This could happen when there are still holes on trades and the process needs to catch up. "); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - - } - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - try { - candleArray = JSON.parse(text); - - /* We need to find the candle at which the process is currently running. */ - - for (let i = 0; i < candleArray.length; i++) { - - let candle = { - open: candleArray[i][2], - close: candleArray[i][3], - min: candleArray[i][0], - max: candleArray[i][1], - begin: candleArray[i][4], - end: candleArray[i][5] - }; - - // TODO condition added for when there is no market rate available. - if ((bot.processDatetime.valueOf() >= candle.begin && bot.processDatetime.valueOf() < candle.end) - || (i + 1) === candleArray.length) { - - marketRate = (candle.open + candle.close) / 2; - marketRate = thisObject.truncDecimals(marketRate); - context.newHistoryRecord.marketRate = marketRate; - - ticker = { - bid: marketRate, - ask: marketRate, - last: marketRate - }; - - validateExchangeSyncronicity(); - return; - } - } - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> getMarketRateFromIndicator -> onFileReceived -> err = " + JSON.stringify(err)); - logger.write(MODULE_NAME, "[ERROR] initialize -> getMarketRateFromIndicator -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - } - } else { - logger.write(MODULE_NAME, "[ERROR] initialize -> getMarketRateFromIndicator -> onFileReceived -> err = " + JSON.stringify(err)); - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> getMarketRateFromIndicator -> err = " + err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - function validateExchangeSyncronicity() { try { diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 23996337c..50adc5b49 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -1,8 +1,9 @@ -exports.newExchangeAPI = function newExchangeAPI(logger, exchangeName) { +exports.newExchangeAPI = function newExchangeAPI(logger, BOT) { let MODULE_NAME = "Exchange API"; let LOG_INFO = true; let apiClient; + let bot = BOT let thisObject = { initialize: initialize, @@ -14,11 +15,41 @@ getMaxDecimalPositions: getMaxDecimalPositions }; + let exchangeId + let options = {} + let exchange + const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset + const ccxt = require('ccxt') + return thisObject; function initialize(callBackFunction) { + try { + exchangeId = bot.exchange.toLowerCase() - callBackFunction(global.DEFAULT_OK_RESPONSE); + let key = process.env.KEY + let secret = process.env.SECRET + + if (key === "undefined") { key = undefined } + if (secret === "undefined") { secret = undefined } + + const exchangeClass = ccxt[exchangeId] + const exchangeConstructorParams = { + 'apiKey': key, + 'secret': secret, + 'timeout': 30000, + 'enableRateLimit': true, + verbose: false, + options: options + } + + exchange = new exchangeClass(exchangeConstructorParams) + + callBackFunction(global.DEFAULT_OK_RESPONSE) + } catch (err) { + logError("initialize -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } } function getMaxDecimalPositions() { @@ -34,13 +65,22 @@ * last Number * }; */ - function getTicker(pMarket, callBack) { + async function getTicker(pMarket, callBackFunction) { try { logInfo("getTicker -> Entering function."); - apiClient.getTicker(pMarket, callBack); + let ticker + + if (exchange.has['fetchTicker']) { + ticker = await (exchange.fetchTicker(symbol)) + callBackFunction(global.DEFAULT_OK_RESPONSE, ticker) + } else { + logError("getTicker -> Exchange does not support fetchTicker command."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } catch (err) { logError("getTicker -> err = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index ca5bda4aa..0aac6246a 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -145,7 +145,7 @@ /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ const UTILITIES = require(ROOT_DIR + 'CloudUtilities'); - const EXCHANGE_API = require('ExchangeAPI'); + const EXCHANGE_API = require(ROOT_DIR + 'ExchangeAPI'); const CONTEXT = require(ROOT_DIR + 'Context'); const ASSISTANT = require(ROOT_DIR + 'Assistant'); const STATUS_REPORT = require(ROOT_DIR + 'StatusReport'); @@ -581,7 +581,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeExchangeAPI -> Entering function."); } - exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, bot.exchange); + exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, bot); exchangeAPI.initialize(onInizialized); From ce963250c05cae48ca5b29be5d6cf225f1f058e2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 16:44:31 +0100 Subject: [PATCH 26/36] open position method working --- Assistant.js | 20 +++++++++---------- ExchangeAPI.js | 52 +++++++++++++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Assistant.js b/Assistant.js index b7cc33f6b..14b7dafec 100644 --- a/Assistant.js +++ b/Assistant.js @@ -32,7 +32,7 @@ let utilities = UTILITIES.newCloudUtilities(logger); - let exchangePositions = []; // These are the open positions at the exchange at the account the bot is authorized to use. + let openOrders = []; // These are the open positions at the exchange at the account the bot is authorized to use. let openPositions = []; // These are the open positions the bot knows it made by itself. let context; @@ -246,15 +246,15 @@ case "Live": { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> Live Mode Detected."); } - exchangeAPI.getOpenPositions(bot.market, onResponse); + exchangeAPI.getOpenOrders(bot.market, onResponse); break; } case "Backtest": { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> Backtest Mode Detected."); } - let exchangePositions = []; // We simulate all positions were executed. - onResponse(global.DEFAULT_OK_RESPONSE, exchangePositions); + let openOrders = []; // We simulate all positions were executed. + onResponse(global.DEFAULT_OK_RESPONSE, openOrders); break; } @@ -266,15 +266,15 @@ } } - function onResponse(err, pExchangePositions) { + function onResponse(err, pOpenOrders) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> onResponse -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> onResponse -> pExchangePositions = " + JSON.stringify(pExchangePositions)); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> onResponse -> pOpenOrders = " + JSON.stringify(pOpenOrders)); } switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getPositionsAtExchange -> onResponse -> Execution finished well."); } - exchangePositions = pExchangePositions; + openOrders = pOpenOrders; ordersExecutionCheck(callBack); return; } @@ -365,11 +365,11 @@ let position = context.executionContext.positions[i]; let exchangePosition; - for (let j = 0; j < exchangePositions.length; j++) { + for (let j = 0; j < openOrders.length; j++) { - if (position.id === exchangePositions[j].id) { + if (position.id === openOrders[j].id) { - exchangePosition = exchangePositions[j]; + exchangePosition = openOrders[j]; positionFound(); return; } diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 50adc5b49..b13e336a5 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -8,7 +8,7 @@ let thisObject = { initialize: initialize, getTicker: getTicker, - getOpenPositions: getOpenPositions, + getOpenOrders: getOpenOrders, getExecutedTrades: getExecutedTrades, putPosition: putPosition, movePosition: movePosition, @@ -18,7 +18,7 @@ let exchangeId let options = {} let exchange - const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset + const ccxt = require('ccxt') return thisObject; @@ -65,9 +65,10 @@ * last Number * }; */ - async function getTicker(pMarket, callBackFunction) { + async function getTicker(market, callBackFunction) { try { logInfo("getTicker -> Entering function."); + const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset let ticker if (exchange.has['fetchTicker']) { @@ -89,27 +90,38 @@ * The object returned is an array of positions * */ - function getOpenPositions(pMarket, callBack) { + async function getOpenOrders(market, callBackFunction) { try { - logInfo("getOpenPositions -> Entering function. pMarket = " + JSON.stringify(pMarket)); - apiClient.getOpenPositions(pMarket, callBack); + logInfo("getOpenOrders -> Entering function. market = " + JSON.stringify(market)); + + const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset + let openOrders + + if (exchange.has['fetchOpenOrders']) { + openOrders = await(exchange.fetchOpenOrders (symbol)) + callBackFunction(global.DEFAULT_OK_RESPONSE, openOrders) + } else { + logError("getTicker -> Exchange does not support fetchOpenOrders command."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } catch (err) { - logError("getOpenPositions -> Error = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + logError("getOpenOrders -> Error = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } /* * Returns the trades for a given order number. - * The object returned is an array of positions + * The object returned is an array of trades */ - function getExecutedTrades(pPositionId, callBack) { + function getExecutedTrades(pPositionId, callBackFunction) { try { logInfo("getExecutedTrades -> Entering function. pPositionId = " + pPositionId); - apiClient.getExecutedTrades(pPositionId, callBack); + apiClient.getExecutedTrades(pPositionId, callBackFunction); } catch (err) { logError("getExecutedTrades -> Error = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -117,7 +129,7 @@ * Creates a new buy or sell order. * The orderNumber is returned. String */ - function putPosition(pMarket, pType, pRate, pAmountA, pAmountB, callBack) { + function putPosition(pMarket, pType, pRate, pAmountA, pAmountB, callBackFunction) { try { logInfo("putPosition -> Entering function."); @@ -132,16 +144,16 @@ logInfo("putPosition -> pAmountB = " + amountB); if (pType === "buy") { - apiClient.buy(pMarket.assetA, pMarket.assetB, rate, amountB, callBack); + apiClient.buy(pMarket.assetA, pMarket.assetB, rate, amountB, callBackFunction); } else if (pType === "sell") { - apiClient.sell(pMarket.assetA, pMarket.assetB, rate, amountB, callBack); + apiClient.sell(pMarket.assetA, pMarket.assetB, rate, amountB, callBackFunction); } else { logError("putPosition -> pType must be either 'buy' or 'sell'."); - callBack(global.DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } catch (err) { logError("putPosition -> err = " + JSON.stringify(err.stack) || err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -149,16 +161,16 @@ * Move an existing position to the new rate. * The new orderNumber is returned. */ - function movePosition(pPosition, pNewRate, pNewAmountB, callBack) { + function movePosition(pPosition, pNewRate, pNewAmountB, callBackFunction) { try { logInfo("movePosition -> Entering function."); logInfo("movePosition -> pPosition = " + JSON.stringify(pPosition)); logInfo("movePosition -> pNewRate = " + truncDecimals(pNewRate)); - apiClient.movePosition(pPosition, truncDecimals(pNewRate), truncDecimals(pNewAmountB), callBack); + apiClient.movePosition(pPosition, truncDecimals(pNewRate), truncDecimals(pNewAmountB), callBackFunction); } catch (err) { logError("movePosition -> err = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } From 6851b7524c43b79c2243f80a9e147c51212f7d3d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 17:50:41 +0100 Subject: [PATCH 27/36] getTrades Implemented --- Assistant.js | 30 +++++++++++++++--------------- ExchangeAPI.js | 22 ++++++++++++++++------ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Assistant.js b/Assistant.js index 14b7dafec..d8f7e4bf5 100644 --- a/Assistant.js +++ b/Assistant.js @@ -419,12 +419,12 @@ } - function getPositionTradesAtExchange(pPositionId, innerCallBack) { + function getPositionTradesAtExchange(pOrderId, innerCallBack) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> pPositionId = " + pPositionId); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> pOrderId = " + pOrderId); } /* @@ -437,7 +437,7 @@ case "Live": { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> Live Mode Detected."); } - exchangeAPI.getExecutedTrades(pPositionId, onResponse); + exchangeAPI.getOrder(pOrderId, bot.market, onResponse); return; } @@ -452,18 +452,18 @@ for (let i = 0; i < context.executionContext.positions.length; i++) { - let thisPosition = context.executionContext.positions[i]; + let thisOrder = context.executionContext.positions[i]; - if (thisPosition.id === pPositionId) { + if (thisOrder.id === pOrderId) { let feeRate = 0.002; // Default backtesting fee simulation let trade = { id: Math.trunc(Math.random(1) * 1000000), - type: thisPosition.type, - rate: thisPosition.rate.toString(), - amountA: thisObject.truncDecimals(thisPosition.amountA).toString(), - amountB: thisObject.truncDecimals(thisPosition.amountB).toString(), + type: thisOrder.type, + rate: thisOrder.rate.toString(), + amountA: thisObject.truncDecimals(thisOrder.amountA).toString(), + amountB: thisObject.truncDecimals(thisOrder.amountB).toString(), fee: thisObject.truncDecimals(feeRate).toString(), date: (new Date()).valueOf() } @@ -890,11 +890,11 @@ } } - function onResponse(err, pPositionId) { + function onResponse(err, pOrderId) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> onResponse -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> onResponse -> pPositionId = " + pPositionId); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> onResponse -> pOrderId = " + pOrderId); } switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. @@ -902,7 +902,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> onResponse -> Execution finished well."); } let position = { - id: pPositionId, + id: pOrderId, type: pType, rate: pRate, amountA: pAmountA, @@ -1010,11 +1010,11 @@ } } - function onResponse(err, pPositionId) { + function onResponse(err, pOrderId) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> onResponse -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> onResponse -> pPositionId = " + pPositionId); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> onResponse -> pOrderId = " + pOrderId); } switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. @@ -1022,7 +1022,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> onResponse -> Execution finished well."); } let newPosition = { - id: pPositionId, + id: pOrderId, type: pPosition.type, rate: pNewRate, amountA: pPosition.amountA, diff --git a/ExchangeAPI.js b/ExchangeAPI.js index b13e336a5..5a90c762d 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -9,7 +9,7 @@ initialize: initialize, getTicker: getTicker, getOpenOrders: getOpenOrders, - getExecutedTrades: getExecutedTrades, + getOrder: getOrder, putPosition: putPosition, movePosition: movePosition, getMaxDecimalPositions: getMaxDecimalPositions @@ -101,7 +101,7 @@ openOrders = await(exchange.fetchOpenOrders (symbol)) callBackFunction(global.DEFAULT_OK_RESPONSE, openOrders) } else { - logError("getTicker -> Exchange does not support fetchOpenOrders command."); + logError("getOpenOrders -> Exchange does not support fetchOpenOrders command."); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } @@ -115,12 +115,22 @@ * Returns the trades for a given order number. * The object returned is an array of trades */ - function getExecutedTrades(pPositionId, callBackFunction) { + function getOrder(orderId, market, callBackFunction) { try { - logInfo("getExecutedTrades -> Entering function. pPositionId = " + pPositionId); - apiClient.getExecutedTrades(pPositionId, callBackFunction); + logInfo("getOrder -> Entering function. orderId = " + orderId); + + const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset + let order + + if (exchange.has['fetchOrder']) { + order = await(exchange.fetchOpenOrders(orderId, symbol)) + callBackFunction(global.DEFAULT_OK_RESPONSE, order) + } else { + logError("getOrder -> Exchange does not support fetchOrder command."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } } catch (err) { - logError("getExecutedTrades -> Error = " + err.message); + logError("getOrder -> Error = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } From 741d1e14c8017d40eb1632fbadc2f22af6bd9311 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 17:52:17 +0100 Subject: [PATCH 28/36] refactoring --- Assistant.js | 52 ++++++++++++++++++++++---------------------- ExchangeAPI.js | 20 ++++++++--------- TradingSimulation.js | 4 ++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Assistant.js b/Assistant.js index d8f7e4bf5..5bcaaf4b0 100644 --- a/Assistant.js +++ b/Assistant.js @@ -11,7 +11,7 @@ let thisObject = { dataDependencies: undefined, initialize: initialize, - putPosition: putPosition, + createOrder: createOrder, movePosition: movePosition, getPositions: getPositions, getBalance: getBalance, @@ -804,10 +804,10 @@ } } - function putPosition(pType, pRate, pAmountA, pAmountB, callBackFunction) { + function createOrder(pType, pRate, pAmountA, pAmountB, callBackFunction) { try { - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> Entering function."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> Entering function."); } /* Removing extra decimals. */ @@ -815,10 +815,10 @@ pAmountA = thisObject.truncDecimals(pAmountA); pAmountB = thisObject.truncDecimals(pAmountB); - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pType = " + pType); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pRate = " + pRate); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountA = " + pAmountA); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountB = " + pAmountB); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> pType = " + pType); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> pRate = " + pRate); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> pAmountA = " + pAmountA); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> pAmountB = " + pAmountB); } /* Validations that the limits are not surpassed. */ @@ -826,9 +826,9 @@ if (pAmountA > thisObject.truncDecimals(context.executionContext.availableBalance.baseAsset)) { - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountA is grater than the Available Balance."); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountA = " + pAmountA); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.baseAsset)); + logger.write(MODULE_NAME, "[ERROR] createOrder -> Input Validations -> pAmountA is grater than the Available Balance."); + logger.write(MODULE_NAME, "[ERROR] createOrder -> Input Validations -> pAmountA = " + pAmountA); + logger.write(MODULE_NAME, "[ERROR] createOrder -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.baseAsset)); let err = { result: global.DEFAULT_FAIL_RESPONSE.result, @@ -844,9 +844,9 @@ if (pAmountB > thisObject.truncDecimals(context.executionContext.availableBalance.quotedAsset)) { - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountB is grater than the Available Balance."); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountB = " + pAmountB); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.quotedAsset)); + logger.write(MODULE_NAME, "[ERROR] createOrder -> Input Validations -> pAmountB is grater than the Available Balance."); + logger.write(MODULE_NAME, "[ERROR] createOrder -> Input Validations -> pAmountB = " + pAmountB); + logger.write(MODULE_NAME, "[ERROR] createOrder -> Input Validations -> Available Balance = " + thisObject.truncDecimals(context.executionContext.availableBalance.quotedAsset)); let err = { result: global.DEFAULT_FAIL_RESPONSE.result, @@ -864,7 +864,7 @@ case "Live": { - exchangeAPI.putPosition(bot.market, pType, pRate, pAmountA, pAmountB, onResponse); + exchangeAPI.createOrder(bot.market, pType, pRate, pAmountA, pAmountB, onResponse); return; } @@ -872,19 +872,19 @@ if (pRate !== marketRate) { - logger.write(MODULE_NAME, "[WARNING] putPosition -> Input Validations -> putPosition Rate can is different to marketRate while in Backtesting Mode. "); + logger.write(MODULE_NAME, "[WARNING] createOrder -> Input Validations -> createOrder Rate can is different to marketRate while in Backtesting Mode. "); //onResponse(global.DEFAULT_FAIL_RESPONSE, positionId); } let positionId = Math.trunc(Math.random(1) * 1000000); - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> Simulating Exchange Response -> orderId = " + positionId); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> Simulating Exchange Response -> orderId = " + positionId); } onResponse(global.DEFAULT_OK_RESPONSE, positionId); return; } default: { - logger.write(MODULE_NAME, "[ERROR] putPosition -> Unexpected bot.startMode."); - logger.write(MODULE_NAME, "[ERROR] putPosition -> bot.startMode = " + bot.startMode); + logger.write(MODULE_NAME, "[ERROR] createOrder -> Unexpected bot.startMode."); + logger.write(MODULE_NAME, "[ERROR] createOrder -> bot.startMode = " + bot.startMode); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -893,13 +893,13 @@ function onResponse(err, pOrderId) { try { - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> onResponse -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> onResponse -> pOrderId = " + pOrderId); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> onResponse -> Entering function."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> onResponse -> pOrderId = " + pOrderId); } switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> onResponse -> Execution finished well."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> onResponse -> Execution finished well."); } let position = { id: pOrderId, @@ -944,25 +944,25 @@ } break; case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write(MODULE_NAME, "[ERROR] putPosition -> onResponse -> Retry Later. Requesting Execution Retry."); + logger.write(MODULE_NAME, "[ERROR] createOrder -> onResponse -> Retry Later. Requesting Execution Retry."); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } break; case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write(MODULE_NAME, "[ERROR] putPosition -> onResponse -> Operation Failed. Aborting the process."); + logger.write(MODULE_NAME, "[ERROR] createOrder -> onResponse -> Operation Failed. Aborting the process."); callBackFunction(err); return; } break; } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] putPosition -> onResponse -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] createOrder -> onResponse -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] putPosition -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] createOrder -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -997,7 +997,7 @@ case "Backtest": { let positionId = Math.trunc(Math.random(1) * 1000000); - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> Simulating Exchange Response -> orderId = " + positionId); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> Simulating Exchange Response -> orderId = " + positionId); } onResponse(global.DEFAULT_OK_RESPONSE, positionId); return; } diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 5a90c762d..e3ac34b6b 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -10,7 +10,7 @@ getTicker: getTicker, getOpenOrders: getOpenOrders, getOrder: getOrder, - putPosition: putPosition, + createOrder: createOrder, movePosition: movePosition, getMaxDecimalPositions: getMaxDecimalPositions }; @@ -139,30 +139,30 @@ * Creates a new buy or sell order. * The orderNumber is returned. String */ - function putPosition(pMarket, pType, pRate, pAmountA, pAmountB, callBackFunction) { + function createOrder(pMarket, pType, pRate, pAmountA, pAmountB, callBackFunction) { try { - logInfo("putPosition -> Entering function."); + logInfo("createOrder -> Entering function."); let rate = truncDecimals(pRate); let amountA = truncDecimals(pAmountA); let amountB = truncDecimals(pAmountB); - logInfo("putPosition -> pMarket = " + pMarket.assetA + "_" + pMarket.assetB); - logInfo("putPosition -> pType = " + pType); - logInfo("putPosition -> pRate = " + rate); - logInfo("putPosition -> pAmountA = " + amountA); - logInfo("putPosition -> pAmountB = " + amountB); + logInfo("createOrder -> pMarket = " + pMarket.assetA + "_" + pMarket.assetB); + logInfo("createOrder -> pType = " + pType); + logInfo("createOrder -> pRate = " + rate); + logInfo("createOrder -> pAmountA = " + amountA); + logInfo("createOrder -> pAmountB = " + amountB); if (pType === "buy") { apiClient.buy(pMarket.assetA, pMarket.assetB, rate, amountB, callBackFunction); } else if (pType === "sell") { apiClient.sell(pMarket.assetA, pMarket.assetB, rate, amountB, callBackFunction); } else { - logError("putPosition -> pType must be either 'buy' or 'sell'."); + logError("createOrder -> pType must be either 'buy' or 'sell'."); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } catch (err) { - logError("putPosition -> err = " + JSON.stringify(err.stack) || err.message); + logError("createOrder -> err = " + JSON.stringify(err.stack) || err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/TradingSimulation.js b/TradingSimulation.js index 0573fe091..156202441 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -2066,7 +2066,7 @@ } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> Ready to put order."); } - assistant.putPosition(positionDirection, openPositionRate, amountA, amountB, onOrderPut) + assistant.createOrder(positionDirection, openPositionRate, amountA, amountB, onOrderPut) function onOrderPut(err) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> Entering function."); } @@ -2284,7 +2284,7 @@ } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> About to close position at the exchange."); } - assistant.putPosition(positionDirection, closePositionRate, amountA, amountB, onOrderPut) + assistant.createOrder(positionDirection, closePositionRate, amountA, amountB, onOrderPut) function onOrderPut(err) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderPut -> Entering function."); } From 3774ef12c6f479a9607ff225b2b025c89f4356c2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 18:14:50 +0100 Subject: [PATCH 29/36] createOrder Implemented --- Assistant.js | 125 ++----------------------------------------------- ExchangeAPI.js | 77 +++++++++--------------------- 2 files changed, 24 insertions(+), 178 deletions(-) diff --git a/Assistant.js b/Assistant.js index 5bcaaf4b0..fcc4ae73a 100644 --- a/Assistant.js +++ b/Assistant.js @@ -12,7 +12,6 @@ dataDependencies: undefined, initialize: initialize, createOrder: createOrder, - movePosition: movePosition, getPositions: getPositions, getBalance: getBalance, getAvailableBalance: getAvailableBalance, @@ -890,11 +889,11 @@ } } - function onResponse(err, pOrderId) { + function onResponse(err, order) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> onResponse -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> onResponse -> pOrderId = " + pOrderId); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> onResponse -> order.id = " + order.id); } switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. @@ -902,7 +901,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> onResponse -> Execution finished well."); } let position = { - id: pOrderId, + id: order.id, type: pType, rate: pRate, amountA: pAmountA, @@ -967,124 +966,6 @@ } } - function movePosition(pPosition, pNewRate, callBackFunction) { - - try { - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> pPosition = " + JSON.stringify(pPosition)); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> pNewRate = " + pNewRate); } - - /* Removing extra decimals. */ - pNewRate = thisObject.truncDecimals(pNewRate); - - let newAmountB; - if (pPosition.type === "buy") { - newAmountB = thisObject.truncDecimals(pPosition.amountA / pNewRate); - } else { - newAmountB = pPosition.amountB; - } - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> newAmountB = " + newAmountB); } - - switch (bot.startMode) { - - case "Live": { - - exchangeAPI.movePosition(pPosition, pNewRate, newAmountB, onResponse); - return; - } - - case "Backtest": { - - let positionId = Math.trunc(Math.random(1) * 1000000); - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createOrder -> Simulating Exchange Response -> orderId = " + positionId); } - onResponse(global.DEFAULT_OK_RESPONSE, positionId); - return; - } - - default: { - logger.write(MODULE_NAME, "[ERROR] movePosition -> Unexpected bot.startMode."); - logger.write(MODULE_NAME, "[ERROR] movePosition -> bot.startMode = " + bot.startMode); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - function onResponse(err, pOrderId) { - - try { - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> onResponse -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> onResponse -> pOrderId = " + pOrderId); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> onResponse -> Execution finished well."); } - - let newPosition = { - id: pOrderId, - type: pPosition.type, - rate: pNewRate, - amountA: pPosition.amountA, - amountB: newAmountB, - date: (bot.processDatetime.valueOf()), - status: "open", - trades: [] - }; - - let oldPosition = JSON.parse(JSON.stringify(pPosition)); - - /* We need to update the position we have on file. */ - - for (let i = 0; i < context.executionContext.positions.length; i++) { - - if (context.executionContext.positions[i].id === pPosition.id) { - - context.executionContext.positions[i] = newPosition; - - break; - } - } - - let newTransaction = { - type: "movePosition", - oldPosition: oldPosition, - newPosition: newPosition - }; - - context.executionContext.transactions.push(newTransaction); - - context.newHistoryRecord.movedPositions++; - - recalculateRateAverages(); - - callBackFunction(global.DEFAULT_OK_RESPONSE, newPosition); - } - break; - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write(MODULE_NAME, "[ERROR] movePosition -> onResponse -> Retry Later. Requesting Execution Retry."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - } - break; - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write(MODULE_NAME, "[ERROR] movePosition -> onResponse -> Operation Failed. Aborting the process."); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - break; - } - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] movePosition -> onResponse -> err = " + err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] movePosition -> err = " + err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - function getPublicTradeHistory(baseAsset, quotedAsset, startTime, endTime, callback) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTradeHistory -> Entering function."); } diff --git a/ExchangeAPI.js b/ExchangeAPI.js index e3ac34b6b..1944ec123 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -11,7 +11,6 @@ getOpenOrders: getOpenOrders, getOrder: getOrder, createOrder: createOrder, - movePosition: movePosition, getMaxDecimalPositions: getMaxDecimalPositions }; @@ -53,18 +52,9 @@ } function getMaxDecimalPositions() { - + return 8 } - /* - * Returns the price for a given pair of assets. - * The object returned is an array of trades: - * ticker = { - * bid, Number - * ask, Number - * last Number - * }; - */ async function getTicker(market, callBackFunction) { try { logInfo("getTicker -> Entering function."); @@ -85,11 +75,6 @@ } } - /* - * Returns the open positions ath the exchange for a given market and user account. - * The object returned is an array of positions - * - */ async function getOpenOrders(market, callBackFunction) { try { logInfo("getOpenOrders -> Entering function. market = " + JSON.stringify(market)); @@ -111,10 +96,6 @@ } } - /* - * Returns the trades for a given order number. - * The object returned is an array of trades - */ function getOrder(orderId, market, callBackFunction) { try { logInfo("getOrder -> Entering function. orderId = " + orderId); @@ -135,56 +116,40 @@ } } - /* - * Creates a new buy or sell order. - * The orderNumber is returned. String - */ - function createOrder(pMarket, pType, pRate, pAmountA, pAmountB, callBackFunction) { + function createOrder(market, side, pRate, amount, price, callBackFunction) { try { logInfo("createOrder -> Entering function."); - let rate = truncDecimals(pRate); - let amountA = truncDecimals(pAmountA); - let amountB = truncDecimals(pAmountB); + const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset - logInfo("createOrder -> pMarket = " + pMarket.assetA + "_" + pMarket.assetB); - logInfo("createOrder -> pType = " + pType); + logInfo("createOrder -> market = " + market.assetA + "_" + market.assetB); + logInfo("createOrder -> side = " + side); logInfo("createOrder -> pRate = " + rate); - logInfo("createOrder -> pAmountA = " + amountA); - logInfo("createOrder -> pAmountB = " + amountB); + logInfo("createOrder -> amount = " + amount); + logInfo("createOrder -> price = " + price); - if (pType === "buy") { - apiClient.buy(pMarket.assetA, pMarket.assetB, rate, amountB, callBackFunction); - } else if (pType === "sell") { - apiClient.sell(pMarket.assetA, pMarket.assetB, rate, amountB, callBackFunction); - } else { - logError("createOrder -> pType must be either 'buy' or 'sell'."); + if (side !== "buy" && side !== "sell") { + logError("createOrder -> side must be either 'buy' or 'sell'."); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } + + let type = 'market' + let order + + if (exchange.has['createOrder']) { + order = await(exchange.createOrder(symbol, type, side, amount, price)) + callBackFunction(global.DEFAULT_OK_RESPONSE, order) + } else { + logError("createOrder -> Exchange does not support createOrder command."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } catch (err) { logError("createOrder -> err = " + JSON.stringify(err.stack) || err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } - /* - * Move an existing position to the new rate. - * The new orderNumber is returned. - */ - function movePosition(pPosition, pNewRate, pNewAmountB, callBackFunction) { - try { - logInfo("movePosition -> Entering function."); - logInfo("movePosition -> pPosition = " + JSON.stringify(pPosition)); - logInfo("movePosition -> pNewRate = " + truncDecimals(pNewRate)); - - apiClient.movePosition(pPosition, truncDecimals(pNewRate), truncDecimals(pNewAmountB), callBackFunction); - } catch (err) { - logError("movePosition -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - - function logInfo(message) { if (LOG_INFO === true) { logger.write(MODULE_NAME, '[INFO] ' + message) } } From 51e0de9e1aa34708a6c7ff45ac0aa89f17a51157 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 20:15:26 +0100 Subject: [PATCH 30/36] Several bug fixes at session level --- Assistant.js | 40 +++++++++++++++++++++++----------------- Commons.js | 2 +- ExchangeAPI.js | 8 ++++---- Session.js | 36 +++++++++++++++++++++++------------- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/Assistant.js b/Assistant.js index fcc4ae73a..9a98b1cbd 100644 --- a/Assistant.js +++ b/Assistant.js @@ -469,7 +469,10 @@ trades.push(trade); - onResponse(global.DEFAULT_OK_RESPONSE, trades); + let order = { + trades: trades + } + onResponse(global.DEFAULT_OK_RESPONSE, order); return; } @@ -488,7 +491,7 @@ } } - function onResponse(err, pTrades) { + function onResponse(err, order) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> onResponse -> Entering function."); } @@ -496,7 +499,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> getPositionTradesAtExchange -> onResponse -> Execution finished well."); } - innerCallBack(pTrades); + innerCallBack(order); } break; case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -523,13 +526,14 @@ } } - function confirmOrderWasExecuted(pTrades) { + function confirmOrderWasExecuted(order) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> pTrades = " + JSON.stringify(pTrades)); } + if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasExecuted -> trades = " + JSON.stringify(trades)); } + let trades = order.trades /* To confirm everything is ok, we will add all the amounts on trades asociated to the order and @@ -542,8 +546,8 @@ let sumQuotedAsset = 0; let sumRate = 0; - for (let k = 0; k < pTrades.length; k++) { - let trade = pTrades[k]; + for (let k = 0; k < trades.length; k++) { + let trade = trades[k]; sumBaseAsset = sumBaseAsset + thisObject.truncDecimals(trade.amountA); sumQuotedAsset = sumQuotedAsset + thisObject.truncDecimals(trade.amountB); sumRate = sumRate + thisObject.truncDecimals(trade.rate); @@ -572,12 +576,12 @@ position.status = "executed"; if (position.type === "sell") { - context.newHistoryRecord.sellExecRate = sumRate / pTrades.length; + context.newHistoryRecord.sellExecRate = sumRate / trades.length; } else { - context.newHistoryRecord.buyExecRate = sumRate / pTrades.length; + context.newHistoryRecord.buyExecRate = sumRate / trades.length; } - applyTradesToContext(pTrades); + applyTradesToContext(trades); let newTransaction = { type: position.type + " executed", @@ -597,11 +601,13 @@ } } - function confirmOrderWasPartiallyExecuted(pTrades) { + function confirmOrderWasPartiallyExecuted(trades) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] ordersExecutionCheck -> loopBody -> confirmOrderWasPartiallyExecuted -> Entering function."); } + let trades = order.trades + /* To confirm everything is ok, we will add all the amounts on trades plus the remaining amounts @@ -613,8 +619,8 @@ let sumBaseAsset = 0; let sumQuotedAsset = 0; - for (let k = 0; k < pTrades.length; k++) { - let trade = pTrades[k]; + for (let k = 0; k < trades.length; k++) { + let trade = trades[k]; sumBaseAsset = sumBaseAsset + thisObject.truncDecimals(trade.amountA); sumQuotedAsset = sumQuotedAsset + thisObject.truncDecimals(trade.amountB); } @@ -663,7 +669,7 @@ position.amountB = exchangePosition.amountB; position.date = (new Date(exchangePosition.date)).valueOf(); - applyTradesToContext(pTrades); + applyTradesToContext(trades); let newTransaction = { type: position.type + " partially executed", @@ -683,7 +689,7 @@ } } - function applyTradesToContext(pTrades) { + function applyTradesToContext(trades) { try { @@ -691,9 +697,9 @@ /* Here we apply the trades that already happened at the exchange to the balance and available balance of the bot. We also calculate its profits. */ - for (k = 0; k < pTrades.length; k++) { + for (k = 0; k < trades.length; k++) { - let trade = pTrades[k]; + let trade = trades[k]; position.trades.push(trade); diff --git a/Commons.js b/Commons.js index aaf3d3dcf..5ad2fb509 100644 --- a/Commons.js +++ b/Commons.js @@ -71,7 +71,7 @@ return } if (outputDatasetNode.referenceParent.parentNode.dataBuilding === undefined) { - logger.write(MODULE_NAME, "[WARN] start -> Product Definition without a Data Building Procedure. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); + logger.write(MODULE_NAME, "[WARN] start -> Product Definition " + outputDatasetNode.referenceParent.parentNode.name + " without a Data Building Procedure. Product Definition = " + JSON.stringify(outputDatasetNode.referenceParent.parentNode)); } if (outputDatasetNode.referenceParent.code.codeName === undefined) { logger.write(MODULE_NAME, "[ERROR] start -> Dataset witn no codeName defined. Product Dataset = " + JSON.stringify(outputDatasetNode.referenceParent)); diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 1944ec123..a48e18aac 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -96,7 +96,7 @@ } } - function getOrder(orderId, market, callBackFunction) { + async function getOrder(orderId, market, callBackFunction) { try { logInfo("getOrder -> Entering function. orderId = " + orderId); @@ -116,7 +116,7 @@ } } - function createOrder(market, side, pRate, amount, price, callBackFunction) { + async function createOrder(market, side, price, cost, amount, callBackFunction) { try { logInfo("createOrder -> Entering function."); @@ -124,7 +124,7 @@ logInfo("createOrder -> market = " + market.assetA + "_" + market.assetB); logInfo("createOrder -> side = " + side); - logInfo("createOrder -> pRate = " + rate); + logInfo("createOrder -> cost = " + cost); logInfo("createOrder -> amount = " + amount); logInfo("createOrder -> price = " + price); @@ -137,7 +137,7 @@ let order if (exchange.has['createOrder']) { - order = await(exchange.createOrder(symbol, type, side, amount, price)) + order = await(exchange.createOrder(symbol, type, side, amount)) callBackFunction(global.DEFAULT_OK_RESPONSE, order) } else { logError("createOrder -> Exchange does not support createOrder command."); diff --git a/Session.js b/Session.js index 0aaf44d55..359548ea9 100644 --- a/Session.js +++ b/Session.js @@ -2,6 +2,7 @@ const MODULE_NAME = "Session" const FULL_LOG = true; + const ONE_YEAR_IN_MILISECONDS = 365 * 24 * 60 * 60 * 1000 let thisObject = { initialize: initialize @@ -97,6 +98,17 @@ bot.STOP_SESSION = true } + function checkDatetimes() { + if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) { + if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Overriding initialDatetime with present datetime because " + bot.VALUES_TO_USE.timeRange.initialDatetime + " is in the past."); } + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() + } + if (bot.VALUES_TO_USE.timeRange.finalDatetime.valueOf() < (new Date()).valueOf()) { + if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Overriding finalDatetime with present datetime plus one year because " + bot.VALUES_TO_USE.timeRange.finalDatetime + " is in the past."); } + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date() + ONE_YEAR_IN_MILISECONDS + } + } + function startBackTesting(message) { bot.startMode = "Backtest" if (bot.VALUES_TO_USE.timeRange.finalDatetime.valueOf() > (new Date()).valueOf()) { @@ -117,9 +129,7 @@ } bot.startMode = "Live" - if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() - } + checkDatetimes() bot.resumeExecution = false; bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) bot.hasTheBotJustStarted = true @@ -135,9 +145,7 @@ } bot.startMode = "Live" - if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() - } + checkDatetimes() bot.resumeExecution = false; bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) bot.hasTheBotJustStarted = true @@ -164,9 +172,7 @@ function startPaperTrading(message) { bot.startMode = "Backtest" - if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() - } + checkDatetimes() bot.resumeExecution = false; bot.hasTheBotJustStarted = true bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) @@ -204,7 +210,7 @@ } /* Session Type Dependant Default Values */ - const ONE_YEAR_IN_MILISECONDS = 365 * 24 * 60 * 60 * 1000 + switch (bot.SESSION.type) { case 'Backtesting Session': { bot.VALUES_TO_USE.timeRange.initialDatetime = new Date((new Date()).valueOf() - ONE_YEAR_IN_MILISECONDS) @@ -247,6 +253,8 @@ bot.VALUES_TO_USE.baseAsset = code.codeName; } + code = tradingSystem.parameters.baseAsset.code + if (bot.VALUES_TO_USE.baseAsset === 'BTC') { if (code.initialBalance !== undefined) { bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; @@ -347,15 +355,17 @@ /* Base Asset and Initial Balances. */ { if (bot.SESSION.parameters.baseAsset !== undefined) { - if (tradingSystem.parameters.baseAsset.referenceParent !== undefined) { - if (tradingSystem.parameters.baseAsset.referenceParent.referenceParent !== undefined) { + if (bot.SESSION.parameters.baseAsset.referenceParent !== undefined) { + if (bot.SESSION.parameters.baseAsset.referenceParent.referenceParent !== undefined) { - let code = tradingSystem.parameters.baseAsset.referenceParent.referenceParent.code + let code = bot.SESSION.parameters.baseAsset.referenceParent.referenceParent.code if (code.codeName !== undefined) { bot.VALUES_TO_USE.baseAsset = code.codeName; } + code = bot.SESSION.parameters.baseAsset.code + if (bot.VALUES_TO_USE.baseAsset === 'BTC') { if (code.initialBalance !== undefined) { bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; From e20df555c6cd2e76d40714bb5089b53e900433ed Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 7 Feb 2020 08:20:41 +0100 Subject: [PATCH 31/36] name fixed --- ExchangeAPI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExchangeAPI.js b/ExchangeAPI.js index a48e18aac..54c3c52e7 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -104,7 +104,7 @@ let order if (exchange.has['fetchOrder']) { - order = await(exchange.fetchOpenOrders(orderId, symbol)) + order = await (exchange.fetchOrder(orderId, symbol)) callBackFunction(global.DEFAULT_OK_RESPONSE, order) } else { logError("getOrder -> Exchange does not support fetchOrder command."); From 4b40d87925b971a29a7a7ad084d15961dc17b038 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 7 Feb 2020 09:18:21 +0100 Subject: [PATCH 32/36] removing Assistant AND Context --- MultiPeriod.js | 4 +- TradingBot.js | 8 +- TradingBotProcessMainLoop.js | 280 +++-------------------------------- TradingSimulation.js | 21 ++- 4 files changed, 37 insertions(+), 276 deletions(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index 94a1cd318..2ad6c0757 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -29,7 +29,7 @@ return thisObject; - function initialize(pProcessConfig, pStatusDependencies, pDataDependencies, pAssistant, callBackFunction) { + function initialize(pProcessConfig, pStatusDependencies, pDataDependencies, exchangeAPI, callBackFunction) { try { @@ -63,7 +63,7 @@ let USER_BOT_MODULE = require("./TradingBot") botInstance = USER_BOT_MODULE.newTradingBot(bot, logger, UTILITIES, FILE_STORAGE); - botInstance.initialize(pAssistant, callBackFunction); + botInstance.initialize(exchangeAPI, callBackFunction); } catch (err) { logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); diff --git a/TradingBot.js b/TradingBot.js index e969a90fc..3129df6d7 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -18,7 +18,7 @@ const COMMONS = require('./Commons.js'); let commons = COMMONS.newCommons(bot, logger, UTILITIES, FILE_STORAGE); - let assistant; + let exchangeAPI; return thisObject; @@ -29,7 +29,7 @@ commons = undefined } - function initialize(pAssistant, callBackFunction) { + function initialize(pExchangeAPI, callBackFunction) { try { @@ -38,7 +38,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } - assistant = pAssistant; + exchangeAPI = pExchangeAPI; callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { @@ -130,7 +130,7 @@ timeFrameLabel, currentDay, interExecutionMemory, - assistant, + exchangeAPI, writeFiles, callBackFunction) diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 0aac6246a..85ae4182d 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -146,8 +146,6 @@ const UTILITIES = require(ROOT_DIR + 'CloudUtilities'); const EXCHANGE_API = require(ROOT_DIR + 'ExchangeAPI'); - const CONTEXT = require(ROOT_DIR + 'Context'); - const ASSISTANT = require(ROOT_DIR + 'Assistant'); const STATUS_REPORT = require(ROOT_DIR + 'StatusReport'); const STATUS_DEPENDENCIES = require(ROOT_DIR + 'StatusDependencies'); const DATA_DEPENDENCIES = require(ROOT_DIR + 'DataDependencies'); @@ -443,7 +441,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeDataDependencies -> onInizialized -> Execution finished well."); } - initializeContext(); + initializeExchangeAPI(); return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -500,81 +498,6 @@ } } - function initializeContext() { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeContext -> Entering function."); } - - context = CONTEXT.newContext(bot, logger, UTILITIES); - context.initialize(statusDependencies, onInizialized); - - function onInizialized(err) { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeContext -> onInizialized -> Entering function."); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeContext -> onInizialized -> Execution finished well."); } - initializeExchangeAPI(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeContext -> onInizialized -> Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - sessionStopped() - processStopped() - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Operation Failed. Aborting the process."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err = " + err.message); - - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - function initializeExchangeAPI() { try { @@ -594,7 +517,25 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeExchangeAPI -> onInizialized -> Execution finished well."); } - initializeAssistant(); + + switch (processConfig.framework.name) { + case 'Multi-Period': { + processFramework = MULTI_PERIOD.newMultiPeriod(bot, logger, UTILITIES, USER_BOT_MODULE, USER_BOT_COMMONS); + intitializeProcessFramework(); + break; + } + default: { + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Process Framework not Supported."); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Process Framework Name = " + processConfig.framework.name); + logger.persist(); + clearInterval(fixedTimeLoopIntervalHandle); + clearTimeout(nextLoopTimeoutHandle); + clearTimeout(checkLoopHealthHandle); + bot.enableCheckLoopHealth = false; + callBackFunction(err); + return; + } + } return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -651,112 +592,13 @@ } } - function initializeAssistant() { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeAssistant -> Entering function."); } - - assistant = ASSISTANT.newAssistant(bot, logger, UTILITIES); - assistant.initialize(context, exchangeAPI, dataDependencies, onInizialized); - - function onInizialized(err) { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeAssistant -> onInizialized -> Entering function."); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeAssistant -> onInizialized -> Execution finished well."); } - - /* If the process is configured to run inside a framework, we continue there, otherwise we run the bot directly. */ - if (processConfig.framework === undefined) { - initializeUserBot(); - return; - } - - switch (processConfig.framework.name) { - case 'Multi-Period': { - processFramework = MULTI_PERIOD.newMultiPeriod(bot, logger, UTILITIES, USER_BOT_MODULE, USER_BOT_COMMONS); - intitializeProcessFramework(); - break; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Process Framework not Supported."); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Process Framework Name = " + processConfig.framework.name); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - } - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeAssistant -> onInizialized -> Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - sessionStopped() - processStopped() - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Operation Failed. Aborting the process."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err = " + err.message); - - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - function intitializeProcessFramework() { try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> intitializeProcessFramework -> Entering function."); } - processFramework.initialize(processConfig, statusDependencies, dataDependencies, assistant, onInizialized); + processFramework.initialize(processConfig, statusDependencies, dataDependencies, exchangeAPI, onInizialized); function onInizialized(err) { @@ -859,7 +701,7 @@ case global.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessFramework -> onFinished -> Execution finished well."); nextWaitTime = 'Normal'; - saveContext(); + raiseEventsProcessOutput() return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -943,84 +785,6 @@ } } - function saveContext() { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> saveContext -> Entering function."); } - - context.saveThemAll(onFinished); - - function onFinished(err) { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> saveContext -> onFinished -> Entering function."); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> saveContext -> onFinished -> Execution finished well."); } - raiseEventsProcessOutput() - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Can not retry at this point."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - sessionStopped() - processStopped() - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Operation Failed. Aborting the process."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err = " + err.message); - - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> err = "+ err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - function raiseEventsProcessOutput() { try { diff --git a/TradingSimulation.js b/TradingSimulation.js index 156202441..de67e9093 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -39,7 +39,7 @@ timeFrameLabel, currentDay, interExecutionMemory, - assistant, + exchangeAPI, callback, callBackFunction) { @@ -554,8 +554,6 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Candle Begin @ " + (new Date(candle.begin)).toLocaleString()) } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Candle End @ " + (new Date(candle.end)).toLocaleString()) } - /* Assistant Info */ - let ticker = { bid: candle.close, ask: candle.close, @@ -1995,7 +1993,7 @@ /* Checking the status of current positions */ - let positions = assistant.getPositions(); + let positions = exchangeAPI.getPositions(); if (positions.length > 0) { let position = positions[positions.length - 1] // We are allways checking the the last position is not open. if (position.status === 'open') { @@ -2006,7 +2004,6 @@ } /* Mechanism to avoid putting the same order over and over again at different executions of the simulation engine. */ - if (interExecutionMemory.executionContext !== undefined) { if (interExecutionMemory.executionContext.periods !== undefined) { if (periods <= interExecutionMemory.executionContext.periods) { @@ -2034,7 +2031,7 @@ let amountA let amountB let positionDirection - let availableBalance = assistant.getAvailableBalance() + let availableBalance = exchangeAPI.getAvailableBalance() if (bot.VALUES_TO_USE.baseAsset === 'BTC') { positionDirection = "sell" @@ -2044,7 +2041,7 @@ amountA = tradePositionSize * openPositionRate amountB = tradePositionSize - if (amountB > availableBalance.quotedAsset) { // The assistant know what fees were paid. + if (amountB > availableBalance.quotedAsset) { // The exchangeAPI know what fees were paid. amountB = availableBalance.quotedAsset } } else { @@ -2055,7 +2052,7 @@ amountA = tradePositionSize amountB = tradePositionSize / openPositionRate - if (amountA > availableBalance.baseAsset) { // The assistant know what fees were paid. + if (amountA > availableBalance.baseAsset) { // The exchangeAPI know what fees were paid. amountA = availableBalance.baseAsset } } @@ -2066,7 +2063,7 @@ } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> Ready to put order."); } - assistant.createOrder(positionDirection, openPositionRate, amountA, amountB, onOrderPut) + exchangeAPI.createOrder(positionDirection, openPositionRate, amountA, amountB, onOrderPut) function onOrderPut(err) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> Entering function."); } @@ -2232,7 +2229,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> putClosingOrder -> Entering function."); } /* Checking the status of current positions */ - let positions = assistant.getPositions(); + let positions = exchangeAPI.getPositions(); if (positions.length > 0) { let position = positions[positions.length - 1] // We are allways checking the the last position is not open. if (position.status === 'open') { @@ -2258,7 +2255,7 @@ let amountA let amountB let positionDirection - let availableBalance = assistant.getAvailableBalance() + let availableBalance = exchangeAPI.getAvailableBalance() if (bot.VALUES_TO_USE.baseAsset === 'BTC') { positionDirection = "buy" @@ -2284,7 +2281,7 @@ } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> About to close position at the exchange."); } - assistant.createOrder(positionDirection, closePositionRate, amountA, amountB, onOrderPut) + exchangeAPI.createOrder(positionDirection, closePositionRate, amountA, amountB, onOrderPut) function onOrderPut(err) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderPut -> Entering function."); } From a8950c6b4cdbaec3845c959b3e1896f6e083d5c8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 7 Feb 2020 11:31:48 +0100 Subject: [PATCH 33/36] Ready implementation to trade live --- Session.js | 4 +- TradingSimulation.js | 130 +++++++++++++++++++++---------------------- 2 files changed, 65 insertions(+), 69 deletions(-) diff --git a/Session.js b/Session.js index 359548ea9..3d61e42aa 100644 --- a/Session.js +++ b/Session.js @@ -255,7 +255,7 @@ code = tradingSystem.parameters.baseAsset.code - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { if (code.initialBalance !== undefined) { bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; bot.VALUES_TO_USE.initialBalanceB = 0 @@ -366,7 +366,7 @@ code = bot.SESSION.parameters.baseAsset.code - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { if (code.initialBalance !== undefined) { bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; bot.VALUES_TO_USE.initialBalanceB = 0 diff --git a/TradingSimulation.js b/TradingSimulation.js index de67e9093..6cc2dd623 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -704,7 +704,7 @@ if (openStage !== undefined) { /* Default Values*/ - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { positionSize = balanceBaseAsset; positionRate = candle.close; } else { @@ -727,13 +727,13 @@ initialDefinition.positionSize.formula.error = err.message } if (isNaN(positionSize)) { - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { positionSize = balanceBaseAsset; } else { positionSize = balanceQuotedAsset; } } else { - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { if (positionSize > balanceBaseAsset) { positionSize = balanceBaseAsset } } else { if (positionSize > balanceQuotedAsset) { positionSize = balanceQuotedAsset } @@ -754,7 +754,7 @@ initialDefinition.positionRate.formula.error = err.message } if (isNaN(positionRate)) { - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { positionRate = candle.close; } else { positionRate = candle.close; @@ -1091,7 +1091,7 @@ let maximumBalance let balance - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { balance = balanceBaseAsset minimumBalance = bot.VALUES_TO_USE.minimumBalanceA maximumBalance = bot.VALUES_TO_USE.maximumBalanceA @@ -1673,7 +1673,7 @@ /* Stop Loss condition: Here we verify if the Stop Loss was hitted or not. */ - if ((bot.VALUES_TO_USE.baseAsset === 'BTC' && candle.max >= stopLoss) || (bot.VALUES_TO_USE.baseAsset !== 'BTC' && candle.min <= stopLoss)) { + if ((bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset && candle.max >= stopLoss) || (bot.VALUES_TO_USE.baseAsset !== bot.market.baseAsset && candle.min <= stopLoss)) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Stop Loss was hit."); } /* @@ -1683,7 +1683,7 @@ If we take the stop loss value at those situation would be a huge distortion of facts. */ - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { if (stopLoss < candle.min) { stopLoss = candle.min if (processingDailyFiles) { @@ -1708,7 +1708,7 @@ /* Apply the Slippage */ let slippageAmount = slippedStopLoss * bot.VALUES_TO_USE.slippage.stopLoss / 100 - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { slippedStopLoss = slippedStopLoss + slippageAmount } else { slippedStopLoss = slippedStopLoss - slippageAmount @@ -1718,7 +1718,7 @@ let feePaid = 0 - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { strategy.positionSize = balanceQuotedAsset / finalStopLoss; strategy.positionRate = finalStopLoss; @@ -1770,7 +1770,7 @@ /* Take Profit condition: Here we verify if the Take Profit was hit or not. */ - if ((bot.VALUES_TO_USE.baseAsset === 'BTC' && candle.min <= takeProfit) || (bot.VALUES_TO_USE.baseAsset !== 'BTC' && candle.max >= takeProfit)) { + if ((bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset && candle.min <= takeProfit) || (bot.VALUES_TO_USE.baseAsset !== bot.market.baseAsset && candle.max >= takeProfit)) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Take Profit was hit."); } /* @@ -1780,7 +1780,7 @@ If we take the stop loss value at those situation would be a huge distortion of facts. */ - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { if (takeProfit > candle.max) { takeProfit = candle.max if (processingDailyFiles) { @@ -1804,7 +1804,7 @@ /* Apply the Slippage */ let slippageAmount = slippedTakeProfit * bot.VALUES_TO_USE.slippage.takeProfit / 100 - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { slippedTakeProfit = slippedTakeProfit + slippageAmount } else { slippedTakeProfit = slippedTakeProfit - slippageAmount @@ -1814,7 +1814,7 @@ let feePaid = 0 - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { strategy.positionSize = balanceQuotedAsset / finalTakeProfit; strategy.positionRate = finalTakeProfit; @@ -1893,7 +1893,7 @@ /* We take what was calculated at the formula and apply the slippage. */ let slippageAmount = tradePositionRate * bot.VALUES_TO_USE.slippage.positionRate / 100 - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { tradePositionRate = tradePositionRate - slippageAmount } else { tradePositionRate = tradePositionRate + slippageAmount @@ -2027,34 +2027,28 @@ } } - let openPositionRate + let orderPrice let amountA let amountB - let positionDirection - let availableBalance = exchangeAPI.getAvailableBalance() + let orderSide + - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - positionDirection = "sell" + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { + orderSide = "sell" - openPositionRate = tradePositionRate - 100 // 100 is Provisional since we do have management of orders yet + orderPrice = tradePositionRate - 100 // This is going to be ingnored at the Exchange API for now since we only put market orders. - amountA = tradePositionSize * openPositionRate + amountA = tradePositionSize * orderPrice amountB = tradePositionSize - - if (amountB > availableBalance.quotedAsset) { // The exchangeAPI know what fees were paid. - amountB = availableBalance.quotedAsset - } + } else { - positionDirection = "buy" + orderSide = "buy" - openPositionRate = tradePositionRate + 100 // 100 is Provisional since we do have management of orders yet + orderPrice = tradePositionRate // This is going to be ingnored at the Exchange API for now since we only put market orders. amountA = tradePositionSize - amountB = tradePositionSize / openPositionRate + amountB = tradePositionSize / orderPrice - if (amountA > availableBalance.baseAsset) { // The exchangeAPI know what fees were paid. - amountA = availableBalance.baseAsset - } } interExecutionMemory.executionContext = { @@ -2062,46 +2056,47 @@ periods: periods, } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> Ready to put order."); } - exchangeAPI.createOrder(positionDirection, openPositionRate, amountA, amountB, onOrderPut) + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> Ready to create order."); } + exchangeAPI.createOrder(bot.market, orderSide, orderPrice, amountA, amountB, onOrderCreated) - function onOrderPut(err) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> Entering function."); } + function onOrderCreated(err, order) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> Entering function."); } try { switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> DEFAULT_OK_RESPONSE "); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> DEFAULT_OK_RESPONSE "); } interExecutionMemory.executionContext = { status: "In a Position", periods: periods, amountA: amountA, - amountB: amountB + amountB: amountB, + orderId: order.id } takePositionAtSimulation() return; } case global.DEFAULT_FAIL_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> DEFAULT_FAIL_RESPONSE "); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> Message = " + err.message); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> DEFAULT_FAIL_RESPONSE "); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> Message = " + err.message); } strategy.openStage.openExecution.error = err.message afterLoop() return; } case global.DEFAULT_RETRY_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> DEFAULT_RETRY_RESPONSE "); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> Message = " + err.message); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> DEFAULT_RETRY_RESPONSE "); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> Message = " + err.message); } strategy.openStage.openExecution.error = err.message afterLoop() return; } } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> Unexpected Response -> Message = " + err.message); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> Unexpected Response -> Message = " + err.message); } callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } catch (err) { - logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -2132,7 +2127,7 @@ let feePaid = 0 - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { feePaid = tradePositionSize * tradePositionRate * bot.VALUES_TO_USE.feeStructure.taker / 100 @@ -2251,27 +2246,27 @@ } } - let closePositionRate + let orderPrice let amountA let amountB - let positionDirection + let orderSide let availableBalance = exchangeAPI.getAvailableBalance() - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { - positionDirection = "buy" + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { + orderSide = "buy" - closePositionRate = ticker.last + 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. + orderPrice = ticker.last + 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. - amountA = availableBalance.baseAsset - amountB = availableBalance.baseAsset / closePositionRate + amountA = balanceBaseAsset + amountB = balanceBaseAsset / orderPrice } else { - positionDirection = "sell" + orderSide = "sell" - closePositionRate = ticker.last - 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. + orderPrice = ticker.last - 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. - amountA = availableBalance.quotedAsset * closePositionRate - amountB = availableBalance.quotedAsset + amountA = balanceQuotedAsset * orderPrice + amountB = balanceQuotedAsset } @@ -2281,44 +2276,45 @@ } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> About to close position at the exchange."); } - exchangeAPI.createOrder(positionDirection, closePositionRate, amountA, amountB, onOrderPut) + exchangeAPI.createOrder(bot.market, orderSide, orderPrice, amountA, amountB, onOrderCreated) - function onOrderPut(err) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderPut -> Entering function."); } + function onOrderCreated(err) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderCreated -> Entering function."); } try { switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderPut -> DEFAULT_OK_RESPONSE "); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderCreated -> DEFAULT_OK_RESPONSE "); } interExecutionMemory.executionContext = { status: "Position Closed", periods: periods, amountA: amountA, - amountB: amountB + amountB: amountB, + orderId: order.id } closePositionAtSimulation() return; } case global.DEFAULT_FAIL_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderPut -> DEFAULT_FAIL_RESPONSE "); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderCreated -> DEFAULT_FAIL_RESPONSE "); } /* We will assume that the problem is temporary, and expect that it will work at the next execution.*/ strategy.closeStage.closeExecution.error = err.message afterLoop() return; } case global.DEFAULT_RETRY_RESPONSE.result: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderPut -> DEFAULT_RETRY_RESPONSE "); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> onOrderCreated -> DEFAULT_RETRY_RESPONSE "); } strategy.closeStage.closeExecution.error = err.message afterLoop() return; } } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putClosingOrder -> onOrderPut -> Unexpected Response -> Message = " + err.message); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putClosingOrder -> onOrderCreated -> Unexpected Response -> Message = " + err.message); } callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } catch (err) { - logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putClosingOrder -> onOrderPut -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] runSimulation -> loop -> putClosingOrder -> onOrderCreated -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return } @@ -2336,7 +2332,7 @@ } } - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { lastTradeProfitLoss = balanceBaseAsset - previousBalanceBaseAsset; lastTradeROI = lastTradeProfitLoss * 100 / tradePositionSize; if (isNaN(lastTradeROI)) { lastTradeROI = 0; } @@ -2383,7 +2379,7 @@ } } - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { ROI = (bot.VALUES_TO_USE.initialBalanceA + profit) / bot.VALUES_TO_USE.initialBalanceA - 1; hitRatio = hits / roundtrips; anualizedRateOfReturn = ROI / days * 365; @@ -2649,7 +2645,7 @@ currentTrade.endRate = candle.close /* Here we will calculate the ongoing ROI */ - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { currentTrade.lastTradeROI = (tradePositionRate - candle.close) / tradePositionRate * 100 } else { currentTrade.lastTradeROI = (candle.close - tradePositionRate) / tradePositionRate * 100 From 075bc53f8e38408d0de0c655f3bc4281861bc931 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 7 Feb 2020 16:44:48 +0100 Subject: [PATCH 34/36] Live trading tested at Binance --- TradingSimulation.js | 132 ++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 91 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 6cc2dd623..06c48ab4a 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -167,6 +167,8 @@ let periods = 0; let positionPeriods = 0; + let closeRate + /* Usefull counters for conditions and formulas */ let distanceToLast = { @@ -1714,36 +1716,9 @@ slippedStopLoss = slippedStopLoss - slippageAmount } - let finalStopLoss = slippedStopLoss; + closeRate = slippedStopLoss; - let feePaid = 0 - - if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { - strategy.positionSize = balanceQuotedAsset / finalStopLoss; - strategy.positionRate = finalStopLoss; - - feePaid = balanceQuotedAsset / finalStopLoss * bot.VALUES_TO_USE.feeStructure.taker / 100 - - balanceBaseAsset = balanceBaseAsset + balanceQuotedAsset / finalStopLoss - feePaid; - balanceQuotedAsset = 0; - } else { - strategy.positionSize = balanceBaseAsset * finalStopLoss; - strategy.positionRate = finalStopLoss; - - feePaid = balanceBaseAsset * finalStopLoss * bot.VALUES_TO_USE.feeStructure.taker / 100 - - balanceQuotedAsset = balanceQuotedAsset + balanceBaseAsset * finalStopLoss - feePaid; - balanceBaseAsset = 0; - } - - if (processingDailyFiles) { - if (positionedAtYesterday) { - yesterday.balanceBaseAsset = balanceBaseAsset; - yesterday.balanceQuotedAsset = balanceQuotedAsset; - } - } - - marketRate = finalStopLoss; + marketRate = closeRate; type = '"Close@StopLoss"'; strategyStage = 'Close Stage'; stopLossStage = 'No Stage'; @@ -1751,7 +1726,7 @@ currentTrade.end = candle.end; currentTrade.status = 1; currentTrade.exitType = 1; - currentTrade.endRate = finalStopLoss; + currentTrade.endRate = closeRate; closePositionNow = true; @@ -1810,37 +1785,9 @@ slippedTakeProfit = slippedTakeProfit - slippageAmount } - let finalTakeProfit = slippedTakeProfit; + closeRate = slippedTakeProfit; - let feePaid = 0 - - if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { - strategy.positionSize = balanceQuotedAsset / finalTakeProfit; - strategy.positionRate = finalTakeProfit; - - feePaid = balanceQuotedAsset / finalTakeProfit * bot.VALUES_TO_USE.feeStructure.taker / 100 - - balanceBaseAsset = balanceBaseAsset + balanceQuotedAsset / finalTakeProfit - feePaid; - balanceQuotedAsset = 0; - } else { - strategy.positionSize = balanceBaseAsset * finalTakeProfit; - strategy.positionRate = finalTakeProfit; - - feePaid = balanceBaseAsset * finalTakeProfit * bot.VALUES_TO_USE.feeStructure.taker / 100 - - balanceQuotedAsset = balanceQuotedAsset + balanceBaseAsset * finalTakeProfit - feePaid; - balanceBaseAsset = 0; - } - - if (processingDailyFiles) { - if (positionedAtYesterday) { - yesterday.balanceBaseAsset = balanceBaseAsset; - yesterday.balanceQuotedAsset = balanceQuotedAsset; - - } - } - - marketRate = finalTakeProfit; + marketRate = closeRate; type = '"Close@TakeProfit"'; strategyStage = 'Close Stage'; stopLossStage = 'No Stage'; @@ -1849,7 +1796,7 @@ currentTrade.end = candle.end; currentTrade.status = 1; currentTrade.exitType = 2; - currentTrade.endRate = finalTakeProfit; + currentTrade.endRate = closeRate; closePositionNow = true; @@ -1991,18 +1938,6 @@ } } - - /* Checking the status of current positions */ - let positions = exchangeAPI.getPositions(); - if (positions.length > 0) { - let position = positions[positions.length - 1] // We are allways checking the the last position is not open. - if (position.status === 'open') { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putOpeningOrder -> Not placing the trade at the exchange because the last position is still open. "); } - afterLoop(); - return - } - } - /* Mechanism to avoid putting the same order over and over again at different executions of the simulation engine. */ if (interExecutionMemory.executionContext !== undefined) { if (interExecutionMemory.executionContext.periods !== undefined) { @@ -2223,19 +2158,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> putClosingOrder -> Entering function."); } - /* Checking the status of current positions */ - let positions = exchangeAPI.getPositions(); - if (positions.length > 0) { - let position = positions[positions.length - 1] // We are allways checking the the last position is not open. - if (position.status === 'open') { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> Exiting function because status of last position is Open."); } - afterLoop(); - return - } - } - /* Mechanism to avoid putting the same order over and over again at different executions of the simulation engine. */ - if (interExecutionMemory.executionContext !== undefined) { if (interExecutionMemory.executionContext.periods !== undefined) { if (periods <= interExecutionMemory.executionContext.periods) { @@ -2250,23 +2173,22 @@ let amountA let amountB let orderSide - let availableBalance = exchangeAPI.getAvailableBalance() if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { orderSide = "buy" orderPrice = ticker.last + 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. - amountA = balanceBaseAsset - amountB = balanceBaseAsset / orderPrice + amountA = balanceQuotedAsset + amountB = balanceQuotedAsset / orderPrice } else { orderSide = "sell" orderPrice = ticker.last - 100; // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff. - amountA = balanceQuotedAsset * orderPrice - amountB = balanceQuotedAsset + amountA = balanceBaseAsset * orderPrice + amountB = balanceBaseAsset } @@ -2278,7 +2200,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> About to close position at the exchange."); } exchangeAPI.createOrder(bot.market, orderSide, orderPrice, amountA, amountB, onOrderCreated) - function onOrderCreated(err) { + function onOrderCreated(err, order) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> putClosingOrder -> onOrderCreated -> Entering function."); } try { @@ -2332,6 +2254,34 @@ } } + let feePaid = 0 + + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { + strategy.positionSize = balanceQuotedAsset / closeRate; + strategy.positionRate = closeRate; + + feePaid = balanceQuotedAsset / closeRate * bot.VALUES_TO_USE.feeStructure.taker / 100 + + balanceBaseAsset = balanceBaseAsset + balanceQuotedAsset / closeRate - feePaid; + balanceQuotedAsset = 0; + } else { + strategy.positionSize = balanceBaseAsset * closeRate; + strategy.positionRate = closeRate; + + feePaid = balanceBaseAsset * closeRate * bot.VALUES_TO_USE.feeStructure.taker / 100 + + balanceQuotedAsset = balanceQuotedAsset + balanceBaseAsset * closeRate - feePaid; + balanceBaseAsset = 0; + } + + if (processingDailyFiles) { + if (positionedAtYesterday) { + yesterday.balanceBaseAsset = balanceBaseAsset; + yesterday.balanceQuotedAsset = balanceQuotedAsset; + + } + } + if (bot.VALUES_TO_USE.baseAsset === bot.market.baseAsset) { lastTradeProfitLoss = balanceBaseAsset - previousBalanceBaseAsset; lastTradeROI = lastTradeProfitLoss * 100 / tradePositionSize; From 7a3f4f3696d5652eace946b0a4220d7dac52ae60 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 8 Feb 2020 18:55:08 +0100 Subject: [PATCH 35/36] Reset Begining of Market Mechanism Implemented --- MultiPeriodDaily.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 1e87a91a5..71ad6181a 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -26,6 +26,7 @@ let bootstrappingTheProcess = false let processConfig; + let beginingOfMarket return thisObject; @@ -223,6 +224,16 @@ if (thisReport.lastFile !== undefined) { + beginingOfMarket = new Date(thisReport.beginingOfMarket); + + if (beginingOfMarket.valueOf() !== contextVariables.dateBeginOfMarket.valueOf()) { // Reset Mechanism for Begining of the Market + logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Reset Mechanism for Begining of the Market Activated. -> reportKey = " + reportKey); + + beginingOfMarket = new Date(contextVariables.dateBeginOfMarket.valueOf()); + startFromBegining(); + return; + } + if (bot.hasTheBotJustStarted === true && processConfig.framework.startDate.resumeExecution === false) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting from the begining because bot has just started and resume execution was true."); } @@ -242,6 +253,7 @@ In the case when there is no status report, we assume like the last processed file is the one on the date of Begining of Market. */ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting from the begining of the market because own status report not found or lastFile was undefined."); } + beginingOfMarket = new Date(contextVariables.dateBeginOfMarket.valueOf()); startFromBegining(); return; } @@ -765,6 +777,7 @@ thisReport.file.lastExecution = bot.currentDaytime; thisReport.file.lastFile = lastFileDate; thisReport.file.interExecutionMemoryArray = interExecutionMemoryArray; + thisReport.file.beginingOfMarket = beginingOfMarket.toUTCString() thisReport.save(callBack); bot.hasTheBotJustStarted = false; From 86a84792031724fa06aca2ec88d6cf42b899a281 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Feb 2020 18:17:01 +0100 Subject: [PATCH 36/36] Bug Fixed --- ExchangeAPI.js | 2 +- MultiPeriod.js | 2 +- package-lock.json | 66 +++++++++++++++++++++++++++-------------------- package.json | 6 ++--- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 54c3c52e7..4677a2c45 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -38,7 +38,7 @@ 'secret': secret, 'timeout': 30000, 'enableRateLimit': true, - verbose: false, + verbose: true, options: options } diff --git a/MultiPeriod.js b/MultiPeriod.js index 2ad6c0757..6364f346a 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -475,7 +475,7 @@ /* Validation that we are not going past the head of the market. */ - if (bot.multiPeriodProcessDatetime.valueOf() > contextVariables.dateEndOfMarket.valueOf()) { + if (bot.multiPeriodProcessDatetime.valueOf() > contextVariables.dateEndOfMarket.valueOf() + ONE_DAY_IN_MILISECONDS - 1) { const logText = "Head of the market found @ " + previousDay.getUTCFullYear() + "/" + (previousDay.getUTCMonth() + 1) + "/" + previousDay.getUTCDate() + "."; if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> " + logText); } diff --git a/package-lock.json b/package-lock.json index fbf97a4f3..bdb728c2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,19 +5,27 @@ "requires": true, "dependencies": { "@types/node": { - "version": "12.7.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz", - "integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ==" + "version": "13.7.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz", + "integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ==" }, "ccxt": { - "version": "1.21.82", - "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.21.82.tgz", - "integrity": "sha512-+HX/6WK8BM5c9OwhALl9zzMKvueZfHDXVmfrKNmQ4005hc+BtNuNe47XEs6dAylY+ll7n9JpzaoIZhy6Lipiew==" + "version": "1.22.39", + "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.22.39.tgz", + "integrity": "sha512-Vq4BzYS/FwRudPKQ6BQGU3SVntYv7EAQGT+2guf+e7qm45CJMhdoVwR1z89kl42fbK39XMnl8sUnRCwsKPs38A==" + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "requires": { + "ms": "2.1.2" + } }, "dotenv": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz", - "integrity": "sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg==" + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" }, "easy-stack": { "version": "1.0.0", @@ -42,6 +50,21 @@ "easy-stack": "1.0.0" } }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + }, + "module-alias": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", + "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -63,30 +86,17 @@ "integrity": "sha512-jLYV0DORrzY3xaz/S9ydJL6Iz7essZeAfnAavsJ+zsJGZ1MOnsS52yRjU3uF3pJa/lla7+wisp//fxOwOH8SKQ==" }, "telegraf": { - "version": "3.32.0", - "resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.32.0.tgz", - "integrity": "sha512-5ZHiovyuG1rVLygJjaqf57wDt8e1nijAinKXCxN1tyUZ4BcrkZW/z5rVTEXA+KegpFbWxKKv3KnJwUJrKDqD0Q==", + "version": "3.36.0", + "resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.36.0.tgz", + "integrity": "sha512-9o6AJKRiTm5vMWYI6WpTfBHzu4FMpWBNKxvnMxRds/cbMY9RnsVVjdi8i4bFFlfd+xbi73EbrnI3dybayryICA==", "requires": { - "@types/node": "12.7.12", + "@types/node": "13.7.0", "debug": "4.1.1", + "minimist": "1.2.0", + "module-alias": "2.2.2", "node-fetch": "2.6.0", "sandwich-stream": "2.0.2", "telegram-typings": "3.6.1" - }, - "dependencies": { - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "requires": { - "ms": "2.1.2" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - } } }, "telegram-typings": { diff --git a/package.json b/package.json index e9977e889..a81037332 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "ccxt": "^1.21.82", - "dotenv": "^8.0.0", + "ccxt": "^1.22.39", + "dotenv": "^8.2.0", "node-ipc": "^9.1.1", - "telegraf": "^3.32.0" + "telegraf": "^3.36.0" } }