From f37d16b797ebec4b96296364b6070e4adc7c368f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 11 Oct 2019 14:41:59 +0200 Subject: [PATCH 01/14] Keys taken from parameters --- Session.js | 25 ++++++++++++++++++++++++- server.js | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Session.js b/Session.js index 862bc1a2e..6d5a718d7 100644 --- a/Session.js +++ b/Session.js @@ -67,6 +67,7 @@ function startLiveTrading(message) { + /* 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) { @@ -84,8 +85,30 @@ } } + /* 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 + + process.env.KEY = key.name + process.env.SECRET = key.code + } + } + } + + /* 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.name + process.env.SECRET = key.code + } + } + if (process.env.KEY === undefined || process.env.SECRET === undefined) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Live mode."); } + 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."); } return } diff --git a/server.js b/server.js index 94ca6fde1..e167585f2 100644 --- a/server.js +++ b/server.js @@ -72,7 +72,7 @@ if (global.TASK_NODE !== undefined) { } else { // I use this section to debug in standalone mode. - let argument = '{"type":"Task","name":"Runs Backtests","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"10 Minutes","id":"121202ea-6735-4bf3-8a95-aaa55f00f6e7"},"id":"3f483482-d8a1-4755-ba50-7cac6296fa5f"}],"id":"25fe9099-b53d-4757-8a63-3f8a15875f33"},"id":"5b21d2d2-0f52-4408-83eb-ddaa844ec58c"}' + let argument = '{"type":"Task","name":"New Task","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Trading Engine Process","code":{"process":"Multi-Period"},"session":{"type":"Live Trading Session","name":"New Live Trading Session","id":"1be42eb3-bfaf-432f-8da6-15f15d547f50"},"id":"16d02098-221f-4d83-9682-a5f83262bb74"}],"id":"72cdfb23-b7c6-4feb-ba2d-d56415d30162"},"id":"c6fb2087-d2a2-49a0-9790-2c4d1cb015d7"}' /* charly argument = '{"type":"Task","name":"Brings Trades Records from the Exchange","bot":{"type":"Sensor","name":"Charly","processes":[{"type":"Process","name":"Live Trades","code":{"team":"AAMasters","bot":"AACharly","process":"Live-Trades"},"id":"5846ebc7-1979-4a80-9cc7-94bb4b8659dc"},{"type":"Process","name":"Hole Fixing","code":{"team":"AAMasters","bot":"AACharly","process":"Hole-Fixing"},"id":"31fc4f05-75d4-419a-9fb0-73e25e856f15"}]},"id":"5bfef4dc-54c1-44db-ace6-1ab27a86746e"}' // olivia argument = '{"type":"Task","name":"Generates 1 min to 24 hs Candles & Volumes","bot":{"type":"Indicator","name":"Olivia","processes":[{"type":"Process","name":"Daily","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Daily"},"id":"68cc8e1b-e94a-477e-82d0-15ecc9f1b9e2"},{"type":"Process","name":"Market","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Market"},"id":"e1ac5e3d-d491-4e90-baf4-d4e5b71a8b1a"}]},"id":"efe36e05-75ea-41b5-8d92-c6b27635c834"}' // bruce argument = ' {"type":"Task","name":"Converts Trades into 1 min Candles & Volumes","bot":{"type":"Indicator","name":"Bruce","processes":[{"type":"Process","name":"New Process","code":{"team":"AAMasters","bot":"AABruce","process":"Single-Period-Daily"},"id":"e184744f-5de0-41c1-ad4c-36960f4ced90"}]},"id":"42758590-a7bd-4712-a5c9-80a3a820c5b3"}' From 772482e1569ac442303c0b90ae204cc41e3dc0e5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 16 Oct 2019 19:14:22 +0200 Subject: [PATCH 02/14] Bug fixed undefined in logs --- DebugLog.js | 4 ++-- Session.js | 3 ++- package-lock.json | 47 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + server.js | 29 ++++++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 4 deletions(-) diff --git a/DebugLog.js b/DebugLog.js index d2f34a057..cf1a694c1 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -69,7 +69,7 @@ exports.newDebugLog = function newDebugLog() { let filePath = thisObject.bot.filePathRoot + "/Logs/" + thisObject.bot.process + "/" if (thisObject.bot.SESSION !== undefined) { - filePath = filePath + thisObject.bot.SESSION.name + "/" + executionDatetime; + filePath = filePath + thisObject.bot.SESSION.id + "/" + executionDatetime; } else { filePath = filePath + executionDatetime; } @@ -101,7 +101,7 @@ exports.newDebugLog = function newDebugLog() { if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - console.log("[ERROR] DebugLog -> persist -> onInizialized -> onFileCreated -> err = "+ err.stack); + console.log("[ERROR] DebugLog -> persist -> onInizialized -> onFileCreated -> err = "+ err.message); setTimeout(writeLog, 10000); // Lets retry until we make it. return; diff --git a/Session.js b/Session.js index 6d5a718d7..5ff67d6f6 100644 --- a/Session.js +++ b/Session.js @@ -15,7 +15,8 @@ /* Initialize this info so that everything is logged propeerly */ bot.SESSION = { - name: bot.processNode.session.name + name: bot.processNode.session.name, + id: bot.processNode.session.id } /* Check if there is a session */ diff --git a/package-lock.json b/package-lock.json index 400d53cef..8d6660151 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,11 @@ "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", @@ -458,6 +463,11 @@ "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", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, "node-ipc": { "version": "9.1.1", "resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.1.1.tgz", @@ -572,6 +582,11 @@ "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", @@ -652,6 +667,38 @@ } } }, + "telegraf": { + "version": "3.32.0", + "resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.32.0.tgz", + "integrity": "sha512-5ZHiovyuG1rVLygJjaqf57wDt8e1nijAinKXCxN1tyUZ4BcrkZW/z5rVTEXA+KegpFbWxKKv3KnJwUJrKDqD0Q==", + "requires": { + "@types/node": "12.7.12", + "debug": "4.1.1", + "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": { + "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", diff --git a/package.json b/package.json index d13992b3a..a32ca9fda 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "axios": "^0.19.0", "dotenv": "^8.0.0", "node-ipc": "^9.1.1", + "telegraf": "^3.32.0", "winston": "^3.2.1" } } diff --git a/server.js b/server.js index e167585f2..6490aef23 100644 --- a/server.js +++ b/server.js @@ -72,7 +72,7 @@ if (global.TASK_NODE !== undefined) { } else { // I use this section to debug in standalone mode. - let argument = '{"type":"Task","name":"New Task","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Trading Engine Process","code":{"process":"Multi-Period"},"session":{"type":"Live Trading Session","name":"New Live Trading Session","id":"1be42eb3-bfaf-432f-8da6-15f15d547f50"},"id":"16d02098-221f-4d83-9682-a5f83262bb74"}],"id":"72cdfb23-b7c6-4feb-ba2d-d56415d30162"},"id":"c6fb2087-d2a2-49a0-9790-2c4d1cb015d7"}' + let argument = '{"type":"Task","name":"New Task","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"30min + 6hs down, dev < 15","id":"715839bb-a76c-427f-a48f-5bf1b2184070"},"id":"18dfca43-5015-40d9-824d-09b59b670e32"},{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"30min + 6hs down, dev < 20","id":"7a681e8d-7167-4edb-bb2f-90e12c7f5418"},"id":"5ccdbb76-4e45-4377-bc44-fd0f95e40deb"}],"id":"22b61a44-4fcc-4f6d-bb7c-4c2a24acbfbc"},"id":"9238ed0b-7cc6-4732-83e6-8ac8d52f6dd3"}' /* charly argument = '{"type":"Task","name":"Brings Trades Records from the Exchange","bot":{"type":"Sensor","name":"Charly","processes":[{"type":"Process","name":"Live Trades","code":{"team":"AAMasters","bot":"AACharly","process":"Live-Trades"},"id":"5846ebc7-1979-4a80-9cc7-94bb4b8659dc"},{"type":"Process","name":"Hole Fixing","code":{"team":"AAMasters","bot":"AACharly","process":"Hole-Fixing"},"id":"31fc4f05-75d4-419a-9fb0-73e25e856f15"}]},"id":"5bfef4dc-54c1-44db-ace6-1ab27a86746e"}' // olivia argument = '{"type":"Task","name":"Generates 1 min to 24 hs Candles & Volumes","bot":{"type":"Indicator","name":"Olivia","processes":[{"type":"Process","name":"Daily","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Daily"},"id":"68cc8e1b-e94a-477e-82d0-15ecc9f1b9e2"},{"type":"Process","name":"Market","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Market"},"id":"e1ac5e3d-d491-4e90-baf4-d4e5b71a8b1a"}]},"id":"efe36e05-75ea-41b5-8d92-c6b27635c834"}' // bruce argument = ' {"type":"Task","name":"Converts Trades into 1 min Candles & Volumes","bot":{"type":"Indicator","name":"Bruce","processes":[{"type":"Process","name":"New Process","code":{"team":"AAMasters","bot":"AABruce","process":"Single-Period-Daily"},"id":"e184744f-5de0-41c1-ad4c-36960f4ced90"}]},"id":"42758590-a7bd-4712-a5c9-80a3a820c5b3"}' @@ -152,6 +152,28 @@ global.STOP_TASK_GRACEFULLY = false; function bootLoader() { + /* Telegram Bot Initialization */ + + try { +/* + const Telegraf = require('telegraf') + + global.TELEGRAM_BOT = new Telegraf(process.env.TELEGRAM_BOT_TOKEN) + global.TELEGRAM_BOT.start((ctx) => ctx.reply('Welcome')) + global.TELEGRAM_BOT.help((ctx) => ctx.reply('Send me a sticker')) + global.TELEGRAM_BOT.on('sticker', (ctx) => ctx.reply('??')) + global.TELEGRAM_BOT.hears('hi', (ctx) => ctx.reply('Hey there')) + global.TELEGRAM_BOT.launch() + + const Telegram = require('telegraf/telegram') + global.TELEGRAM_API = new Telegram(process.env.TELEGRAM_BOT_TOKEN) + global.TELEGRAM_API.sendMessage(process.env.TELEGRAM_GROUP_ID, "Task Manager Started.") +*/ + + } catch (err) { + console.log("[ERROR] Task Server -> server -> bootLoader -> Telegram Initialization Failed. -> Error = " + err.stack); + } + /* Heartbeat sent to the UI */ let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id @@ -166,7 +188,12 @@ function bootLoader() { let event = { seconds: (new Date()).getSeconds() } + /* global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) + if (global.TELEGRAM_API !== undefined) { + global.TELEGRAM_API.sendMessage(process.env.TELEGRAM_GROUP_ID, "Task is Alive!") + } + */ } for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { From b3d5c293f55a0345ab3102adc94cc2bfbb2a8b25 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Oct 2019 09:31:14 +0200 Subject: [PATCH 03/14] Logging at user defined folderName in sessions objects --- DebugLog.js | 6 +++++- Session.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DebugLog.js b/DebugLog.js index cf1a694c1..e996fe4dd 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -69,7 +69,11 @@ exports.newDebugLog = function newDebugLog() { let filePath = thisObject.bot.filePathRoot + "/Logs/" + thisObject.bot.process + "/" if (thisObject.bot.SESSION !== undefined) { - filePath = filePath + thisObject.bot.SESSION.id + "/" + executionDatetime; + if (thisObject.bot.SESSION.code.folderName === undefined) { + filePath = filePath + thisObject.bot.SESSION.id + "/" + executionDatetime; + } else { + filePath = filePath + thisObject.bot.SESSION.code.folderName + "/" + executionDatetime; + } } else { filePath = filePath + executionDatetime; } diff --git a/Session.js b/Session.js index 5ff67d6f6..181a0b726 100644 --- a/Session.js +++ b/Session.js @@ -16,7 +16,8 @@ /* Initialize this info so that everything is logged propeerly */ bot.SESSION = { name: bot.processNode.session.name, - id: bot.processNode.session.id + id: bot.processNode.session.id, + code: bot.processNode.session.code } /* Check if there is a session */ From dba159af7aae19f49106f5bfb2b00108db96e64a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Oct 2019 10:20:48 +0200 Subject: [PATCH 04/14] SESSION.folderName implemented --- Context.js | 2 +- DebugLog.js | 6 +----- MultiPeriod.js | 2 +- Session.js | 26 ++++++++++++++++++++++++-- StatusReport.js | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Context.js b/Context.js index 3880cb649..5395ac2ca 100644 --- a/Context.js +++ b/Context.js @@ -84,7 +84,7 @@ statusDependencies = pStatusDependencies; if (bot.SESSION !== undefined) { - sessionPath = bot.SESSION.id + "/" + sessionPath = bot.SESSION.folderName + "/" } /* diff --git a/DebugLog.js b/DebugLog.js index e996fe4dd..06b40a94e 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -69,11 +69,7 @@ exports.newDebugLog = function newDebugLog() { let filePath = thisObject.bot.filePathRoot + "/Logs/" + thisObject.bot.process + "/" if (thisObject.bot.SESSION !== undefined) { - if (thisObject.bot.SESSION.code.folderName === undefined) { - filePath = filePath + thisObject.bot.SESSION.id + "/" + executionDatetime; - } else { - filePath = filePath + thisObject.bot.SESSION.code.folderName + "/" + executionDatetime; - } + filePath = filePath + thisObject.bot.SESSION.folderName + "/" + executionDatetime; } else { filePath = filePath + executionDatetime; } diff --git a/MultiPeriod.js b/MultiPeriod.js index 2c31ec399..f3c183383 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -986,7 +986,7 @@ let fileContent = JSON.stringify(dataRange); let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; - let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.id + "/" + pProductFolder + "/" + 'Multi-Period-Daily' + fileName; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + pProductFolder + "/" + 'Multi-Period-Daily' + fileName; fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); diff --git a/Session.js b/Session.js index 181a0b726..70d00ae53 100644 --- a/Session.js +++ b/Session.js @@ -14,12 +14,19 @@ if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } /* Initialize this info so that everything is logged propeerly */ + bot.SESSION = { name: bot.processNode.session.name, - id: bot.processNode.session.id, - code: bot.processNode.session.code + id: bot.processNode.session.id } + /* Set the folderName for early logging */ + if (bot.processNode.session.code.folderName === undefined) { + bot.SESSION.folderName = bot.SESSION.id + } else { + bot.SESSION.folderName = bot.processNode.session.code.folderName + } + /* Check if there is a session */ if (bot.processNode.session === undefined) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> Cannot run without a Session."); @@ -40,6 +47,21 @@ 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) { + try { + code = JSON.parse(bot.SESSION.code) + if (code.folderName === undefined) { + bot.SESSION.folderName = bot.SESSION.id + } else { + bot.SESSION.folderName = bot.processNode.session.code.folderName + } + } catch (err) { + bot.SESSION.folderName = bot.SESSION.id + } + } + setValuesToUse(message) switch (bot.SESSION.type) { diff --git a/StatusReport.js b/StatusReport.js index 65a6916e2..4096976a4 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -51,7 +51,7 @@ year = pYear; if (bot.SESSION !== undefined && pOwner.type === "Trading Engine") { - sessionPath = bot.SESSION.id + "/" + sessionPath = bot.SESSION.folderName + "/" } if (owner.dataSetSection === "Month") { From 53c396e55cd427db8e59fd4f71aba67b3793880b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Oct 2019 10:44:04 +0200 Subject: [PATCH 05/14] Bug Fixed --- Session.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session.js b/Session.js index 70d00ae53..f91607445 100644 --- a/Session.js +++ b/Session.js @@ -55,7 +55,7 @@ if (code.folderName === undefined) { bot.SESSION.folderName = bot.SESSION.id } else { - bot.SESSION.folderName = bot.processNode.session.code.folderName + bot.SESSION.folderName = code.folderName } } catch (err) { bot.SESSION.folderName = bot.SESSION.id From 231183802351538f101c7d4cee9b4bef1ddc4aa3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Oct 2019 17:28:25 +0200 Subject: [PATCH 06/14] Forward testing and paper trading --- MultiPeriod.js | 11 +++++++ Session.js | 80 +++++++++++++++++++++++++++++++++++++++----------- server.js | 2 +- 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index f3c183383..d4e8325bc 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -160,6 +160,17 @@ contextVariables.dateEndOfMarket = new Date(thisReport.lastFile.valueOf()); + /* Validation that the data is not up-to-date. */ + + if (bot.multiPeriodProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS > contextVariables.dateEndOfMarket.valueOf() && bot.SESSION.type !== "Backtesting Session") { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> " + "Head of the market is @ " + contextVariables.dateEndOfMarket); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> You need to UPDATE your datasets in order to run a " + bot.SESSION.type) } + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + + } /* Finally we get our own Status Report. */ diff --git a/Session.js b/Session.js index f91607445..cf857dcbe 100644 --- a/Session.js +++ b/Session.js @@ -36,12 +36,12 @@ /* Listen to event to start or stop the session. */ bot.sessionKey = bot.processNode.session.name + '-' + bot.processNode.session.type + '-' + bot.processNode.session.id - + global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Run Session', undefined, undefined, undefined, runSession) global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Stop Session', undefined, undefined, undefined, stopSession) function runSession(message) { - + console.log("runSession") /* We are going to run the Definition comming at the event. */ bot.DEFINITION = JSON.parse(message.event.definition) bot.SESSION = JSON.parse(message.event.session) @@ -73,6 +73,14 @@ startLiveTrading(message) break } + case 'Fordward Testing Session': { + startFordwardTesting(message) + break + } + case 'Paper Trading Session': { + startPaperTrading(message) + break + } } bot.SESSION_STATUS = 'Idle' bot.STOP_SESSION = false @@ -84,13 +92,65 @@ function startBackTesting(message) { bot.startMode = "Backtest" + if (bot.VALUES_TO_USE.timeRange.finalDatetime.valueOf() > (new Date()).valueOf()) { + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date() + } bot.resumeExecution = false; bot.hasTheBotJustStarted = true - bot.multiPeriodProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime + bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) } 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."); } + return + } + + bot.startMode = "Live" + if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() + } + bot.resumeExecution = false; + bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) + bot.hasTheBotJustStarted = true + + } + + 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."); } + return + } + + bot.startMode = "Live" + if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() + } + bot.resumeExecution = false; + bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) + bot.hasTheBotJustStarted = 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()) + + } + + 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) { @@ -130,20 +190,6 @@ process.env.SECRET = key.code } } - - 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."); } - return - } - - bot.startMode = "Live" - if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() - } - bot.resumeExecution = false; - bot.multiPeriodProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime - bot.hasTheBotJustStarted = true - } function setValuesToUse(message) { diff --git a/server.js b/server.js index 6490aef23..184f140c5 100644 --- a/server.js +++ b/server.js @@ -212,7 +212,7 @@ function bootLoader() { } if (global.TASK_NODE.bot.processes[processIndex].code.process === undefined) { - console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[processIndex].name); + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' at object Process is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[processIndex].name); continue } From 0ff6e43075c7ce09a9aa811b70ce3206d27afa78 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Oct 2019 22:19:30 +0200 Subject: [PATCH 07/14] Better handling bad timePerdiod definition --- MultiPeriod.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index d4e8325bc..bbbbf4dfb 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -827,8 +827,12 @@ n = 0; - callTheBot(); - + if (currentTimePeriod !== undefined) { + callTheBot(); + } else { + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> periodsControlLoop -> Time Period not Recognized. Can not continue." ); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } } } catch (err) { @@ -842,7 +846,7 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> Entering function."); } - + usertBot.start( multiPeriodDataFiles, currentTimePeriod, From d2bdd1f5df10ac5ace31aab1e66c647ea4d6abc1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 18 Oct 2019 09:42:34 +0200 Subject: [PATCH 08/14] Fordward Test finished --- Session.js | 32 ++++++++++++++++++++++++++++++++ server.js | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Session.js b/Session.js index cf857dcbe..6ff290bb4 100644 --- a/Session.js +++ b/Session.js @@ -136,6 +136,28 @@ bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf()) bot.hasTheBotJustStarted = true + /* Reduce the balance */ + + let balancePercentage = 1 // This is the default value + try { + let code = JSON.parse(bot.SESSION.code) + + if (code.balancePercentage !== undefined) { + balancePercentage = code.balancePercentage + } + + } catch (err) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> startFordwardTesting -> Invalid value por balancePercentage. Using Default."); + } + + bot.VALUES_TO_USE.initialBalanceA = bot.VALUES_TO_USE.initialBalanceA * balancePercentage / 100 + bot.VALUES_TO_USE.initialBalanceB = bot.VALUES_TO_USE.initialBalanceB * balancePercentage / 100 + + bot.VALUES_TO_USE.minimumBalanceA = bot.VALUES_TO_USE.minimumBalanceA * balancePercentage / 100 + bot.VALUES_TO_USE.minimumBalanceB = bot.VALUES_TO_USE.minimumBalanceB * balancePercentage / 100 + + bot.VALUES_TO_USE.maximumBalanceA = bot.VALUES_TO_USE.maximumBalanceA * balancePercentage / 100 + bot.VALUES_TO_USE.maximumBalanceB = bot.VALUES_TO_USE.maximumBalanceB * balancePercentage / 100 } function startPaperTrading(message) { @@ -236,6 +258,16 @@ bot.VALUES_TO_USE.timeRange.finalDatetime = new Date((new Date()).valueOf() + ONE_YEAR_IN_MILISECONDS) break } + case 'Fordward Testing Session': { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date((new Date()).valueOf() + ONE_YEAR_IN_MILISECONDS) + break + } + case 'Paper Trading Session': { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date((new Date()).valueOf() + ONE_YEAR_IN_MILISECONDS) + break + } } let tradingSystem = bot.DEFINITION.tradingSystem diff --git a/server.js b/server.js index 184f140c5..06ed86a90 100644 --- a/server.js +++ b/server.js @@ -112,7 +112,7 @@ 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 minutes.') + 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.') setTimeout(global.EXIT_NODE_PROCESS, 60000); } }); From 151b849fe06204b8ce63c190547deabda09bf788 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 19 Oct 2019 13:35:42 +0200 Subject: [PATCH 09/14] Social Bots Implemented --- Session.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++- server.js | 31 ++-------------------- 2 files changed, 79 insertions(+), 30 deletions(-) diff --git a/Session.js b/Session.js index 6ff290bb4..eda16a9c8 100644 --- a/Session.js +++ b/Session.js @@ -40,6 +40,9 @@ global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Run Session', undefined, undefined, undefined, runSession) global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Stop Session', undefined, undefined, undefined, stopSession) + callBackFunction(global.DEFAULT_OK_RESPONSE) + return + function runSession(message) { console.log("runSession") /* We are going to run the Definition comming at the event. */ @@ -62,6 +65,10 @@ } } + /* Set up Social Bots */ + setUpSocialBots() + + /* Extract values from different sources and consolidate them under one structure that is going to be used later on. */ setValuesToUse(message) switch (bot.SESSION.type) { @@ -500,7 +507,76 @@ } } - callBackFunction(global.DEFAULT_OK_RESPONSE) + function setUpSocialBots() { + + if (bot.SESSION.socialBots !== undefined) { + if (bot.SESSION.socialBots.bots !== undefined) { + for (let i = 0; i < bot.SESSION.socialBots.bots.length; i++) { + let socialBot = bot.SESSION.socialBots.bots[i] + if (socialBot.type === "Telegram Bot") { + try { + let code = JSON.parse(socialBot.code) + socialBot.botInstance = setUpTelegramBot(code.botToken, code.chatId) + } catch (err) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> setUpSocialBots -> err = " + err.stack); + } + } + } + } + + function announce(announcement) { + if (bot.SESSION.socialBots.bots !== undefined) { + for (let i = 0; i < bot.SESSION.socialBots.bots.length; i++) { + 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.type === "Telegram Bot") { + socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, code.text) + } + } + } catch (err) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> setUpSocialBots -> announce -> err = " + err.stack); + } + } + } + } + + bot.SESSION.socialBots.announce = announce + } + } + + function setUpTelegramBot(botToken, chatId) { + /* Telegram Bot Initialization */ + try { + const Telegraf = require('telegraf') + let telegramBot + telegramBot = new Telegraf(botToken) + telegramBot.start((ctx) => ctx.reply('Hi! I am a Telegram Bot powered by Superalgos')) + telegramBot.help((ctx) => ctx.reply('Send me a sticker')) + telegramBot.on('sticker', (ctx) => ctx.reply('??')) + telegramBot.hears('hi', (ctx) => ctx.reply('Hey there')) + telegramBot.launch() + + const Telegram = require('telegraf/telegram') + let telegramAPI + telegramAPI = new Telegram(botToken) + telegramAPI.sendMessage(chatId, bot.SESSION.type + " '" + bot.SESSION.name + "' was Started.") + + let botInstance = { + telegramBot: telegramBot, + telegramAPI: telegramAPI, + chatId: chatId + } + return botInstance + } catch (err) { + parentLogger.write(MODULE_NAME, "[WARN] initialize -> setUpTelegramBot -> err = " + err.stack); + } + + } } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); diff --git a/server.js b/server.js index 06ed86a90..f9c21fc95 100644 --- a/server.js +++ b/server.js @@ -72,7 +72,7 @@ if (global.TASK_NODE !== undefined) { } else { // I use this section to debug in standalone mode. - let argument = '{"type":"Task","name":"New Task","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"30min + 6hs down, dev < 15","id":"715839bb-a76c-427f-a48f-5bf1b2184070"},"id":"18dfca43-5015-40d9-824d-09b59b670e32"},{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"30min + 6hs down, dev < 20","id":"7a681e8d-7167-4edb-bb2f-90e12c7f5418"},"id":"5ccdbb76-4e45-4377-bc44-fd0f95e40deb"}],"id":"22b61a44-4fcc-4f6d-bb7c-4c2a24acbfbc"},"id":"9238ed0b-7cc6-4732-83e6-8ac8d52f6dd3"}' + let argument = ' {"type":"Task","name":"Runs Backtests","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"20 Minutes","code":{"folderName":"Backtest-01"},"parameters":{"type":"Parameters","name":"Parameters","baseAsset":{"type":"Base Asset","name":"Base Asset","code":{"name":"BTC","initialBalance":0.001,"minimumBalance":0.0001,"maximumBalance":1},"id":"666f6f10-2f17-4f5e-951c-b532bdb574d2"},"timeRange":{"type":"Time Range","name":"Time Range","code":{"initialDatetime":"2019-09-01T00:00:00.000Z","finalDatetime":"2019-09-05T00:00:00.000Z"},"id":"172958dd-b268-4444-8163-70979538ea6e"},"timePeriod":{"type":"Time Period","name":"Time Period","code":"01-hs","id":"37ee839d-9a7c-410c-9251-c33b8f1b99f7"},"slippage":{"type":"Slippage","name":"Slippage","code":{"positionRate":0.1,"stopLoss":0.1,"takeProfit":0.1},"id":"86ebd973-6ad9-4070-aece-a87623f24c2e"},"feeStructure":{"type":"Fee Structure","name":"Fee Structure","code":{"maker":0.15,"taker":0.25},"id":"a0ec3f6f-6047-4740-87fe-393b1c714adb"},"key":{"type":"Exchange Account Key","name":"New Key","code":"Paste your exchange API secret key here and the put the key name as this key object title. Secret keys are filtered out and NOT exported when using the SHARE menu option on any object at your workspace. Secret keys ARE downloaded when using the download button.","id":"368f879d-e363-47c7-b55e-7b927d896b20"},"id":"09db5e1e-a7e8-468c-ad70-0d2ab1c8b8b8"},"layerManager":{"type":"Layer Manager","name":"New Layer Manager","layers":[{"type":"Layer","name":"Live","code":{"product":"Live-Trading-History"},"id":"0ec05e1c-230b-44a1-9f2c-fba0ea2ff9e2"},{"type":"Layer","name":"Trades","code":{"product":"Simulation-Trades"},"id":"6326e03a-96c0-4d21-b877-f2c6a0419fc5"},{"type":"Layer","name":"Strategies","code":{"product":"Simulation-Strategies"},"id":"bda1e06c-e569-4bd5-95fb-90154aafb003"},{"type":"Layer","name":"Simulation","code":{"product":"Trading-Simulation"},"id":"d58d8cd2-f125-4f0c-b241-08e2af8ac4be"},{"type":"Layer","name":"Formulas & Conditions","code":{"product":"Simulation-Conditions"},"id":"15dfeca0-acd9-40d3-afe0-4805654bf0d0"}],"id":"884c4dd7-4beb-43fb-bda5-d6097d58ae09"},"socialBots":{"type":"Social Bots","name":"New Social Bots","bots":[{"type":"Telegram Bot","name":"New Telegram Bot","code":{"botToken":"861966974:AAEx9Gfg4boBDX_ZzqNjxXSzIK4fweFwH9A","chatId":-330926442},"announcements":[],"id":"b7fdad03-d096-4e9c-b7f5-6bf6d697c3dd"}],"id":"281eb022-cf9f-4ac2-978b-c8358bee8fec"},"id":"121202ea-6735-4bf3-8a95-aaa55f00f6e7"},"id":"3f483482-d8a1-4755-ba50-7cac6296fa5f"}],"id":"25fe9099-b53d-4757-8a63-3f8a15875f33"},"id":"5b21d2d2-0f52-4408-83eb-ddaa844ec58c"}' /* charly argument = '{"type":"Task","name":"Brings Trades Records from the Exchange","bot":{"type":"Sensor","name":"Charly","processes":[{"type":"Process","name":"Live Trades","code":{"team":"AAMasters","bot":"AACharly","process":"Live-Trades"},"id":"5846ebc7-1979-4a80-9cc7-94bb4b8659dc"},{"type":"Process","name":"Hole Fixing","code":{"team":"AAMasters","bot":"AACharly","process":"Hole-Fixing"},"id":"31fc4f05-75d4-419a-9fb0-73e25e856f15"}]},"id":"5bfef4dc-54c1-44db-ace6-1ab27a86746e"}' // olivia argument = '{"type":"Task","name":"Generates 1 min to 24 hs Candles & Volumes","bot":{"type":"Indicator","name":"Olivia","processes":[{"type":"Process","name":"Daily","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Daily"},"id":"68cc8e1b-e94a-477e-82d0-15ecc9f1b9e2"},{"type":"Process","name":"Market","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Market"},"id":"e1ac5e3d-d491-4e90-baf4-d4e5b71a8b1a"}]},"id":"efe36e05-75ea-41b5-8d92-c6b27635c834"}' // bruce argument = ' {"type":"Task","name":"Converts Trades into 1 min Candles & Volumes","bot":{"type":"Indicator","name":"Bruce","processes":[{"type":"Process","name":"New Process","code":{"team":"AAMasters","bot":"AABruce","process":"Single-Period-Daily"},"id":"e184744f-5de0-41c1-ad4c-36960f4ced90"}]},"id":"42758590-a7bd-4712-a5c9-80a3a820c5b3"}' @@ -152,28 +152,6 @@ global.STOP_TASK_GRACEFULLY = false; function bootLoader() { - /* Telegram Bot Initialization */ - - try { -/* - const Telegraf = require('telegraf') - - global.TELEGRAM_BOT = new Telegraf(process.env.TELEGRAM_BOT_TOKEN) - global.TELEGRAM_BOT.start((ctx) => ctx.reply('Welcome')) - global.TELEGRAM_BOT.help((ctx) => ctx.reply('Send me a sticker')) - global.TELEGRAM_BOT.on('sticker', (ctx) => ctx.reply('??')) - global.TELEGRAM_BOT.hears('hi', (ctx) => ctx.reply('Hey there')) - global.TELEGRAM_BOT.launch() - - const Telegram = require('telegraf/telegram') - global.TELEGRAM_API = new Telegram(process.env.TELEGRAM_BOT_TOKEN) - global.TELEGRAM_API.sendMessage(process.env.TELEGRAM_GROUP_ID, "Task Manager Started.") -*/ - - } catch (err) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Telegram Initialization Failed. -> Error = " + err.stack); - } - /* Heartbeat sent to the UI */ let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id @@ -188,12 +166,7 @@ function bootLoader() { let event = { seconds: (new Date()).getSeconds() } - /* - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) - if (global.TELEGRAM_API !== undefined) { - global.TELEGRAM_API.sendMessage(process.env.TELEGRAM_GROUP_ID, "Task is Alive!") - } - */ + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) } for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { From e09083e9eb9b2b24464c777e55f673b295069a5d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 09:24:38 +0200 Subject: [PATCH 10/14] Formula to Announcement --- Session.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Session.js b/Session.js index eda16a9c8..29d974f0e 100644 --- a/Session.js +++ b/Session.js @@ -535,7 +535,11 @@ } if (socialBot.type === code.botType && socialBot.id === code.botId) { if (socialBot.type === "Telegram Bot") { - socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, code.text) + if (announcement.formulaValue !== undefined) { + socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, announcement.formulaValue) + } else { + socialBot.botInstance.telegramAPI.sendMessage(socialBot.botInstance.chatId, code.text) + } } } } catch (err) { From c69318a47968ac4ecd7cd25d7c361771af81f30a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 13:42:26 +0200 Subject: [PATCH 11/14] parameters come already parsed --- Session.js | 286 +++++++++++++++++++++++------------------------------ server.js | 2 +- 2 files changed, 125 insertions(+), 163 deletions(-) diff --git a/Session.js b/Session.js index 29d974f0e..bb081545d 100644 --- a/Session.js +++ b/Session.js @@ -44,7 +44,7 @@ return function runSession(message) { - console.log("runSession") + /* We are going to run the Definition comming at the event. */ bot.DEFINITION = JSON.parse(message.event.definition) bot.SESSION = JSON.parse(message.event.session) @@ -146,15 +146,9 @@ /* Reduce the balance */ let balancePercentage = 1 // This is the default value - try { - let code = JSON.parse(bot.SESSION.code) - - if (code.balancePercentage !== undefined) { - balancePercentage = code.balancePercentage - } - - } catch (err) { - parentLogger.write(MODULE_NAME, "[WARN] initialize -> startFordwardTesting -> Invalid value por balancePercentage. Using Default."); + + if (bot.SESSION.code.balancePercentage !== undefined) { + balancePercentage = bot.SESSION.code.balancePercentage } bot.VALUES_TO_USE.initialBalanceA = bot.VALUES_TO_USE.initialBalanceA * balancePercentage / 100 @@ -287,15 +281,109 @@ /* Base Asset and Initial Balances. */ { if (tradingSystem.parameters.baseAsset !== undefined) { - let code - try { - code = JSON.parse(tradingSystem.parameters.baseAsset.code); + let code = tradingSystem.parameters.baseAsset.code + + if (code.name !== undefined) { + bot.VALUES_TO_USE.baseAsset = code.name; + } + + 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 + } + } + } + } + + /* Time Period */ + if (tradingSystem.parameters.timePeriod !== undefined) { + bot.VALUES_TO_USE.timePeriod = tradingSystem.parameters.timePeriod.code + } + + /* Slippage */ + if (tradingSystem.parameters.slippage !== undefined) { + if (tradingSystem.parameters.slippage.code !== undefined) { + + let code = tradingSystem.parameters.slippage.code + + if (code.positionRate !== undefined) { + bot.VALUES_TO_USE.slippage.positionRate = code.positionRate + } + if (code.stopLoss !== undefined) { + bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss + } + if (code.takeProfit !== undefined) { + bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit + } + } + } + + /* Fee Structure */ + if (tradingSystem.parameters.feeStructure !== undefined) { + if (tradingSystem.parameters.feeStructure.code !== undefined) { + + let code = tradingSystem.parameters.feeStructure.code + + if (code.maker !== undefined) { + bot.VALUES_TO_USE.feeStructure.maker = code.maker + } + if (code.taker !== undefined) { + bot.VALUES_TO_USE.feeStructure.taker = code.taker + } + } + } + + /* Time Range */ + if (tradingSystem.parameters.timeRange !== undefined) { + if (tradingSystem.parameters.timeRange.code !== undefined) { + + let code = tradingSystem.parameters.timeRange.code + if (code.initialDatetime !== undefined) { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) + } + if (code.finalDatetime !== undefined) { + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) + } + } + } + } + + /* Applying Session Level Parameters */ + if (bot.SESSION !== undefined) { + if (bot.SESSION.parameters !== undefined) { + + /* Base Asset and Initial Balances. */ + { + if (bot.SESSION.parameters.baseAsset !== undefined) { + let code = bot.SESSION.parameters.baseAsset.code if (code.name !== undefined) { bot.VALUES_TO_USE.baseAsset = code.name; } - if (bot.VALUES_TO_USE.baseAsset === 'BTC') { + if (bot.VALUES_TO_USE.baseAsset === 'BTC') { if (code.initialBalance !== undefined) { bot.VALUES_TO_USE.initialBalanceA = code.initialBalance; bot.VALUES_TO_USE.initialBalanceB = 0 @@ -322,121 +410,6 @@ bot.VALUES_TO_USE.maximumBalanceA = 0 } } - } catch (err) { - tradingSystem.parameters.baseAsset.error = err.message - } - } - } - - /* Time Period */ - if (tradingSystem.parameters.timePeriod !== undefined) { - bot.VALUES_TO_USE.timePeriod = tradingSystem.parameters.timePeriod.code - } - - /* Slippage */ - if (tradingSystem.parameters.slippage !== undefined) { - if (tradingSystem.parameters.slippage.code !== undefined) { - try { - let code = JSON.parse(tradingSystem.parameters.slippage.code) - - if (code.positionRate !== undefined) { - bot.VALUES_TO_USE.slippage.positionRate = code.positionRate - } - if (code.stopLoss !== undefined) { - bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss - } - if (code.takeProfit !== undefined) { - bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit - } - - } catch (err) { - tradingSystem.parameters.slippage.error = err.message - } - } - } - - /* Fee Structure */ - if (tradingSystem.parameters.feeStructure !== undefined) { - if (tradingSystem.parameters.feeStructure.code !== undefined) { - try { - let code = JSON.parse(tradingSystem.parameters.feeStructure.code) - - if (code.maker !== undefined) { - bot.VALUES_TO_USE.feeStructure.maker = code.maker - } - if (code.taker !== undefined) { - bot.VALUES_TO_USE.feeStructure.taker = code.taker - } - - } catch (err) { - tradingSystem.parameters.feeStructure.error = err.message - } - } - } - - /* Time Range */ - if (tradingSystem.parameters.timeRange !== undefined) { - if (tradingSystem.parameters.timeRange.code !== undefined) { - try { - let code = JSON.parse(tradingSystem.parameters.timeRange.code) - if (code.initialDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) - } - if (code.finalDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) - } - } catch (err) { - tradingSystem.parameters.timeRange.error = err.message - } - } - } - } - - /* Applying Session Level Parameters */ - if (bot.SESSION !== undefined) { - if (bot.SESSION.parameters !== undefined) { - - /* Base Asset and Initial Balances. */ - { - if (bot.SESSION.parameters.baseAsset !== undefined) { - let code - try { - code = JSON.parse(bot.SESSION.parameters.baseAsset.code); - - if (code.name !== undefined) { - bot.VALUES_TO_USE.baseAsset = code.name; - } - - 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 - } - } - } catch (err) { - parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Base Asset Value -> err = " + err.stack); - } } } @@ -448,21 +421,17 @@ /* Slippage */ if (bot.SESSION.parameters.slippage !== undefined) { if (bot.SESSION.parameters.slippage.code !== undefined) { - try { - let code = JSON.parse(bot.SESSION.parameters.slippage.code) - if (code.positionRate !== undefined) { - bot.VALUES_TO_USE.slippage.positionRate = code.positionRate - } - if (code.stopLoss !== undefined) { - bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss - } - if (code.takeProfit !== undefined) { - bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit - } + let code = bot.SESSION.parameters.slippage.code - } catch (err) { - parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Slippage Value -> err = " + err.stack); + if (code.positionRate !== undefined) { + bot.VALUES_TO_USE.slippage.positionRate = code.positionRate + } + if (code.stopLoss !== undefined) { + bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss + } + if (code.takeProfit !== undefined) { + bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit } } } @@ -470,18 +439,14 @@ /* Fee Structure */ if (bot.SESSION.parameters.feeStructure !== undefined) { if (bot.SESSION.parameters.feeStructure.code !== undefined) { - try { - let code = JSON.parse(bot.SESSION.parameters.feeStructure.code) - if (code.maker !== undefined) { - bot.VALUES_TO_USE.feeStructure.maker = code.maker - } - if (code.taker !== undefined) { - bot.VALUES_TO_USE.feeStructure.taker = code.taker - } + let code = bot.SESSION.parameters.feeStructure.code - } catch (err) { - parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Fee Structure Value -> err = " + err.stack); + if (code.maker !== undefined) { + bot.VALUES_TO_USE.feeStructure.maker = code.maker + } + if (code.taker !== undefined) { + bot.VALUES_TO_USE.feeStructure.taker = code.taker } } } @@ -489,16 +454,13 @@ /* Time Range */ if (bot.SESSION.parameters.timeRange !== undefined) { if (bot.SESSION.parameters.timeRange.code !== undefined) { - try { - let code = JSON.parse(bot.SESSION.parameters.timeRange.code) - if (code.initialDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) - } - if (code.finalDatetime !== undefined) { - bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) - } - } catch (err) { - parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Time Range Value -> err = " + err.stack); + + let code = bot.SESSION.parameters.timeRange.code + if (code.initialDatetime !== undefined) { + bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime) + } + if (code.finalDatetime !== undefined) { + bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime) } } } diff --git a/server.js b/server.js index f9c21fc95..82a8fcdc7 100644 --- a/server.js +++ b/server.js @@ -72,7 +72,7 @@ if (global.TASK_NODE !== undefined) { } else { // I use this section to debug in standalone mode. - let argument = ' {"type":"Task","name":"Runs Backtests","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"20 Minutes","code":{"folderName":"Backtest-01"},"parameters":{"type":"Parameters","name":"Parameters","baseAsset":{"type":"Base Asset","name":"Base Asset","code":{"name":"BTC","initialBalance":0.001,"minimumBalance":0.0001,"maximumBalance":1},"id":"666f6f10-2f17-4f5e-951c-b532bdb574d2"},"timeRange":{"type":"Time Range","name":"Time Range","code":{"initialDatetime":"2019-09-01T00:00:00.000Z","finalDatetime":"2019-09-05T00:00:00.000Z"},"id":"172958dd-b268-4444-8163-70979538ea6e"},"timePeriod":{"type":"Time Period","name":"Time Period","code":"01-hs","id":"37ee839d-9a7c-410c-9251-c33b8f1b99f7"},"slippage":{"type":"Slippage","name":"Slippage","code":{"positionRate":0.1,"stopLoss":0.1,"takeProfit":0.1},"id":"86ebd973-6ad9-4070-aece-a87623f24c2e"},"feeStructure":{"type":"Fee Structure","name":"Fee Structure","code":{"maker":0.15,"taker":0.25},"id":"a0ec3f6f-6047-4740-87fe-393b1c714adb"},"key":{"type":"Exchange Account Key","name":"New Key","code":"Paste your exchange API secret key here and the put the key name as this key object title. Secret keys are filtered out and NOT exported when using the SHARE menu option on any object at your workspace. Secret keys ARE downloaded when using the download button.","id":"368f879d-e363-47c7-b55e-7b927d896b20"},"id":"09db5e1e-a7e8-468c-ad70-0d2ab1c8b8b8"},"layerManager":{"type":"Layer Manager","name":"New Layer Manager","layers":[{"type":"Layer","name":"Live","code":{"product":"Live-Trading-History"},"id":"0ec05e1c-230b-44a1-9f2c-fba0ea2ff9e2"},{"type":"Layer","name":"Trades","code":{"product":"Simulation-Trades"},"id":"6326e03a-96c0-4d21-b877-f2c6a0419fc5"},{"type":"Layer","name":"Strategies","code":{"product":"Simulation-Strategies"},"id":"bda1e06c-e569-4bd5-95fb-90154aafb003"},{"type":"Layer","name":"Simulation","code":{"product":"Trading-Simulation"},"id":"d58d8cd2-f125-4f0c-b241-08e2af8ac4be"},{"type":"Layer","name":"Formulas & Conditions","code":{"product":"Simulation-Conditions"},"id":"15dfeca0-acd9-40d3-afe0-4805654bf0d0"}],"id":"884c4dd7-4beb-43fb-bda5-d6097d58ae09"},"socialBots":{"type":"Social Bots","name":"New Social Bots","bots":[{"type":"Telegram Bot","name":"New Telegram Bot","code":{"botToken":"861966974:AAEx9Gfg4boBDX_ZzqNjxXSzIK4fweFwH9A","chatId":-330926442},"announcements":[],"id":"b7fdad03-d096-4e9c-b7f5-6bf6d697c3dd"}],"id":"281eb022-cf9f-4ac2-978b-c8358bee8fec"},"id":"121202ea-6735-4bf3-8a95-aaa55f00f6e7"},"id":"3f483482-d8a1-4755-ba50-7cac6296fa5f"}],"id":"25fe9099-b53d-4757-8a63-3f8a15875f33"},"id":"5b21d2d2-0f52-4408-83eb-ddaa844ec58c"}' + let argument = '{"type":"Task","name":"Runs Backtests","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"Backtest 01","code":{"folderName":"Backtest-01"},"parameters":{"type":"Parameters","name":"Parameters","baseAsset":{"type":"Base Asset","name":"Base Asset","code":{"name":"BTC","initialBalance":0.001,"minimumBalance":0.0001,"maximumBalance":1},"id":"666f6f10-2f17-4f5e-951c-b532bdb574d2"},"timeRange":{"type":"Time Range","name":"Time Range","code":{"initialDatetime":"2019-09-24T00:00:00.000Z","finalDatetime":"2019-09-27T00:00:00.000Z"},"id":"172958dd-b268-4444-8163-70979538ea6e"},"timePeriod":{"type":"Time Period","name":"Time Period","code":"10-min","id":"37ee839d-9a7c-410c-9251-c33b8f1b99f7"},"slippage":{"type":"Slippage","name":"Slippage","code":{"positionRate":0.1,"stopLoss":0.1,"takeProfit":0.1},"id":"86ebd973-6ad9-4070-aece-a87623f24c2e"},"feeStructure":{"type":"Fee Structure","name":"Fee Structure","code":{"maker":0.15,"taker":0.25},"id":"a0ec3f6f-6047-4740-87fe-393b1c714adb"},"key":{"type":"Exchange Account Key","name":"New Key","code":"Paste your exchange API secret key here and the put the key name as this key object title. Secret keys are filtered out and NOT exported when using the SHARE menu option on any object at your workspace. Secret keys ARE downloaded when using the download button.","id":"368f879d-e363-47c7-b55e-7b927d896b20"},"id":"09db5e1e-a7e8-468c-ad70-0d2ab1c8b8b8"},"layerManager":{"type":"Layer Manager","name":"New Layer Manager","layers":[{"type":"Layer","name":"Live","code":{"product":"Live-Trading-History"},"id":"0ec05e1c-230b-44a1-9f2c-fba0ea2ff9e2"},{"type":"Layer","name":"Trades","code":{"product":"Simulation-Trades"},"id":"6326e03a-96c0-4d21-b877-f2c6a0419fc5"},{"type":"Layer","name":"Strategies","code":{"product":"Simulation-Strategies"},"id":"bda1e06c-e569-4bd5-95fb-90154aafb003"},{"type":"Layer","name":"Simulation","code":{"product":"Trading-Simulation"},"id":"d58d8cd2-f125-4f0c-b241-08e2af8ac4be"},{"type":"Layer","name":"Formulas & Conditions","code":{"product":"Simulation-Conditions"},"id":"15dfeca0-acd9-40d3-afe0-4805654bf0d0"}],"id":"884c4dd7-4beb-43fb-bda5-d6097d58ae09"},"socialBots":{"type":"Social Bots","name":"New Social Bots","bots":[],"id":"281eb022-cf9f-4ac2-978b-c8358bee8fec"},"id":"121202ea-6735-4bf3-8a95-aaa55f00f6e7"},"id":"3f483482-d8a1-4755-ba50-7cac6296fa5f"}],"id":"25fe9099-b53d-4757-8a63-3f8a15875f33"},"id":"5b21d2d2-0f52-4408-83eb-ddaa844ec58c"}' /* charly argument = '{"type":"Task","name":"Brings Trades Records from the Exchange","bot":{"type":"Sensor","name":"Charly","processes":[{"type":"Process","name":"Live Trades","code":{"team":"AAMasters","bot":"AACharly","process":"Live-Trades"},"id":"5846ebc7-1979-4a80-9cc7-94bb4b8659dc"},{"type":"Process","name":"Hole Fixing","code":{"team":"AAMasters","bot":"AACharly","process":"Hole-Fixing"},"id":"31fc4f05-75d4-419a-9fb0-73e25e856f15"}]},"id":"5bfef4dc-54c1-44db-ace6-1ab27a86746e"}' // olivia argument = '{"type":"Task","name":"Generates 1 min to 24 hs Candles & Volumes","bot":{"type":"Indicator","name":"Olivia","processes":[{"type":"Process","name":"Daily","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Daily"},"id":"68cc8e1b-e94a-477e-82d0-15ecc9f1b9e2"},{"type":"Process","name":"Market","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Market"},"id":"e1ac5e3d-d491-4e90-baf4-d4e5b71a8b1a"}]},"id":"efe36e05-75ea-41b5-8d92-c6b27635c834"}' // bruce argument = ' {"type":"Task","name":"Converts Trades into 1 min Candles & Volumes","bot":{"type":"Indicator","name":"Bruce","processes":[{"type":"Process","name":"New Process","code":{"team":"AAMasters","bot":"AABruce","process":"Single-Period-Daily"},"id":"e184744f-5de0-41c1-ad4c-36960f4ced90"}]},"id":"42758590-a7bd-4712-a5c9-80a3a820c5b3"}' From 88d9c630da434d0df6b8b0750aca5324f1680a42 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 14:24:00 +0200 Subject: [PATCH 12/14] id added to foldername --- Session.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Session.js b/Session.js index bb081545d..626eaec34 100644 --- a/Session.js +++ b/Session.js @@ -24,7 +24,7 @@ if (bot.processNode.session.code.folderName === undefined) { bot.SESSION.folderName = bot.SESSION.id } else { - bot.SESSION.folderName = bot.processNode.session.code.folderName + bot.SESSION.folderName = bot.processNode.session.code.folderName + "-" + bot.SESSION.id } /* Check if there is a session */ @@ -53,15 +53,12 @@ /* Set the folderName for logging, reports, context and data output */ let code if (bot.SESSION.code !== undefined) { - try { - code = JSON.parse(bot.SESSION.code) - if (code.folderName === undefined) { - bot.SESSION.folderName = bot.SESSION.id - } else { - bot.SESSION.folderName = code.folderName - } - } catch (err) { - bot.SESSION.folderName = bot.SESSION.id + + code = bot.SESSION.code + if (code.folderName === undefined) { + bot.SESSION.folderName = bot.SESSION.id + } else { + bot.SESSION.folderName = code.folderName + "-" + bot.SESSION.id } } From 0a53e27abc107b7d43b74b03981f6026ca5b6843 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 15:31:10 +0200 Subject: [PATCH 13/14] Data Range Updated by Events --- MultiPeriod.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index bbbbf4dfb..b30afd5d3 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -89,7 +89,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } let currentTimePeriod - let currentOutputPeriodLabel + let currentOutputPeriodName let market = global.MARKET; let botNeverRan = true; @@ -297,7 +297,7 @@ if (bot.VALUES_TO_USE.timePeriod === outputPeriodLabel) { currentTimePeriod = global.marketFilesPeriods[n][0]; - currentOutputPeriodLabel = global.marketFilesPeriods[n][1]; + currentOutputPeriodName = global.marketFilesPeriods[n][1]; } dependencyLoopBody(); @@ -598,7 +598,7 @@ if (bot.VALUES_TO_USE.timePeriod === outputPeriodLabel) { currentTimePeriod = global.dailyFilePeriods[n][0]; - currentOutputPeriodLabel = global.dailyFilePeriods[n][1]; + currentOutputPeriodName = global.dailyFilePeriods[n][1]; } let dependencyIndex = 0; @@ -850,7 +850,7 @@ usertBot.start( multiPeriodDataFiles, currentTimePeriod, - currentOutputPeriodLabel, + currentOutputPeriodName, bot.multiPeriodProcessDatetime, interExecutionMemoryArray[n], onBotFinished); @@ -872,7 +872,7 @@ writeMarketStatusReport(onMarketStatusReport) } else { - writeDataRanges(onWritten); + writeDataRanges(currentOutputPeriodName, onWritten); } function onWritten(err) { @@ -953,7 +953,7 @@ } } - function writeDataRanges(callBack) { + function writeDataRanges(currentOutputPeriodName, callBack) { try { @@ -964,9 +964,9 @@ function productLoopBody() { - let folderName = bot.products[productIndex].codeName; + let product = bot.products[productIndex]; - writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodProcessDatetime, folderName, controlLoop); + writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodProcessDatetime, product, currentOutputPeriodName, controlLoop); } function controlLoop() { @@ -987,7 +987,7 @@ } - function writeDataRange(pBegin, pEnd, pProductFolder, callBack) { + function writeDataRange(pBegin, pEnd, product, currentOutputPeriodName, callBack) { try { @@ -1001,7 +1001,7 @@ let fileContent = JSON.stringify(dataRange); let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; - let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + pProductFolder + "/" + 'Multi-Period-Daily' + fileName; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + product.codeName + "/" + 'Multi-Period-Daily' + fileName; fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); @@ -1019,6 +1019,13 @@ logger.write(MODULE_NAME, "[INFO] start -> writeDataRange -> onFileCreated -> Content written = " + fileContent); } + let key = bot.devTeam + "-" + bot.codeName + "-" + product.codeName + "-" + currentOutputPeriodName + let event = { + dateRange: dataRange + } + console.log(key) + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Data Range Updated', event) + callBack(global.DEFAULT_OK_RESPONSE); } } From 9d16680022ecb1b2f8cc62280a5a208fbb64dc8d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 17:15:31 +0200 Subject: [PATCH 14/14] Not Parsing --- MultiPeriod.js | 2 +- Session.js | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index b30afd5d3..df6dc1195 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -1023,7 +1023,7 @@ let event = { dateRange: dataRange } - console.log(key) + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Data Range Updated', event) callBack(global.DEFAULT_OK_RESPONSE); diff --git a/Session.js b/Session.js index 626eaec34..2f7b77ab2 100644 --- a/Session.js +++ b/Session.js @@ -473,12 +473,8 @@ for (let i = 0; i < bot.SESSION.socialBots.bots.length; i++) { let socialBot = bot.SESSION.socialBots.bots[i] if (socialBot.type === "Telegram Bot") { - try { - let code = JSON.parse(socialBot.code) - socialBot.botInstance = setUpTelegramBot(code.botToken, code.chatId) - } catch (err) { - parentLogger.write(MODULE_NAME, "[WARN] initialize -> setUpSocialBots -> err = " + err.stack); - } + let code = socialBot.code + socialBot.botInstance = setUpTelegramBot(code.botToken, code.chatId) } } }