From 4a8cb84f8c9d4d16dcd78f6d4ce6ac658e30d8f1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 4 Feb 2021 13:33:46 +0100 Subject: [PATCH] Simplifying step 1 --- .../Low-Frequency-Trading/TradingOutput.js | 16 +---- .../Low-Frequency-Trading/TradingProcess.js | 24 +------ .../Trading-Bot/SingleMarketTradingBot.js | 62 +------------------ .../UI/Spaces/Docs-Space/SearchEngine.js | 2 + 4 files changed, 7 insertions(+), 97 deletions(-) diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js index d0a799b9a..348a4f064 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js @@ -6,26 +6,11 @@ exports.newSuperalgosBotModulesTradingOutput = function (processIndex) { const MODULE_NAME = 'Trading Output' let thisObject = { - initialize: initialize, - finalize: finalize, start: start } - let fileStorage = TS.projects.superalgos.taskModules.fileStorage.newFileStorage(processIndex) - return thisObject - function finalize() { - thisObject = undefined - utilities = undefined - fileStorage = undefined - commons = undefined - } - - function initialize() { - - } - async function start( chart, market, @@ -35,6 +20,7 @@ exports.newSuperalgosBotModulesTradingOutput = function (processIndex) { tradingProcessDate ) { try { + let fileStorage = TS.projects.superalgos.taskModules.fileStorage.newFileStorage(processIndex) if (timeFrame > TS.projects.superalgos.globals.timeFrames.dailyFilePeriods()[0][0]) { TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_PROCESSING_DAILY_FILES = false diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js index edcee3374..52197fb04 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js @@ -6,13 +6,10 @@ const MODULE_NAME = "Trading Process" thisObject = { - initialize: initialize, finalize: finalize, start: start } - let statusDependencies - let dataDependenciesModule let dataFiles = new Map() let multiTimeFrameDataFiles = new Map() let fileStorage = TS.projects.superalgos.taskModules.fileStorage.newFileStorage(processIndex) @@ -21,29 +18,11 @@ return thisObject - function initialize(pStatusDependencies, pDataDependencies, callBackFunction) { - try { - statusDependencies = pStatusDependencies - dataDependenciesModule = pDataDependencies - - tradingOutputModuleObject.initialize() - - callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE) - - } catch (err) { - TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).UNEXPECTED_ERROR = err - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[ERROR] initialize -> err = " + err.stack) - callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE) - } - } - function finalize() { TS.projects.superalgos.globals.processModuleObjects.MODULE_OBJECTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_MODULE_OBJECT.finalize() TS.projects.superalgos.globals.processModuleObjects.MODULE_OBJECTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_MODULE_OBJECT = undefined - tradingOutputModuleObject.finalize() tradingOutputModuleObject = undefined dataFiles = undefined @@ -54,8 +33,9 @@ thisObject = undefined } - async function start(callBackFunction) { + async function start(statusDependencies, dataDependenciesModule, callBackFunction) { try { + let currentTimeFrame let currentTimeFrameLabel diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/SingleMarketTradingBot.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/SingleMarketTradingBot.js index 3ce3a60e6..e9cf0705c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/SingleMarketTradingBot.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/SingleMarketTradingBot.js @@ -282,7 +282,7 @@ switch (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.framework.name) { case 'Low-Frequency-Trading-Process': { processFramework = TS.projects.superalgos.botModules.tradingProcess.newSuperalgosBotModulesTradingProcess(processIndex); - intitializeProcessFramework(); + startProcessFramework(); break; } default: { @@ -335,67 +335,9 @@ } } - function intitializeProcessFramework() { - try { - processFramework.initialize(statusDependencies, dataDependencies, onInizialized); - - function onInizialized(err) { - try { - switch (err.result) { - case TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result: { - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[INFO] run -> loop -> intitializeProcessFramework -> onInizialized -> Execution finished well."); - startProcessFramework(); - return; - } - case TS.projects.superalgos.globals.standardResponses.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized -> Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Operation Failed. Aborting the process."); - TS.projects.superalgos.functionLibraries.processFunctions.stopProcess(processIndex, callBackFunction, nextLoopTimeoutHandle) - return - } - case TS.projects.superalgos.globals.standardResponses.CUSTOM_OK_RESPONSE.result: { - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message); - TS.projects.superalgos.functionLibraries.processFunctions.stopProcess(processIndex, callBackFunction, nextLoopTimeoutHandle) - return - } - default: { - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err = " + err.message); - TS.projects.superalgos.functionLibraries.processFunctions.stopProcess(processIndex, callBackFunction, nextLoopTimeoutHandle) - return - } - } - } catch (err) { - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> err = " + err.stack); - TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).UNEXPECTED_ERROR = err - TS.projects.superalgos.functionLibraries.processFunctions.stopProcess(processIndex, callBackFunction, nextLoopTimeoutHandle) - return - } - } - } catch (err) { - TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, - "[ERROR] run -> loop -> intitializeProcessFramework -> err = " + err.stack); - TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).UNEXPECTED_ERROR = err - TS.projects.superalgos.functionLibraries.processFunctions.stopProcess(processIndex, callBackFunction, nextLoopTimeoutHandle) - return - } - } - function startProcessFramework() { try { - processFramework.start(onFinished); + processFramework.start(statusDependencies, dataDependencies, onFinished); function onFinished(err) { try { diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js index 101ce7823..ea44ac22f 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js @@ -17,6 +17,8 @@ function newSuperalgosDocsSearchEngine() { } function setUpSearchEngine(callbackFunction) { + callbackFunction() + return let totalAsyncCallsMade = 0 let totalAsyncCallsFinished = 0