From ded8100260a7a3ef9512df41868eaa19163a9a41 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Jan 2021 18:23:25 +0100 Subject: [PATCH] Error Handling Improved in a few modules of the LF Trading Bot --- ...error-order-quoted-asset-node-missing.json | 4 +- ...t-error-stage-base-asset-node-missing.json | 20 +++ ...error-stage-quoted-asset-node-missing.json | 20 +++ ...ng-bot-error-target-size-node-missing.json | 20 +++ ...ng-bot-error-size-placed-node-missing.json | 20 +++ ...g-bot-error-snapshot-unexpected-error.json | 101 +++++++++++++++ ...snapshot-instruction-evaluation-error.json | 119 ++++++++++++++++++ .../Low-Frequency-Trading/Snapshots.js | 22 +++- .../Low-Frequency-Trading/TradingExecution.js | 32 +++-- .../Low-Frequency-Trading/TradingPosition.js | 2 +- .../Low-Frequency-Trading/TradingStages.js | 35 ++++++ 11 files changed, 379 insertions(+), 16 deletions(-) create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-046-ts-lf-trading-bot-error-stage-base-asset-node-missing.json create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-047-ts-lf-trading-bot-error-stage-quoted-asset-node-missing.json create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-048-ts-lf-trading-bot-error-target-size-node-missing.json create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-049-ts-lf-trading-bot-error-size-placed-node-missing.json create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-050-ts-lf-trading-bot-error-snapshot-unexpected-error.json create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-051-ts-lf-trading-bot-error-snapshot-instruction-evaluation-error.json diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-038-ts-lf-trading-bot-error-order-quoted-asset-node-missing.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-038-ts-lf-trading-bot-error-order-quoted-asset-node-missing.json index 0ade8a411..016f53628 100644 --- a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-038-ts-lf-trading-bot-error-order-quoted-asset-node-missing.json +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-038-ts-lf-trading-bot-error-order-quoted-asset-node-missing.json @@ -3,8 +3,8 @@ "pageNumber": "38", "type": "TS LF Trading Bot Error - Order Quoted Asset Node Missing", "definition": { - "text": "A Order Quoted Asset Node was expected but not found at the node where the error poped up.", - "updated": 1611650168650 + "text": "An Order Quoted Asset Node was expected but not found at the node where the error poped up.", + "updated": 1611677527859 }, "paragraphs": [ { diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-046-ts-lf-trading-bot-error-stage-base-asset-node-missing.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-046-ts-lf-trading-bot-error-stage-base-asset-node-missing.json new file mode 100644 index 000000000..a1f688471 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-046-ts-lf-trading-bot-error-stage-base-asset-node-missing.json @@ -0,0 +1,20 @@ +{ + "topic": "TS LF Trading Bot Errors", + "pageNumber": "46", + "type": "TS LF Trading Bot Error - Stage Base Asset Node Missing", + "definition": { + "text": "A Stage Base Asset Asset Node was expected but not found at the node where the error poped up.", + "updated": 1611677607596 + }, + "paragraphs": [ + { + "style": "Error", + "text": "Stage Base Asset Node Missing", + "updated": 1611678203390 + }, + { + "style": "Success", + "text": "Add the missing node and try again." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-047-ts-lf-trading-bot-error-stage-quoted-asset-node-missing.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-047-ts-lf-trading-bot-error-stage-quoted-asset-node-missing.json new file mode 100644 index 000000000..bd0a16c01 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-047-ts-lf-trading-bot-error-stage-quoted-asset-node-missing.json @@ -0,0 +1,20 @@ +{ + "topic": "TS LF Trading Bot Errors", + "pageNumber": "47", + "type": "TS LF Trading Bot Error - Stage Quoted Asset Node Missing", + "definition": { + "text": "A Stage Quoted Asset Asset Node was expected but not found at the node where the error poped up.", + "updated": 1611677624495 + }, + "paragraphs": [ + { + "style": "Error", + "text": "Stage Quoted Asset Node Missing", + "updated": 1611678239797 + }, + { + "style": "Success", + "text": "Add the missing node and try again." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-048-ts-lf-trading-bot-error-target-size-node-missing.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-048-ts-lf-trading-bot-error-target-size-node-missing.json new file mode 100644 index 000000000..2899ec601 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-048-ts-lf-trading-bot-error-target-size-node-missing.json @@ -0,0 +1,20 @@ +{ + "topic": "TS LF Trading Bot Errors", + "pageNumber": "48", + "type": "TS LF Trading Bot Error - Target Size Node Missing", + "definition": { + "text": "A Target Size Node was expected but not found at the node where the error poped up.", + "updated": 1611677647791 + }, + "paragraphs": [ + { + "style": "Error", + "text": "Target Size Node Missing", + "updated": 1611678342962 + }, + { + "style": "Success", + "text": "Add the missing node and try again." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-049-ts-lf-trading-bot-error-size-placed-node-missing.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-049-ts-lf-trading-bot-error-size-placed-node-missing.json new file mode 100644 index 000000000..a783c3be0 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-049-ts-lf-trading-bot-error-size-placed-node-missing.json @@ -0,0 +1,20 @@ +{ + "topic": "TS LF Trading Bot Errors", + "pageNumber": "49", + "type": "TS LF Trading Bot Error - Size Placed Node Missing", + "definition": { + "text": "A Size Placed Node was expected but not found at the node where the error poped up.", + "updated": 1611677675945 + }, + "paragraphs": [ + { + "style": "Error", + "text": "Size Placed Node Missing", + "updated": 1611678372361 + }, + { + "style": "Success", + "text": "Add the missing node and try again." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-050-ts-lf-trading-bot-error-snapshot-unexpected-error.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-050-ts-lf-trading-bot-error-snapshot-unexpected-error.json new file mode 100644 index 000000000..20f01c5de --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-050-ts-lf-trading-bot-error-snapshot-unexpected-error.json @@ -0,0 +1,101 @@ +{ + "topic": "TS LF Trading Bot Errors", + "pageNumber": "50", + "type": "TS LF Trading Bot Error - Snapshot Unexpected Error", + "definition": { + "text": "The Trading Bot found an Unexpected Error during the generation of a Snapshot. The trading process continued but the task of generating the Snapshot was aborted.", + "updated": 1611681073241 + }, + "paragraphs": [ + { + "style": "Error", + "text": "Snapshot Unexpected Error", + "updated": 1611680863486 + }, + { + "style": "Title", + "text": "Error Details" + }, + { + "style": "Text", + "text": "In the following section you will find the specific information received when this error occured." + }, + { + "style": "Text", + "text": "You will only see it if you opened this page as a result of the error actually happening.", + "updated": 1611680880668 + }, + { + "style": "Subtitle", + "text": "Error Message" + }, + { + "style": "Text", + "text": "The following is the Error Message of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorMessage" + }, + { + "style": "Subtitle", + "text": "Error Stack" + }, + { + "style": "Text", + "text": "The following is the Error Stack of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorStack" + }, + { + "style": "Subtitle", + "text": "Error Code" + }, + { + "style": "Text", + "text": "The follwing is the Error Code of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorCode" + }, + { + "style": "Subtitle", + "text": "Error Details" + }, + { + "style": "Text", + "text": "The follwing are all the Error details of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorDetails" + }, + { + "style": "Subtitle", + "text": "Node Name" + }, + { + "style": "Text", + "text": "The follwing is the node's name of the Node most related to this error:" + }, + { + "style": "Placeholder", + "text": "nodeName" + }, + { + "style": "Subtitle", + "text": "Node Code" + }, + { + "style": "Text", + "text": "The follwing is the code stored at the node that produced the error at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "nodeCode" + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-051-ts-lf-trading-bot-error-snapshot-instruction-evaluation-error.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-051-ts-lf-trading-bot-error-snapshot-instruction-evaluation-error.json new file mode 100644 index 000000000..8bb6f4f8f --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-051-ts-lf-trading-bot-error-snapshot-instruction-evaluation-error.json @@ -0,0 +1,119 @@ +{ + "topic": "TS LF Trading Bot Errors", + "pageNumber": "51", + "type": "TS LF Trading Bot Error - Snapshot Instruction Evaluation Error", + "definition": { + "text": "This error occured while evaluation an instruction as part of the process of generating a Snapshot. This did not prevent the Snapshot to be created but that instruction value was set to zero.", + "updated": 1611681320900 + }, + "paragraphs": [ + { + "style": "Error", + "text": "Snapshot Instruction Evaluation Error", + "updated": 1611681105978 + }, + { + "style": "Title", + "text": "Error Details" + }, + { + "style": "Text", + "text": "In the following section you will find the specific information received when this error occured." + }, + { + "style": "Note", + "text": "You will only see it if you opened this page as a result of the error actually happening." + }, + { + "style": "Subtitle", + "text": "Error Message" + }, + { + "style": "Text", + "text": "The following is the Error Message of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorMessage" + }, + { + "style": "Subtitle", + "text": "Error Stack" + }, + { + "style": "Text", + "text": "The following is the Error Stack of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorStack" + }, + { + "style": "Subtitle", + "text": "Error Code" + }, + { + "style": "Text", + "text": "The follwing is the Error Code of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorCode" + }, + { + "style": "Subtitle", + "text": "Error Details" + }, + { + "style": "Text", + "text": "The follwing are all the Error details of the Exception that occured at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "errorDetails" + }, + { + "style": "Subtitle", + "text": "Node Name" + }, + { + "style": "Text", + "text": "The follwing is the node's name of the Node most related to this error:" + }, + { + "style": "Placeholder", + "text": "nodeName" + }, + { + "style": "Subtitle", + "text": "Node Code" + }, + { + "style": "Text", + "text": "The follwing is the code stored at the node that produced the error at the LF Trading Bot:" + }, + { + "style": "Placeholder", + "text": "nodeCode" + }, + { + "style": "Subtitle", + "text": "Context Info", + "updated": 1611681195733 + }, + { + "style": "Text", + "text": "The follwing is the context information preserved when the error occured:", + "updated": 1611681225358 + }, + { + "style": "Placeholder", + "text": "contextInfo", + "updated": 1611681233411 + }, + { + "style": "Text", + "text": "" + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js index ed3950d39..1e1a4ce48 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js @@ -240,6 +240,18 @@ exports.newSuperalgosBotModulesSnapshots = function (processIndex) { let value = eval(instruction) values.push(value) } catch (err) { + let docs = { + project: 'Superalgos', + category: 'Topic', + type: 'TS LF Trading Bot Error - Snapshot Instruction Evaluation Error', + placeholder: {} + } + + let contextInfo = { + instruction: instruction + } + TS.projects.superalgos.utilities.docsFunctions.buildPlaceholder(docs, err, nodeWithCode.name, nodeWithCode.code, undefined, undefined, contextInfo) + tradingSystem.errors.push([nodeWithCode.id, 'Instruction ' + instruction + ' evalueates with error ' + err.message]) values.push(0) } @@ -248,7 +260,15 @@ exports.newSuperalgosBotModulesSnapshots = function (processIndex) { } } } catch (err) { - tradingSystem.errors.push([nodeWithCode.id, err.message]) + let docs = { + project: 'Superalgos', + category: 'Topic', + type: 'TS LF Trading Bot Error - Snapshot Unexpected Error', + placeholder: {} + } + TS.projects.superalgos.utilities.docsFunctions.buildPlaceholder(docs, err, nodeWithCode.name, nodeWithCode.code, undefined) + + tradingSystem.errors.push([nodeWithCode.id, err.message, docs]) TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, '[ERROR] runSimulation -> addCodeToSnapshot -> nodeWithCode.code = ' + nodeWithCode.code) TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, '[ERROR] runSimulation -> addCodeToSnapshot -> err = ' + err.stack) } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingExecution.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingExecution.js index acc3141fc..d2bf43c82 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingExecution.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingExecution.js @@ -51,16 +51,16 @@ exports.newSuperalgosBotModulesTradingExecution = function (processIndex) { ) { try { /* Trading Engine Stage Validations */ - if (tradingEngineStage.stageBaseAsset === undefined) { badDefinitionUnhandledException(undefined, 'stageBaseAsset === undefined', tradingEngineStage) } - if (tradingEngineStage.stageBaseAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'stageBaseAsset.targetSize === undefined', tradingEngineStage) } - if (tradingEngineStage.stageBaseAsset.sizePlaced === undefined) { badDefinitionUnhandledException(undefined, 'stageBaseAsset.sizePlaced === undefined', tradingEngineStage) } - if (tradingEngineStage.stageBaseAsset.sizeFilled === undefined) { badDefinitionUnhandledException(undefined, 'stageBaseAsset.sizeFilled === undefined', tradingEngineStage) } - if (tradingEngineStage.stageBaseAsset.feesPaid === undefined) { badDefinitionUnhandledException(undefined, 'stageBaseAsset.feesPaid === undefined', tradingEngineStage) } - if (tradingEngineStage.stageQuotedAsset === undefined) { badDefinitionUnhandledException(undefined, 'stageQuotedAsset === undefined', tradingEngineStage) } - if (tradingEngineStage.stageQuotedAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'stageQuotedAsset.targetSize === undefined', tradingEngineStage) } - if (tradingEngineStage.stageQuotedAsset.sizePlaced === undefined) { badDefinitionUnhandledException(undefined, 'stageQuotedAsset.sizePlaced === undefined', tradingEngineStage) } - if (tradingEngineStage.stageQuotedAsset.sizeFilled === undefined) { badDefinitionUnhandledException(undefined, 'stageQuotedAsset.sizeFilled === undefined', tradingEngineStage) } - if (tradingEngineStage.stageQuotedAsset.feesPaid === undefined) { badDefinitionUnhandledException(undefined, 'stageQuotedAsset.feesPaid === undefined', tradingEngineStage) } + if (tradingEngineStage.stageBaseAsset === undefined) { badDefinitionUnhandledException(undefined, 'Stage Base Asset Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageBaseAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'Target Size Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageBaseAsset.sizePlaced === undefined) { badDefinitionUnhandledException(undefined, 'Size Placed Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageBaseAsset.sizeFilled === undefined) { badDefinitionUnhandledException(undefined, 'Size Filled Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageBaseAsset.feesPaid === undefined) { badDefinitionUnhandledException(undefined, 'Fees Paid Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageQuotedAsset === undefined) { badDefinitionUnhandledException(undefined, 'Stage Quoted Asset Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageQuotedAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'Target Size Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageQuotedAsset.sizePlaced === undefined) { badDefinitionUnhandledException(undefined, 'Size Placed Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageQuotedAsset.sizeFilled === undefined) { badDefinitionUnhandledException(undefined, 'Size Filled Node Missing', tradingEngineStage) } + if (tradingEngineStage.stageQuotedAsset.feesPaid === undefined) { badDefinitionUnhandledException(undefined, 'Fees Paid Node Missing', tradingEngineStage) } await checkExecutionAlgorithms(executionNode) @@ -89,7 +89,15 @@ exports.newSuperalgosBotModulesTradingExecution = function (processIndex) { } function badDefinitionUnhandledException(err, message, node) { - tradingSystem.errors.push([node.id, message]) + + let docs = { + project: 'Superalgos', + category: 'Topic', + type: 'TS LF Trading Bot Error - ' + message, + placeholder: {} + } + + tradingSystem.errors.push([node.id, message, docs]) TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> " + message); TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> node.name = " + node.name); @@ -98,7 +106,7 @@ exports.newSuperalgosBotModulesTradingExecution = function (processIndex) { if (err !== undefined) { TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> err.stack = " + err.stack); } - throw 'Please fix the problem and try again.' + throw 'Error Already Recorded' } } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js index 5bfbca03e..4ddc37c00 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js @@ -526,6 +526,6 @@ exports.newSuperalgosBotModulesTradingPosition = function (processIndex) { if (err !== undefined) { TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> err.stack = " + err.stack); } - throw 'Please fix the problem and try again.' + throw 'Error Already Recorded' } } \ No newline at end of file diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js index 144aa6ffa..27e0e22bb 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js @@ -380,6 +380,13 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) { } function initializeStageTargetSize() { + /* + Validations that all needed nodes are there. + */ + if (tradingEngine.current.strategyOpenStage.stageBaseAsset === undefined) { badDefinitionUnhandledException(undefined, 'Stage Base Asset Node Missing', tradingEngine.current.strategyOpenStage) } + if (tradingEngine.current.strategyOpenStage.stageBaseAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'Target Size Node Missing', tradingEngine.current.strategyOpenStage.stageBaseAsset) } + if (tradingEngine.current.strategyOpenStage.stageQuotedAsset === undefined) { badDefinitionUnhandledException(undefined, 'Stage Quoted Asset Node Missing', tradingEngine.current.strategyOpenStage) } + if (tradingEngine.current.strategyOpenStage.stageQuotedAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'Target Size Node Missing', tradingEngine.current.strategyOpenStage.stageQuotedAsset) } /* Here we will transform the position size into targets for each asset of the stage. */ @@ -851,6 +858,13 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) { } function initializeStageTargetSize() { + /* + Validations that all needed nodes are there. + */ + if (tradingEngine.current.strategyCloseStage.stageBaseAsset === undefined) { badDefinitionUnhandledException(undefined, 'Stage Base Asset Node Missing', tradingEngine.current.strategyCloseStage) } + if (tradingEngine.current.strategyCloseStage.stageBaseAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'Target Size Node Missing', tradingEngine.current.strategyCloseStage.stageBaseAsset) } + if (tradingEngine.current.strategyCloseStage.stageQuotedAsset === undefined) { badDefinitionUnhandledException(undefined, 'Stage Quoted Asset Node Missing', tradingEngine.current.strategyCloseStage) } + if (tradingEngine.current.strategyCloseStage.stageQuotedAsset.targetSize === undefined) { badDefinitionUnhandledException(undefined, 'Target Size Node Missing', tradingEngine.current.strategyCloseStage.stageQuotedAsset) } /* Here we will transform the position size into targets for each asset of the stage. */ @@ -1126,4 +1140,25 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) { function updateStatistics() { } + + function badDefinitionUnhandledException(err, message, node) { + + let docs = { + project: 'Superalgos', + category: 'Topic', + type: 'TS LF Trading Bot Error - ' + message, + placeholder: {} + } + + tradingSystem.errors.push([node.id, message, docs]) + + TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> " + message); + TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> node.name = " + node.name); + TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> node.type = " + node.type); + TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> node.config = " + JSON.stringify(node.config)); + if (err !== undefined) { + TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> err.stack = " + err.stack); + } + throw 'Error Already Recorded' + } } \ No newline at end of file