From 3f66d48e7a07b58ed6bfcf8ed534bd1311073338 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 3 Sep 2020 09:55:43 +0200 Subject: [PATCH] More fixes --- AppSchema.json | 16 ++++----- .../LowFrequencyTrading/TradingOrders.js | 34 +++++++++++++++---- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/AppSchema.json b/AppSchema.json index 420e05397..eca0de787 100644 --- a/AppSchema.json +++ b/AppSchema.json @@ -733,9 +733,9 @@ }, "menuItems": [ { - "action": "Edit Image", + "action": "Configure", "actionFunction": "uiObject.configEditor.activate", - "label": "Edit Image", + "label": "Configure", "iconPathOn": "html", "iconPathOff": "html" }, @@ -839,9 +839,9 @@ }, "menuItems": [ { - "action": "Edit This", + "action": "Configure", "actionFunction": "uiObject.configEditor.activate", - "label": "Edit This", + "label": "Configure", "iconPathOn": "html", "iconPathOff": "html" }, @@ -1028,9 +1028,9 @@ }, "menuItems": [ { - "action": "Edit Text", + "action": "Configure", "actionFunction": "uiObject.configEditor.activate", - "label": "Edit Text", + "label": "Configure", "iconPathOn": "html", "iconPathOff": "html" }, @@ -11904,9 +11904,9 @@ }, "menuItems": [ { - "action": "Edit This", + "action": "Configure", "actionFunction": "uiObject.codeEditor.activate", - "label": "Edit This", + "label": "Configure", "iconPathOn": "html", "iconPathOff": "html" }, diff --git a/TaskServer/LowFrequencyTrading/TradingOrders.js b/TaskServer/LowFrequencyTrading/TradingOrders.js index a40021d99..04c320e0f 100644 --- a/TaskServer/LowFrequencyTrading/TradingOrders.js +++ b/TaskServer/LowFrequencyTrading/TradingOrders.js @@ -719,8 +719,17 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM /* Close this Order */ tradingEngineOrder.status.value = 'Closed' - tradingEngineOrder.exitType.value = 'Cancelled at the Exchange' + /* + We must be carefull here not to overide an already defined exitType. It can happen + for instance that the order was cancellerd from the bot, but veryfing the cancellation + was not possible because of a connection to the exchange problem. In that case + the exit type was defined but the order was kept open until the verification could be done. + */ + if (tradingEngineOrder.exitType.value === tradingEngineOrder.exitType.config.initialValue) { + tradingEngineOrder.exitType.value = 'Cancelled at the Exchange' + } + /* Initialize this */ tradingEngine.current.episode.distanceToEvent.closeOrder.value = 1 @@ -1096,12 +1105,9 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM /* Check if we can cancel the order at the Exchange. */ let result = await exchangeAPIModule.cancelOrder(tradingSystemOrder, tradingEngineOrder) if (result === true) { - /* Close this Order */ - tradingEngineOrder.status.value = 'Closed' - tradingEngineOrder.exitType.value = exitType - /* Initialize this */ - tradingEngine.current.episode.distanceToEvent.closeOrder.value = 1 + /* At this point we know which is the exit type for this order */ + tradingEngineOrder.exitType.value = exitType /* Perhaps the order was filled a bit more between the last time we checked and when it was cancelled. @@ -1110,7 +1116,21 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM let order = await exchangeAPIModule.getOrder(tradingSystemOrder, tradingEngineOrder) - if (order === undefined) { return } + if (order === undefined) { + tradingSystem.warnings.push([tradingSystemOrder.id, 'Could not verify the status of this order at the exchange, and syncronize the accounting.']) + return false + } + + /* + Close this Order. Note that we are not closing the order until we have the exchange + response with the order details that we can use to syncronize with our accoounting. + Otherwise if the connection to the exchange fails, we would have a closed order not + accounted in any way. + */ + tradingEngineOrder.status.value = 'Closed' + + /* Initialize this */ + tradingEngine.current.episode.distanceToEvent.closeOrder.value = 1 await syncWithExchange(tradingEngineStage, tradingSystemOrder, tradingEngineOrder, order)