From 4839ee9da118596c03f605087dcdee3951a94ed7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Jan 2021 13:29:30 +0100 Subject: [PATCH] Improving on LF Trading Formula evaluation error handling and UX / integration with the Docs --- .../Superalgos/Schemas/Docs-Concepts/lf.json | 13 ++ ...-bot-error-evaluating-condition-error.json | 2 +- ...ng-bot-error-evaluating-formula-error.json | 133 ++++++++++++++++++ .../Low-Frequency-Trading/TradingPosition.js | 12 +- .../Low-Frequency-Trading/TradingSystem.js | 27 ++-- 5 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 Projects/Superalgos/Schemas/Docs-Concepts/lf.json create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-002-ts-lf-trading-bot-error-evaluating-formula-error.json diff --git a/Projects/Superalgos/Schemas/Docs-Concepts/lf.json b/Projects/Superalgos/Schemas/Docs-Concepts/lf.json new file mode 100644 index 000000000..405f12272 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Concepts/lf.json @@ -0,0 +1,13 @@ +{ + "type": "LF", + "definition": { + "text": "LF is the abbreviation of Low Frequency, and most likey refering to the Low Frequency Trading Bot implemented at the Masters Trading Mine.", + "updated": 1611577213413 + }, + "paragraphs": [ + { + "style": "Text", + "text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode. Then you can use doscs.save to save your changes and app.contribute to send it to the main repository." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-001-ts-lf-trading-bot-error-evaluating-condition-error.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-001-ts-lf-trading-bot-error-evaluating-condition-error.json index 5246f5896..7f546e834 100644 --- a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-001-ts-lf-trading-bot-error-evaluating-condition-error.json +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-001-ts-lf-trading-bot-error-evaluating-condition-error.json @@ -9,7 +9,7 @@ "paragraphs": [ { "style": "Text", - "text": "While running at the TS, the Low Frequency Trading Bot encounteren an error while trying to evaluate one of your conditions defined at the Trading System. Conditions are arbitrary Javascript Code that user can write as they want and in some cases they do not write valid Javascript for Nod JS. ", + "text": "While running at the TS, the Low Frequency Trading Bot encountered an error while trying to evaluate one of your conditions defined at the Trading System. Conditions are arbitrary Javascript Code that user can write as they want and in some cases they do not write valid Javascript for Nod JS. ", "updated": 1611569329977 }, { diff --git a/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-002-ts-lf-trading-bot-error-evaluating-formula-error.json b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-002-ts-lf-trading-bot-error-evaluating-formula-error.json new file mode 100644 index 000000000..092bda662 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/ts-lf-trading-bot-errors-002-ts-lf-trading-bot-error-evaluating-formula-error.json @@ -0,0 +1,133 @@ +{ + "topic": "TS LF Trading Bot Errors", + "pageNumber": "2", + "type": "TS LF Trading Bot Error - Evaluating Formula Error", + "definition": { + "text": "An error occured while evaluation a User Defined Formula at the Trading System.", + "updated": 1611568961215 + }, + "paragraphs": [ + { + "style": "Text", + "text": "While running at the TS, the Low Frequency Trading Bot encountered an error while trying to evaluate one of your formulas defined at the Trading System. Formulas are arbitrary Javascript Code that user can write as they want and in some cases they do not write valid Javascript for Nod JS. ", + "updated": 1611569329977 + }, + { + "style": "Error", + "text": "Evaluating Formula Error", + "updated": 1611569347664 + }, + { + "style": "Title", + "text": "Error Details" + }, + { + "style": "Text", + "text": "In the following section you will find the specific information received when this error occured." + }, + { + "style": "Success", + "text": "You will only see it if you opened this page as a result of the error actually happening.", + "updated": 1611569373599 + }, + { + "style": "Subtitle", + "text": "Error Message" + }, + { + "style": "Text", + "text": "The following is the Error Message of the Exception that occured at the LF Trading Bot:", + "updated": 1611569424352 + }, + { + "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:", + "updated": 1611569434043 + }, + { + "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:", + "updated": 1611569440715 + }, + { + "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:", + "updated": 1611569446711 + }, + { + "style": "Placeholder", + "text": "errorDetails" + }, + { + "style": "Subtitle", + "text": "Node Name", + "updated": 1611571361685 + }, + { + "style": "Text", + "text": "The follwing is the node's name of the Node most related to this error:", + "updated": 1611571455498 + }, + { + "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:", + "updated": 1611569545869 + }, + { + "style": "Placeholder", + "text": "nodeCode", + "updated": 1611569590234 + }, + { + "style": "Subtitle", + "text": "Node Config", + "updated": 1611569510340 + }, + { + "style": "Text", + "text": "The follwing is the config stored at the node that produced the error at the LF Trading Bot:", + "updated": 1611569573367 + }, + { + "style": "Placeholder", + "text": "nodeConfig", + "updated": 1611569598109 + }, + { + "style": "Text", + "text": "" + } + ] +} \ No newline at end of file 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 0b4adb632..c67c9c99b 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 @@ -201,11 +201,11 @@ exports.newSuperalgosBotModulesTradingPosition = function (processIndex) { let value = tradingSystem.formulas.get(tradingSystemStageNode.initialTargets.targetRate.formula.id) if (value === undefined) { const message = 'Target Rate can not be undefined. Fix this please.' - badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetRate.formula) + badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetRate) } if (isNaN(value)) { const message = 'Target Rate must be a number. Fix this please.' - badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetRate.formula) + badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetRate) } switch (tradingSystemStageNode.type) { @@ -236,11 +236,11 @@ exports.newSuperalgosBotModulesTradingPosition = function (processIndex) { let value = tradingSystem.formulas.get(tradingSystemStageNode.initialTargets.targetSizeInBaseAsset.formula.id) if (value === undefined) { const message = 'Target Size In Base Asset cannot be undefined. Fix this please.' - badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInBaseAsset.formula) + badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInBaseAsset) } if (value === 0) { const message = 'Target Size In Base Asset cannot be zero. Fix this please.' - badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInBaseAsset.formula) + badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInBaseAsset) } switch (tradingSystemStageNode.type) { @@ -272,11 +272,11 @@ exports.newSuperalgosBotModulesTradingPosition = function (processIndex) { let value = tradingSystem.formulas.get(tradingSystemStageNode.initialTargets.targetSizeInQuotedAsset.formula.id) if (value === undefined) { const message = 'Target Size In Quoted Asset cannot be undefined. Fix this please.' - badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInQuotedAsset.formula) + badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInQuotedAsset) } if (value === 0) { const message = 'Target Size In Quoted Asset cannot be zero. Fix this please.' - badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInQuotedAsset.formula) + badDefinitionUnhandledException(undefined, message, tradingSystemStageNode.initialTargets.targetSizeInQuotedAsset) } switch (tradingSystemStageNode.type) { case 'Open Stage': { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js index 1ccf6a553..279eccb53 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js @@ -290,6 +290,7 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex) { function evalFormula(node) { let value let errorMessage + let docs try { TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, '[INFO] evalFormula -> ' + node.name + ' -> code = ' + node.code) @@ -301,21 +302,29 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex) { */ value = 0 errorMessage = err.message + docs = { + project: 'Superalgos', + category: 'Topic', + type: 'TS LF Trading Bot Error - Evaluating Formula Error', + placeholder: {} + } + TS.projects.superalgos.utilities.docsFunctions.buildPlaceholder(docs, err, node.name, node.code, undefined) } if (errorMessage !== undefined) { - tradingSystem.errors.push([node.id, errorMessage]) + tradingSystem.errors.push([node.id, errorMessage, docs]) TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, '[INFO] evalFormula -> errorMessage = ' + errorMessage) return - } - if (value !== undefined) { - if (node.type === 'Formula' && isNaN(value)) { - tradingSystem.errors.push([node.id, 'Formula needs to return a number.']) - return + } else { + if (value !== undefined) { + if (node.type === 'Formula' && isNaN(value)) { + tradingSystem.errors.push([node.id, 'Formula needs to return a number.']) + return + } + + tradingSystem.values.push([node.id, value]) + tradingSystem.formulas.set(node.id, value) } - - tradingSystem.values.push([node.id, value]) - tradingSystem.formulas.set(node.id, value) } TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, '[INFO] evalFormula -> value = ' + value)