Merge pull request #464 from Luis-Fernando-Molina/develop

Contribution: Improving on LF Trading Formula evaluation error handling and UX / integration with the Docs
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-01-25 13:30:31 +01:00
commit cb693be776
5 files changed
+171 -16

No files matched your search

@@ -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."
}
]
}
@@ -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
},
{
@@ -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": ""
}
]
}
@@ -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': {
@@ -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)