diff --git a/LowFrequencyTrading/TradingExecution.js b/LowFrequencyTrading/TradingExecution.js index 7a1288dde..b588689b7 100644 --- a/LowFrequencyTrading/TradingExecution.js +++ b/LowFrequencyTrading/TradingExecution.js @@ -233,7 +233,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE sizeFilledSimulation() amountReceivedSimulation() - doTheAccounting(previousSizeFilled, previousPercentageFilled, previousAmountReceived, previousFeesPaid) + doTheAccounting(tradingSystemOrder, tradingEngineOrder, previousSizeFilled, previousPercentageFilled, previousAmountReceived, previousFeesPaid) /* If the Stage is Closing and this order is still open, we need to cancel it now */ if (stageIsClosing === true && tradingEngineOrder.status.value !== 'Closed') { @@ -432,10 +432,10 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE tradingEngineOrder.orderStatistics.actualRate.value = order.price tradingEngineOrder.orderStatistics.actualRate.value = global.PRECISE(tradingEngineOrder.orderStatistics.actualRate.value, 10) - doTheAccounting(previousSizeFilled, previousPercentageFilled, previousAmountReceived, previousFeesPaid) + doTheAccounting(tradingSystemOrder, tradingEngineOrder, previousSizeFilled, previousPercentageFilled, previousAmountReceived, previousFeesPaid) } - function doTheAccounting(previousSizeFilled, previousPercentageFilled, previousAmountReceived, previousFeesPaid) { + function doTheAccounting(tradingSystemOrder, tradingEngineOrder, previousSizeFilled, previousPercentageFilled, previousAmountReceived, previousFeesPaid) { /* Unaccount for the previous Stage Filled Size */ stageFilledSize.value = stageFilledSize.value - tradingEngineOrder.size.value * previousPercentageFilled / 100 @@ -443,9 +443,10 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE stageFilledSize.value = stageFilledSize.value + tradingEngineOrder.size.value * tradingEngineOrder.orderStatistics.percentageFilled.value / 100 stageFilledSize.value = global.PRECISE(stageFilledSize.value, 10) + /* Balances Update */ - switch (order.side) { - case 'buy': { + switch (true) { + case tradingSystemOrder.type === 'Market Buy Order' || tradingSystemOrder.type === 'Limit Buy Order': { /* Undo the previous accounting */ tradingEngine.current.balance.baseAsset.value = tradingEngine.current.balance.baseAsset.value - previousFeesPaid - previousSizeFilled @@ -459,7 +460,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE break } - case 'sell': { + case tradingSystemOrder.type === 'Market Sell Order' || tradingSystemOrder.type === 'Limit Sell Order': { /* Undo the previous accounting */ tradingEngine.current.balance.baseAsset.value = tradingEngine.current.balance.baseAsset.value + previousFeesPaid + previousSizeFilled diff --git a/LowFrequencyTrading/TradingRecords.js b/LowFrequencyTrading/TradingRecords.js index d79347f2d..789d67feb 100644 --- a/LowFrequencyTrading/TradingRecords.js +++ b/LowFrequencyTrading/TradingRecords.js @@ -119,7 +119,14 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) { the Root Node specifically for this property only. */ if (recordProperty.config.nodePath !== undefined) { - propertyRootNode = eval(recordProperty.config.nodePath) + try { + propertyRootNode = eval(recordProperty.config.nodePath) + } catch (err) { + logger.write(MODULE_NAME, "[ERROR] appendRecords -> scanRecordDefinition -> Error at Record Property Definition -> recordProperty.name = " + recordProperty.name); + logger.write(MODULE_NAME, "[ERROR] appendRecords -> scanRecordDefinition -> Error at Record Property Definition -> recordProperty.config.nodePath = " + recordProperty.config.nodePath); + logger.write(MODULE_NAME, "[ERROR] appendRecords -> scanRecordDefinition -> Error at Record Property Definition -> err.stack = " + err.stack); + throw 'Can not continue with a Definition Error like this.' + } } /* The Target Node is the node from where we are going to exctract the value. diff --git a/server.js b/server.js index f2910b112..b9e30080f 100644 --- a/server.js +++ b/server.js @@ -47,12 +47,14 @@ global.PRECISE = function (floatNumber, precision) { process.on('uncaughtException', function (err) { console.log('[ERROR] Task Server -> server -> uncaughtException -> err.message = ' + err.message) console.log('[ERROR] Task Server -> server -> uncaughtException -> err.stack = ' + err.stack) + console.log(err.stack) global.EXIT_NODE_PROCESS() }) process.on('unhandledRejection', (reason, p) => { console.log('[ERROR] Task Server -> server -> unhandledRejection -> reason = ' + JSON.stringify(reason)) console.log('[ERROR] Task Server -> server -> unhandledRejection -> p = ' + JSON.stringify(p)) + console.log(reason.stack) global.EXIT_NODE_PROCESS() })