From 1f3f8e03256e9e73f35b884977c9713c8c89fd9c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 2 May 2020 10:16:21 +0200 Subject: [PATCH] Bug fixed --- CanvasApp/FloatingSpace/ConditionEditor.js | 24 +++--- .../TradingSimulation.js | 12 ++- .../TradingSimulationAssetBalancesPanel.js | 79 +++++++++++++------ TaskServer/TradingBot.js | 18 ++++- TaskServer/TradingSimulation.js | 2 + 5 files changed, 93 insertions(+), 42 deletions(-) diff --git a/CanvasApp/FloatingSpace/ConditionEditor.js b/CanvasApp/FloatingSpace/ConditionEditor.js index 6c2eb1ac0..f0b2cbef7 100644 --- a/CanvasApp/FloatingSpace/ConditionEditor.js +++ b/CanvasApp/FloatingSpace/ConditionEditor.js @@ -150,10 +150,10 @@ function newConditionEditor () { checkAlgebra(logicOperand, logicOperand.comparison.operandB) } - function checkAlgebra (logicOperand, comparisonOperand, logicOperandIndex, comparisonOperandIndex) { + function checkAlgebra (logicOperand, comparisonOperand) { comparisonOperand.algebra = { - operandA: {}, - operandB: {} + operandA: { index: 0}, + operandB: { index: 1} } /* The default situation is that there is no Algebraic operation, meaning we will setup a Algebraic operation only with operandA */ @@ -194,19 +194,19 @@ function newConditionEditor () { comparisonOperand.algebra.operatorIndex = 4 } - initializePickersSet(comparisonOperand.algebra.operandA, logicOperandIndex, comparisonOperandIndex, 0) - initializePickersSet(comparisonOperand.algebra.operandB, logicOperandIndex, comparisonOperandIndex, 1) - updatePickers(comparisonOperand.algebra.operandA, comparisonOperand, logicOperand) - updatePickers(comparisonOperand.algebra.operandB, comparisonOperand, logicOperand) + initializePickersSet(logicOperand, comparisonOperand, comparisonOperand.algebra.operandA) + initializePickersSet(logicOperand, comparisonOperand, comparisonOperand.algebra.operandA) + updatePickers(logicOperand, comparisonOperand, comparisonOperand.algebra.operandA) + updatePickers(logicOperand, comparisonOperand, comparisonOperand.algebra.operandA) } - function initializePickersSet (algebraOperand, logicOperandIndex, comparisonOperandIndex, algebraOperandIndex) { + function initializePickersSet (logicOperand, comparisonOperand, algebraOperand) { /* Get the ySign */ let ySign - if (algebraOperandIndex === 0) { + if (algebraOperand.index === 0) { ySign = -1 } - if (algebraOperandIndex === 1) { + if (algebraOperand.index === 1) { ySign = 1 } @@ -309,7 +309,7 @@ function newConditionEditor () { algebraOperand.timeFramePicker.eventSuscriptionId = algebraOperand.productPicker.container.eventHandler.listenToEvent('onParentChanged', algebraOperand.timeFramePicker.onParentChanged) } - function updatePickers (algebraOperand, comparisonOperand, logicOperand) { + function updatePickers (logicOperand, comparisonOperand, algebraOperand) { let codeArray = algebraOperand.code.split('.') let codeTimeFrame = codeArray[1].substring(2, 4) + '-' + codeArray[1].substring(4, 7) @@ -341,7 +341,7 @@ function newConditionEditor () { algebraOperand.whenPicker.setSelected(undefined, undefined, undefined, propertyDisplacement) let codeProperty = codeArray[3 + propertyDisplacement] - let codeValue = codeBArray[0].replace('"', '').replace('"', '') + let codeValue = comparisonOperand.algebra.operandB.code.replace('"', '').replace('"', '') let dataMines = Object.keys(scanResult) for (let i = 0; i < dataMines.length; i++) { diff --git a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulation.js b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulation.js index 624c489c2..f9b3b5787 100644 --- a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulation.js +++ b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulation.js @@ -385,8 +385,10 @@ record.maximunBalanceB = dailyFile[i][32]; record.baseAsset = dailyFile[i][33]; record.quotedAsset = dailyFile[i][34]; - record.positionPeriods = dailyFile[i][35]; - record.positionDays = dailyFile[i][36]; + record.marketBaseAsset = dailyFile[i][35]; + record.marketQuotedAsset = dailyFile[i][36]; + record.positionPeriods = dailyFile[i][37]; + record.positionDays = dailyFile[i][38]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -477,8 +479,10 @@ record.maximunBalanceB = marketFile[i][32]; record.baseAsset = marketFile[i][33]; record.quotedAsset = marketFile[i][34]; - record.positionPeriods = marketFile[i][35]; - record.positionDays = marketFile[i][36]; + record.marketBaseAsset = marketFile[i][35]; + record.marketQuotedAsset = marketFile[i][36]; + record.positionPeriods = marketFile[i][37]; + record.positionDays = marketFile[i][38]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && diff --git a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulationAssetBalancesPanel.js b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulationAssetBalancesPanel.js index 3cc23fa0e..7272577da 100644 --- a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulationAssetBalancesPanel.js +++ b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/TradingSimulationAssetBalancesPanel.js @@ -154,33 +154,64 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul return } - params = {} - params.VALUE = currentRecord.balanceA; - params.INIT_VALUE = currentRecord.initialBalanceA - params.MIN_VALUE = currentRecord.minimunBalanceA - params.MAX_VALUE = currentRecord.maximunBalanceA - params.ASSET_LABEL = 'Asset A' - params.ASSET_NAME = currentRecord.baseAsset - params.LEFT_OFFSET = X_AXIS - params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset - params.DECIMALS = 4 + if (currentRecord.baseAsset === currentRecord.marketBaseAsset) { + params = {} + params.VALUE = currentRecord.balanceA; + params.INIT_VALUE = currentRecord.initialBalanceA + params.MIN_VALUE = currentRecord.minimunBalanceA + params.MAX_VALUE = currentRecord.maximunBalanceA + params.ASSET_LABEL = 'Base' + params.ASSET_NAME = currentRecord.baseAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 4 - paramsArray.push(params) + paramsArray.push(params) - params = {} - params.VALUE = currentRecord.balanceB; - params.MIN_VALUE = currentRecord.minimunBalanceB - params.INIT_VALUE = currentRecord.initialBalanceB - params.MAX_VALUE = currentRecord.maximunBalanceB - params.ASSET_LABEL = 'Asset B' - params.ASSET_NAME = currentRecord.quotedAsset - params.LEFT_OFFSET = X_AXIS - params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset - params.DECIMALS = 2 + params = {} + params.VALUE = currentRecord.balanceB; + params.MIN_VALUE = currentRecord.minimunBalanceB + params.INIT_VALUE = currentRecord.initialBalanceB + params.MAX_VALUE = currentRecord.maximunBalanceB + params.ASSET_LABEL = 'Quoted' + params.ASSET_NAME = currentRecord.quotedAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 2 + + paramsArray.push(params) + } else { + params = {} + params.VALUE = currentRecord.balanceB; + params.INIT_VALUE = currentRecord.initialBalanceB + params.MIN_VALUE = currentRecord.minimunBalanceB + params.MAX_VALUE = currentRecord.maximunBalanceB + params.ASSET_LABEL = 'Base' + params.ASSET_NAME = currentRecord.baseAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 4 + + paramsArray.push(params) + + params = {} + params.VALUE = currentRecord.balanceA; + params.MIN_VALUE = currentRecord.minimunBalanceA + params.INIT_VALUE = currentRecord.initialBalanceA + params.MAX_VALUE = currentRecord.maximunBalanceA + params.ASSET_LABEL = 'Quoted' + params.ASSET_NAME = currentRecord.quotedAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 2 + + paramsArray.push(params) + } - paramsArray.push(params) thisObject.assetBalances.setParamsArray(paramsArray) thisObject.assetBalances.draw() diff --git a/TaskServer/TradingBot.js b/TaskServer/TradingBot.js index 1335f875c..1a2852487 100644 --- a/TaskServer/TradingBot.js +++ b/TaskServer/TradingBot.js @@ -213,6 +213,8 @@ record.maximumBalanceB + "," + record.baseAsset + "," + record.quotedAsset + "," + + record.marketBaseAsset + "," + + record.marketQuotedAsset + "," + record.positionPeriods + "," + record.positionDays + "," + record.distanceToLastTriggerOn + "," + @@ -559,8 +561,14 @@ record.maximumBalanceB + "," + record.baseAsset + "," + record.quotedAsset + "," + + record.marketBaseAsset + "," + + record.marketQuotedAsset + "," + record.positionPeriods + "," + - record.positionDays + "]"; + record.positionDays + "," + + record.distanceToLastTriggerOn + "," + + record.distanceToLastTriggerOff + "," + + record.distanceToLastTakePosition + "," + + record.distanceToLastClosePosition + "]"; if (separator === "") { separator = ","; } @@ -664,8 +672,14 @@ record.maximumBalanceB + "," + record.baseAsset + "," + record.quotedAsset + "," + + record.marketBaseAsset + "," + + record.marketQuotedAsset + "," + record.positionPeriods + "," + - record.positionDays + "]"; + record.positionDays + "," + + record.distanceToLastTriggerOn + "," + + record.distanceToLastTriggerOff + "," + + record.distanceToLastTakePosition + "," + + record.distanceToLastClosePosition + "]"; if (separator === "") { separator = ","; } diff --git a/TaskServer/TradingSimulation.js b/TaskServer/TradingSimulation.js index 9fa497537..1e924e89c 100644 --- a/TaskServer/TradingSimulation.js +++ b/TaskServer/TradingSimulation.js @@ -2798,6 +2798,8 @@ maximumBalanceB: bot.VALUES_TO_USE.maximumBalanceB, baseAsset: quotedBaseAsset, quotedAsset: quotedQuotedAsset, + marketBaseAsset: '"' + bot.market.baseAsset + '"', + marketQuotedAsset: '"' + bot.market.quotedAsset + '"' , positionPeriods: positionPeriods, positionDays: positionDays, distanceToLastTriggerOn: distanceToLast.triggerOn,