Simplifying step 1

This commit is contained in:
Luis Fernando Molina committed 2021-02-04 13:33:46 +01:00
1 parent c236b3887b
commit 4a8cb84f8c
4 files changed
+7 -97

No files matched your search

@@ -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
@@ -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
@@ -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 {
@@ -17,6 +17,8 @@ function newSuperalgosDocsSearchEngine() {
}
function setUpSearchEngine(callbackFunction) {
callbackFunction()
return
let totalAsyncCallsMade = 0
let totalAsyncCallsFinished = 0