diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index ef59d597b..13d85f703 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -462,11 +462,12 @@ function newPlottersManager () { canvas.panelsSpace.destroyPanel(productPlotters[i].panels[j]) } /* Finally the Storage Objects */ - productPlotters[i].storage.finalize() + if (productPlotters[i].plotter.finalize !== undefined) { productPlotters[i].plotter.container.finalize() productPlotters[i].plotter.finalize() } + productPlotters[i].storage.finalize() productPlotters.splice(i, 1) // Delete item from array. return // We already found the product woth changes and processed it. } @@ -530,4 +531,3 @@ function newPlottersManager () { } } } - diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index 98e7eb14e..b73e1a75e 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -35,9 +35,9 @@ function newRestartSimulation () { let executionFocusExists = false let idleLabel = '' - let refreshCounter = 0 let isRunning = false - let eventSubscriptionId + + let eventSubscriptionIdProcessStopped return thisObject @@ -46,7 +46,8 @@ function newRestartSimulation () { thisObject.container.eventHandler.stopListening(selfMouseClickEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfMouseNotOverEventSubscriptionId) - systemEventHandler.stopListening('Jason-Multi-Period', eventSubscriptionId) + systemEventHandler.stopListening('Jason-Multi-Period', eventSubscriptionIdProcessStopped) + systemEventHandler.deleteEventHandler('Cockpit-Restart-Button') thisObject.container.finalize() thisObject.container = undefined @@ -64,20 +65,15 @@ function newRestartSimulation () { systemEventHandler.createEventHandler('Cockpit-Restart-Button') - /* - We will start listening to the event that is triggered when the simulation process finishes processing one day in the case - of daily files or the whole market in the case of market files. - */ - eventSubscriptionId = systemEventHandler.listenToEvent('Jason-Multi-Period', 'Status Report Updated', undefined, undefined, undefined, onEvent) + systemEventHandler.listenToEvent('Jason-Multi-Period', 'Process Stopped', undefined, 'Cockpit-Restart-Button', onResponse, onProcessStopped) - function onEvent (message) { - refreshCounter++ + function onResponse (message) { + eventSubscriptionIdProcessStopped = message.eventSubscriptionId + } - if (refreshCounter === 1) { - refreshCounter = 0 - turnOffProductCards() - turnOnProductCards() - } + function onProcessStopped (message) { + thisObject.status = 'Ready' + isRunning = false } } @@ -144,7 +140,6 @@ function newRestartSimulation () { systemEventHandler.raiseEvent('Cockpit-Restart-Button', 'Stop Requested') isRunning = false thisObject.status = 'Stopping' - counterTillNextState = 200 } } catch (err) { thisObject.status = 'Error' @@ -200,7 +195,7 @@ function newRestartSimulation () { break case 'Stopping': - thisObject.status = 'Ready' + break case 'Error': thisObject.status = 'Ready' diff --git a/FloatingSpace/CircularMenu.js b/FloatingSpace/CircularMenu.js index d35759070..4b4676921 100644 --- a/FloatingSpace/CircularMenu.js +++ b/FloatingSpace/CircularMenu.js @@ -5,6 +5,7 @@ function newCircularMenu () { let thisObject = { container: undefined, isDeployed: undefined, + internalClick: internalClick, physics: physics, drawBackground: drawBackground, drawForeground: drawForeground, @@ -57,6 +58,12 @@ function newCircularMenu () { menuItem.workingLabel = menuItemInitialValue.workingLabel menuItem.workDoneLabel = menuItemInitialValue.workDoneLabel menuItem.workFailedLabel = menuItemInitialValue.workFailedLabel + menuItem.secondaryAction = menuItemInitialValue.secondaryAction + menuItem.secondaryLabel = menuItemInitialValue.secondaryLabel + menuItem.secondaryWorkingLabel = menuItemInitialValue.secondaryWorkingLabel + menuItem.secondaryWorkDoneLabel = menuItemInitialValue.secondaryWorkDoneLabel + menuItem.secondaryWorkFailedLabel = menuItemInitialValue.secondaryWorkFailedLabel + menuItem.secondaryIcon = menuItemInitialValue.secondaryIcon menuItem.visible = menuItemInitialValue.visible menuItem.iconPathOn = menuItemInitialValue.iconPathOn menuItem.iconPathOff = menuItemInitialValue.iconPathOff @@ -90,49 +97,66 @@ function newCircularMenu () { if (thisObject.isDeployed === true) { for (let i = 0; i < menuItems.length; i++) { - let menutItem = menuItems[i] - container = menutItem.getContainer(point) + let menuItem = menuItems[i] + if (menuItem.visible === true) { + container = menuItem.getContainer(point) + } if (container !== undefined) { return container } } } } + function internalClick (action) { + for (let i = 0; i < menuItems.length; i++) { + let menuItem = menuItems[i] + if (menuItem.visible === true) { + if (menuItem.nextAction === action) { + menuItem.internalClick() + } + } + } + } + function physics () { for (let i = 0; i < menuItems.length; i++) { - let menutItem = menuItems[i] - menutItem.physics() + let menuItem = menuItems[i] + menuItem.physics() } } function onFocus () { for (let i = 0; i < menuItems.length; i++) { - let menutItem = menuItems[i] - menutItem.targetRadius = menutItem.rawRadius * 1.5 - menutItem.isDeployed = true + let menuItem = menuItems[i] + menuItem.targetRadius = menuItem.rawRadius * 1.5 + menuItem.isDeployed = true } thisObject.isDeployed = true } function onNotFocus () { for (let i = 0; i < menuItems.length; i++) { - let menutItem = menuItems[i] - menutItem.targetRadius = menutItem.rawRadius * 0 - i * 4 - menutItem.isDeployed = false + let menuItem = menuItems[i] + menuItem.targetRadius = menuItem.rawRadius * 0 - i * 4 + menuItem.isDeployed = false } thisObject.isDeployed = false } function drawBackground (pFloatingObject) { for (let i = 0; i < menuItems.length; i++) { - let menutItem = menuItems[i] - menutItem.drawBackground() + let menuItem = menuItems[i] + if (menuItem.visible === true) { + menuItem.drawBackground() + } } } function drawForeground (pFloatingObject) { for (let i = 0; i < menuItems.length; i++) { - let menutItem = menuItems[i] - menutItem.drawForeground() + let menuItem = menuItems[i] + if (menuItem.visible === true) { + menuItem.drawForeground() + } } } } diff --git a/FloatingSpace/CircularMenuItem.js b/FloatingSpace/CircularMenuItem.js index 40f87bfa0..9fb252e8b 100644 --- a/FloatingSpace/CircularMenuItem.js +++ b/FloatingSpace/CircularMenuItem.js @@ -17,6 +17,13 @@ function newCircularMenuItem () { workingLabel: undefined, workDoneLabel: undefined, workFailedLabel: undefined, + secondaryAction: undefined, + secondaryLabel: undefined, + secondaryWorkingLabel: undefined, + secondaryWorkDoneLabel: undefined, + secondaryWorkFailedLabel: undefined, + secondaryIcon: undefined, + nextAction: undefined, visible: false, iconPathOn: undefined, iconPathOff: undefined, @@ -28,6 +35,7 @@ function newCircularMenuItem () { payload: undefined, relatedStrategyPart: undefined, dontShowAtFullscreen: undefined, + internalClick: internalClick, physics: physics, drawBackground: drawBackground, drawForeground: drawForeground, @@ -57,8 +65,19 @@ function newCircularMenuItem () { let defaultBackgroudColor = UI_COLOR.RED let backgroundColorToUse = UI_COLOR.RED let temporaryStatus = 0 + let temporaryStatusCounter = 0 const EXTRA_MOUSE_OVER_ICON_SIZE = 2 + + const STATUS_NO_ACTION_TAKEN_YET = 0 + const STATUS_PRIMARY_ACTION_WORKING = -1 + const STATUS_SECONDARY_ACTION_WORKING = -2 + const STATUS_PRIMARY_WORK_DONE = -3 + const STATUS_PRIMARY_WORK_FAILED = -4 + const STATUS_WAITING_CONFIRMATION = -5 + const STATUS_SECONDARY_WORK_DONE = -6 + const STATUS_SECONDARY_WORK_FAILED = -7 + return thisObject function finalize () { @@ -90,6 +109,8 @@ function newCircularMenuItem () { } else { thisObject.container.frame.width = 50 } + + thisObject.nextAction = thisObject.action } function getContainer (point) { @@ -123,25 +144,39 @@ function newCircularMenuItem () { /* Temporary Status impacts on the label to use and the background of that label */ - temporaryStatus-- - if (temporaryStatus < 0) { - temporaryStatus = 0 + if (temporaryStatusCounter > 0) { + temporaryStatusCounter-- } - if (temporaryStatus === 0) { + + if (temporaryStatusCounter === 0) { + temporaryStatus = STATUS_NO_ACTION_TAKEN_YET labelToPrint = thisObject.label backgroundColorToUse = defaultBackgroudColor + thisObject.nextAction = thisObject.action } iconPhysics() } function iconPhysics () { - if (thisObject.relatedStrategyPart !== undefined) { - thisObject.iconOn = canvas.strategySpace.iconByPartType.get(thisObject.relatedStrategyPart) - thisObject.iconOff = canvas.strategySpace.iconByPartType.get(thisObject.relatedStrategyPart) + if ( + ( + temporaryStatus === STATUS_PRIMARY_WORK_DONE || + temporaryStatus === STATUS_SECONDARY_ACTION_WORKING || + temporaryStatus === STATUS_SECONDARY_WORK_DONE || + temporaryStatus === STATUS_SECONDARY_WORK_FAILED + ) && thisObject.secondaryAction !== undefined + ) { + thisObject.iconOn = canvas.strategySpace.iconCollection.get(thisObject.secondaryIcon) + thisObject.iconOff = canvas.strategySpace.iconCollection.get(thisObject.secondaryIcon) } else { - thisObject.iconOn = canvas.strategySpace.iconCollection.get(thisObject.iconPathOn) - thisObject.iconOff = canvas.strategySpace.iconCollection.get(thisObject.iconPathOff) + if (thisObject.relatedStrategyPart !== undefined) { + thisObject.iconOn = canvas.strategySpace.iconByPartType.get(thisObject.relatedStrategyPart) + thisObject.iconOff = canvas.strategySpace.iconByPartType.get(thisObject.relatedStrategyPart) + } else { + thisObject.iconOn = canvas.strategySpace.iconCollection.get(thisObject.iconPathOn) + thisObject.iconOff = canvas.strategySpace.iconCollection.get(thisObject.iconPathOff) + } } /* Current Status might be linked to some other object status */ @@ -171,38 +206,106 @@ function newCircularMenuItem () { isMouseOver = false } - async function onMouseClick (event) { - if (temporaryStatus === 0 && thisObject.askConfirmation !== true) { - if (thisObject.workingLabel !== undefined) { - setTemporaryStatus(thisObject.workingLabel, UI_COLOR.GREY, 500) + function internalClick () { + onMouseClick() + } + + function onMouseClick () { + if (thisObject.label === undefined) { + /* This is what we have in the case of menu items that are only Icons. In this situation there is no complex logic, just execute the specified action. */ + thisObject.actionFunction(thisObject.payload, thisObject.action) + return + } + + if (thisObject.askConfirmation !== true) { /* No confirmation is needed */ + if (temporaryStatus === STATUS_NO_ACTION_TAKEN_YET || temporaryStatus === STATUS_PRIMARY_WORK_DONE) { + executeAction() + } // Any click out of those states is ignored + } else { + /* Confirmation is needed */ + + /* The first click ask for confirmation. */ + if (temporaryStatus === STATUS_NO_ACTION_TAKEN_YET) { + setStatus(thisObject.confirmationLabel, UI_COLOR.GREY, 250, STATUS_WAITING_CONFIRMATION) + return } - - thisObject.currentStatus = await thisObject.actionFunction(thisObject.payload, thisObject.action) - - if (thisObject.currentStatus === true) { - if (thisObject.workDoneLabel !== undefined) { - setTemporaryStatus(thisObject.workDoneLabel, UI_COLOR.PATINATED_TURQUOISE, 250) - } - } else { - if (thisObject.workFailedLabel != undefined) { - setTemporaryStatus(thisObject.workFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500) - } + /* A Click during confirmation executes the pre-defined action. */ + if (temporaryStatus === STATUS_WAITING_CONFIRMATION || temporaryStatus === STATUS_PRIMARY_WORK_DONE) { + executeAction() + return } } - if (temporaryStatus > 0 && thisObject.askConfirmation === true) { - thisObject.currentStatus = await thisObject.actionFunction(thisObject.payload, thisObject.action) - } + function executeAction () { + if (temporaryStatus === STATUS_NO_ACTION_TAKEN_YET || temporaryStatus === STATUS_WAITING_CONFIRMATION) { + /* We need to execute the main Action */ + /* If there is a working label defined, we use it here. */ + if (thisObject.workingLabel !== undefined) { + setStatus(thisObject.workingLabel, UI_COLOR.GREY, undefined, STATUS_PRIMARY_ACTION_WORKING) // Status will not expire, will only change with a callback. Mouse Clicks will be ignored. + } - if (temporaryStatus === 0 && thisObject.askConfirmation === true) { - setTemporaryStatus(thisObject.confirmationLabel, UI_COLOR.GREY, 50) + /* Execute the action and wait for callbacks to update our statuus. */ + thisObject.actionFunction(thisObject.payload, thisObject.action, onPrimaryCallBack) + return + } + if (temporaryStatus === STATUS_PRIMARY_WORK_DONE && thisObject.secondaryAction !== undefined) { + /* We need to execute the secondary action. */ + if (thisObject.secondaryWorkingLabel !== undefined) { + setStatus(thisObject.secondaryWorkingLabel, UI_COLOR.GREY, undefined, STATUS_SECONDARY_ACTION_WORKING) // Status will not expire, will only change with a callback. Mouse Clicks will be ignored. + } + + /* Execute the action and wait for callbacks to update our statuus. */ + thisObject.actionFunction(thisObject.payload, thisObject.secondaryAction, onSecondaryCallBack) + return + } + + function onPrimaryCallBack (err) { + /* If there is a secondary action we will act different that if there is not */ + if (thisObject.secondaryAction === undefined) { // This means there are no more possible actions. + if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { + if (thisObject.workDoneLabel !== undefined) { + setStatus(thisObject.workDoneLabel, UI_COLOR.PATINATED_TURQUOISE, 250, STATUS_PRIMARY_WORK_DONE) + } + } else { + if (thisObject.workFailedLabel != undefined) { + setStatus(thisObject.workFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500, STATUS_PRIMARY_WORK_FAILED) + } + } + } else { + if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { + if (thisObject.workDoneLabel !== undefined) { + thisObject.nextAction = thisObject.secondaryAction + setStatus(thisObject.secondaryLabel, defaultBackgroudColor, undefined, STATUS_PRIMARY_WORK_DONE) + } + } else { + if (thisObject.workFailedLabel != undefined) { + setStatus(thisObject.workFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500, STATUS_PRIMARY_WORK_FAILED) + } + } + } + } + function onSecondaryCallBack (err) { + if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { + if (thisObject.secondaryWorkDoneLabel !== undefined) { + setStatus(thisObject.secondaryWorkDoneLabel, UI_COLOR.PATINATED_TURQUOISE, 250, STATUS_SECONDARY_WORK_DONE) + } + } else { + if (thisObject.secondaryWorkFailedLabel != undefined) { + setStatus(thisObject.secondaryWorkFailedLabel, UI_COLOR.TITANIUM_YELLOW, 500, STATUS_SECONDARY_WORK_FAILED) + } + } + } } } - function setTemporaryStatus (text, backgroundColor, waitingCycles) { + function setStatus (text, backgroundColor, waitingCycles, newStatus) { labelToPrint = text backgroundColorToUse = backgroundColor - temporaryStatus = waitingCycles + temporaryStatus = newStatus + temporaryStatusCounter = newStatus // This will often put this into negatives numbers, which will disable the counting back and automatic reseting. + if (waitingCycles !== undefined) { // This will override the often negative value with a positive one that will tend to zero onto the default state. + temporaryStatusCounter = waitingCycles + } } function drawBackground () { @@ -274,4 +377,3 @@ function newCircularMenuItem () { } } } - diff --git a/FloatingSpace/CircularProgressBar.js b/FloatingSpace/CircularProgressBar.js index 2bb3da856..a28c0ea68 100644 --- a/FloatingSpace/CircularProgressBar.js +++ b/FloatingSpace/CircularProgressBar.js @@ -23,11 +23,14 @@ function newCircularProgressBar () { let opacityCounters = [] + let eventSubscriptionHeartbeat + return thisObject function finalize () { - thisObject.container = undefined + systemEventHandler.stopListening('Jason-Heartbeat-Period', eventSubscriptionHeartbeat) + thisObject.container = undefined thisObject.payload = undefined thisObject.fitFunction = undefined } @@ -40,8 +43,11 @@ function newCircularProgressBar () { } let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - systemEventHandler.createEventHandler(key) - systemEventHandler.listenToEvent(key, 'Heartbeat', undefined, key, undefined, onHeartBeat) + systemEventHandler.listenToEvent(key, 'Heartbeat', undefined, key, onResponse, onHeartBeat) + + function onResponse (message) { + eventSubscriptionIdHeartbeat = message.eventSubscriptionId + } } function onHeartBeat (message) { @@ -69,6 +75,10 @@ function newCircularProgressBar () { } function drawBackground (pFloatingObject) { + + } + + function drawForeground (pFloatingObject) { const VISIBLE_RADIUS = thisObject.container.frame.radius * 2 let visiblePosition = { @@ -100,8 +110,4 @@ function newCircularProgressBar () { browserCanvasContext.stroke() } } - - function drawForeground (pFloatingObject) { - - } } diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 1bbd10c08..fb3761428 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -18,11 +18,11 @@ function newStrategyPart () { partTitle: undefined, circularProgressBar: undefined, isExecuting: undefined, - isRunning: undefined, + isDefault: undefined, + setAsDefault: setAsDefault, run: run, - play: play, stop: stop, - setRunningStatus: setRunningStatus, + setDefaultStatus: setDefaultStatus, setNotRunningStatus: setNotRunningStatus, getReadyToAttach: getReadyToAttach, showAvailabilityToAttach: showAvailabilityToAttach, @@ -170,7 +170,7 @@ function newStrategyPart () { thisObject.codeEditor.physics() } - if (thisObject.payload.chainParent === undefined) { + if (thisObject.payload.chainParent === undefined || thisObject.payload.chainParent.payload === undefined) { thisObject.payload.targetPosition.x = thisObject.payload.position.x, thisObject.payload.targetPosition.y = thisObject.payload.position.y } else { @@ -203,151 +203,151 @@ function newStrategyPart () { let compatibleSubType switch (thisObject.payload.node.type) { case 'Trading System': - compatibleType = '->' + 'Definition' + compatibleType = '->' + 'Definition' + '->' compatibleSubType = undefined break case 'Personal Data': - compatibleType = '->' + 'Definition' + compatibleType = '->' + 'Definition' + '->' compatibleSubType = undefined break case 'Exchange Account': - compatibleType = '->' + 'Personal Data' + compatibleType = '->' + 'Personal Data' + '->' compatibleSubType = undefined break case 'Exchange Account Asset': - compatibleType = '->' + 'Exchange Account' + compatibleType = '->' + 'Exchange Account' + '->' compatibleSubType = undefined break case 'Exchange Account Key': - compatibleType = '->' + 'Exchange Account' + compatibleType = '->' + 'Exchange Account' + '->' compatibleSubType = undefined break case 'Parameters': - compatibleType = '->' + 'Trading System' + compatibleType = '->' + 'Trading System' + '->' compatibleSubType = undefined break case 'Base Asset': - compatibleType = '->' + 'Parameters' + compatibleType = '->' + 'Parameters' + '->' compatibleSubType = undefined break case 'Time Range': - compatibleType = '->' + 'Parameters' + compatibleType = '->' + 'Parameters' + '->' compatibleSubType = undefined break case 'Slippage': - compatibleType = '->' + 'Parameters' + compatibleType = '->' + 'Parameters' + '->' compatibleSubType = undefined break case 'Fee Structure': - compatibleType = '->' + 'Parameters' + compatibleType = '->' + 'Parameters' + '->' compatibleSubType = undefined break case 'Task Manager': - compatibleType = '->' + 'Definition' + compatibleType = '->' + 'Definition' + '->' compatibleSubType = undefined break case 'Task': - compatibleType = '->' + 'Task Manager' + compatibleType = '->' + 'Task Manager' + '->' compatibleSubType = undefined break case 'Sensor': - compatibleType = '->' + 'Task' + compatibleType = '->' + 'Task' + '->' compatibleSubType = undefined break case 'Indicator': - compatibleType = '->' + 'Task' + compatibleType = '->' + 'Task' + '->' compatibleSubType = undefined break case 'Trading Engine': - compatibleType = '->' + 'Task' + compatibleType = '->' + 'Task' + '->' compatibleSubType = undefined break case 'Process': - compatibleType = '->' + 'Sensor' + '->' + 'Indicator' + '->' + 'Trading Engine' + compatibleType = '->' + 'Sensor' + '->' + 'Indicator' + '->' + 'Trading Engine' + '->' compatibleSubType = undefined break case 'Strategy': - compatibleType = '->' + 'Trading System' + compatibleType = '->' + 'Trading System' + '->' compatibleSubType = undefined break case 'Trigger Stage': - compatibleType = '->' + 'Strategy' + compatibleType = '->' + 'Strategy' + '->' compatibleSubType = undefined break case 'Open Stage': - compatibleType = '->' + 'Strategy' + compatibleType = '->' + 'Strategy' + '->' compatibleSubType = undefined break case 'Manage Stage': - compatibleType = '->' + 'Strategy' + compatibleType = '->' + 'Strategy' + '->' compatibleSubType = undefined break case 'Close Stage': - compatibleType = '->' + 'Strategy' + compatibleType = '->' + 'Strategy' + '->' compatibleSubType = undefined break case 'Position Size': - compatibleType = '->' + 'Initial Definition' + compatibleType = '->' + 'Initial Definition' + '->' compatibleSubType = undefined break case 'Position Rate': - compatibleType = '->' + 'Initial Definition' + compatibleType = '->' + 'Initial Definition' + '->' compatibleSubType = undefined break case 'Take Position Event': - compatibleType = '->' + 'Trigger Stage' + compatibleType = '->' + 'Trigger Stage' + '->' compatibleSubType = undefined break case 'Trigger Off Event': - compatibleType = '->' + 'Trigger Stage' + compatibleType = '->' + 'Trigger Stage' + '->' compatibleSubType = undefined break case 'Trigger On Event': - compatibleType = '->' + 'Trigger Stage' + compatibleType = '->' + 'Trigger Stage' + '->' compatibleSubType = undefined break case 'Initial Definition': - compatibleType = '->' + 'Open Stage' + compatibleType = '->' + 'Open Stage' + '->' compatibleSubType = undefined break case 'Open Execution': - compatibleType = '->' + 'Open Stage' + compatibleType = '->' + 'Open Stage' + '->' compatibleSubType = undefined break case 'Close Execution': - compatibleType = '->' + 'Close Stage' + compatibleType = '->' + 'Close Stage' + '->' compatibleSubType = undefined break case 'Stop': - compatibleType = '->' + 'Manage Stage' + '->' + 'Initial Definition' + compatibleType = '->' + 'Manage Stage' + '->' + 'Initial Definition' + '->' compatibleSubType = undefined break case 'Take Profit': - compatibleType = '->' + 'Manage Stage' + '->' + 'Initial Definition' + compatibleType = '->' + 'Manage Stage' + '->' + 'Initial Definition' + '->' compatibleSubType = undefined break case 'Phase': - compatibleType = '->' + 'Stop' + '->' + 'Take Profit' + '->' + 'Phase' + compatibleType = '->' + 'Stop' + '->' + 'Take Profit' + '->' + 'Phase' + '->' compatibleSubType = undefined break case 'Formula': - compatibleType = '->' + 'Position Size' + '->' + 'Position Rate' + '->' + 'Phase' + compatibleType = '->' + 'Position Size' + '->' + 'Position Rate' + '->' + 'Phase' + '->' compatibleSubType = undefined break case 'Next Phase Event': - compatibleType = '->' + 'Phase' + compatibleType = '->' + 'Phase' + '->' compatibleSubType = undefined break case 'Situation': - compatibleType = '->' + 'Take Position Event' + '->' + 'Trigger On Event' + '->' + 'Trigger Off Event' + '->' + 'Next Phase Event' + compatibleType = '->' + 'Take Position Event' + '->' + 'Trigger On Event' + '->' + 'Trigger Off Event' + '->' + 'Next Phase Event' + '->' compatibleSubType = undefined break case 'Condition': - compatibleType = '->' + 'Situation' + compatibleType = '->' + 'Situation' + '->' compatibleSubType = undefined break case 'Code': - compatibleType = '->' + 'Condition' + compatibleType = '->' + 'Condition' + '->' compatibleSubType = undefined break default: @@ -362,9 +362,8 @@ function newStrategyPart () { let distance = nearby[0] let floatingObject = nearby[1] let nearbyNode = floatingObject.payload.node - if (compatibleType.indexOf('->' + nearbyNode.type) >= 0) { + if (compatibleType.indexOf('->' + nearbyNode.type + '->') >= 0) { /* Discard objects with busy coonection ports */ - if (thisObject.payload.node.type === 'Task Manager' && nearbyNode.taskManager !== undefined) { continue } if (thisObject.payload.node.type === 'Task' && nearbyNode.task !== undefined) { continue } if (thisObject.payload.node.type === 'Sensor' && nearbyNode.bot !== undefined) { continue } if (thisObject.payload.node.type === 'Indicator' && nearbyNode.bot !== undefined) { continue } @@ -531,7 +530,8 @@ function newStrategyPart () { } } - function play () { + function run (callBackFunction) { + /* We setup the circular progress bar. */ if (thisObject.circularProgressBar !== undefined) { thisObject.circularProgressBar.finalize() } @@ -540,30 +540,49 @@ function newStrategyPart () { thisObject.circularProgressBar.initialize(thisObject.payload) thisObject.circularProgressBar.fitFunction = thisObject.fitFunction thisObject.circularProgressBar.container = thisObject.container - } - function stop () { - setTimeout(removecircularProgressBar, 90000) - function removecircularProgressBar () { - thisObject.circularProgressBar.finalize() - thisObject.circularProgressBar = undefined + /* We will wait to the event that the task was terminated in order to call back the menu item */ + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + systemEventHandler.listenToEvent(key, 'Running', undefined, key, undefined, onTaskTerminated) + + function onTaskTerminated () { + if (callBackFunction !== undefined) { + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) + } } } - function run () { - setRunningStatus() + function stop (callBackFunction) { + /* We will wait to the event that the task was terminated in order to call back the menu item */ + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + let eventSubscriptionId = systemEventHandler.listenToEvent(key, 'Stopped', undefined, key, undefined, onTaskTerminated) + + function onTaskTerminated () { + if (callBackFunction !== undefined) { + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) + } + + if (thisObject.circularProgressBar !== undefined) { + thisObject.circularProgressBar.finalize() + thisObject.circularProgressBar = undefined + } + } + } + + function setAsDefault () { + setDefaultStatus() canvas.cockpitSpace.restartSimulation.restart() } - function setRunningStatus () { + function setDefaultStatus () { canvas.strategySpace.workspace.definition = thisObject.payload.node - thisObject.isRunning = true + thisObject.isDefault = true runningCounter = 30 } function setNotRunningStatus () { canvas.strategySpace.workspace.definition = undefined - thisObject.isRunning = false + thisObject.isDefault = false } function iconPhysics () { @@ -940,7 +959,7 @@ function newStrategyPart () { browserCanvasContext.fill() - if (thisObject.isRunning === true) { + if (thisObject.isDefault === true) { VISIBLE_RADIUS = thisObject.container.frame.radius * 2 let OPACITY = runningCounter / 30 diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 04651ffc9..87db6c451 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -68,8 +68,8 @@ function newStrategyPartConstructor () { strategyPart.container.connectToParent(floatingObject.container, false, false, true, true, false, false, true, true, true, true, true) if (payload.node.savedPayload !== undefined) { - if (payload.node.savedPayload.uiObject.isRunning === true) { - strategyPart.setRunningStatus() + if (payload.node.savedPayload.uiObject.isDefault === true) { + strategyPart.setDefaultStatus() canvas.strategySpace.workspace.definition = payload.node } } @@ -91,7 +91,7 @@ function newStrategyPartConstructor () { actionStatus: floatingObject.getPinStatus, currentStatus: false, label: undefined, - visible: false, + visible: true, iconPathOn: 'menu-fix-pinned', iconPathOff: 'menu-fix-unpinned', rawRadius: 8, @@ -107,7 +107,7 @@ function newStrategyPartConstructor () { actionStatus: floatingObject.getTensionStatus, currentStatus: true, label: undefined, - visible: false, + visible: true, iconPathOn: 'menu-tensor-fixed-angles', iconPathOff: 'menu-tensor-free-angles', rawRadius: 8, @@ -123,7 +123,7 @@ function newStrategyPartConstructor () { actionStatus: floatingObject.getFreezeStatus, currentStatus: true, label: undefined, - visible: false, + visible: true, iconPathOn: 'menu-mobility-freeze', iconPathOff: 'menu-mobility-unfreeze', rawRadius: 8, @@ -139,7 +139,7 @@ function newStrategyPartConstructor () { actionStatus: floatingObject.getCollapeseStatus, currentStatus: false, label: undefined, - visible: false, + visible: true, iconPathOn: 'menu-tree-plus', iconPathOff: 'menu-tree-minus', rawRadius: 8, @@ -153,7 +153,7 @@ function newStrategyPartConstructor () { action: 'Backup', actionFunction: floatingObject.payload.onMenuItemClick, label: undefined, - visible: false, + visible: true, iconPathOn: 'menu-backup', iconPathOff: 'menu-backup', rawRadius: 8, @@ -177,7 +177,7 @@ function newStrategyPartConstructor () { actionStatus: floatingObject.getPinStatus, currentStatus: true, label: undefined, - visible: false, + visible: true, iconPathOn: 'menu-fix-unpinned', iconPathOff: 'menu-fix-pinned', rawRadius: 8, @@ -189,7 +189,7 @@ function newStrategyPartConstructor () { action: 'Backup Workspace', actionFunction: payload.onMenuItemClick, label: undefined, - visible: false, + visible: true, iconPathOn: 'menu-backup', iconPathOff: 'menu-backup', rawRadius: 8, @@ -201,7 +201,7 @@ function newStrategyPartConstructor () { action: 'Share Workspace', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -217,10 +217,10 @@ function newStrategyPartConstructor () { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Run Definition', - actionFunction: payload.uiObject.run, - label: 'Run', - visible: false, + action: 'Set as Default', + actionFunction: payload.uiObject.setAsDefault, + label: 'Set as Default', + visible: true, iconPathOn: 'paper-plane', iconPathOff: 'paper-plane', rawRadius: 8, @@ -237,7 +237,7 @@ function newStrategyPartConstructor () { workingLabel: 'Saving...', workDoneLabel: 'Saved', workFailedLabel: 'Not Saved', - visible: false, + visible: true, iconPathOn: 'menu-backup', iconPathOff: 'menu-backup', rawRadius: 8, @@ -251,7 +251,7 @@ function newStrategyPartConstructor () { action: 'Add Trading System', actionFunction: payload.onMenuItemClick, label: 'Add Trading System', - visible: false, + visible: true, relatedStrategyPart: 'Trading System', rawRadius: 8, targetRadius: 0, @@ -264,7 +264,7 @@ function newStrategyPartConstructor () { action: 'Add Personal Data', actionFunction: payload.onMenuItemClick, label: 'Add Personal Data', - visible: false, + visible: true, relatedStrategyPart: 'Personal Data', rawRadius: 8, targetRadius: 0, @@ -277,7 +277,7 @@ function newStrategyPartConstructor () { action: 'Add Task Manager', actionFunction: payload.onMenuItemClick, label: 'Add Task Manager', - visible: false, + visible: true, relatedStrategyPart: 'Task Manager', rawRadius: 8, targetRadius: 0, @@ -292,7 +292,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Definition', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -306,7 +306,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -324,7 +324,7 @@ function newStrategyPartConstructor () { action: 'Run All Tasks', actionFunction: payload.onMenuItemClick, label: 'Run All Tasks', - visible: false, + visible: true, iconPathOn: 'paper-plane', iconPathOff: 'paper-plane', rawRadius: 8, @@ -338,7 +338,7 @@ function newStrategyPartConstructor () { action: 'Stop All Tasks', actionFunction: payload.onMenuItemClick, label: 'Stop All Tasks', - visible: false, + visible: true, iconPathOn: 'stop', iconPathOff: 'stop', rawRadius: 8, @@ -352,7 +352,7 @@ function newStrategyPartConstructor () { action: 'Add Task', actionFunction: payload.onMenuItemClick, label: 'Add Task', - visible: false, + visible: true, relatedStrategyPart: 'Task Manager', rawRadius: 8, targetRadius: 0, @@ -367,7 +367,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Task Manager', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -381,7 +381,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -399,27 +399,22 @@ function newStrategyPartConstructor () { action: 'Run Task', actionFunction: payload.onMenuItemClick, label: 'Run', - visible: false, + workingLabel: 'Stop', + workDoneLabel: 'Task Running', + workFailedLabel: 'Task Cannot be Run', + secondaryAction: 'Stop Task', + secondaryLabel: 'Stop', + secondaryWorkingLabel: 'Stopping...', + secondaryWorkDoneLabel: 'Task Stopped', + secondaryWorkFailedLabel: 'Task Cannot be Stopped', + secondaryIcon: 'stop', + visible: true, iconPathOn: 'paper-plane', iconPathOff: 'paper-plane', rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -75 - } - ) - menuItemsInitialValues.push( - { - action: 'Stop Task', - actionFunction: payload.onMenuItemClick, - label: 'Stop', - visible: false, - iconPathOn: 'stop', - iconPathOff: 'stop', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -40 + angle: -65 } ) menuItemsInitialValues.push( @@ -427,12 +422,12 @@ function newStrategyPartConstructor () { action: 'Add Sensor', actionFunction: payload.onMenuItemClick, label: 'Add Sensor', - visible: false, + visible: true, relatedStrategyPart: 'Sensor', rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -20 + angle: -30 } ) menuItemsInitialValues.push( @@ -440,12 +435,12 @@ function newStrategyPartConstructor () { action: 'Add Indicator', actionFunction: payload.onMenuItemClick, label: 'Add Indicator', - visible: false, + visible: true, relatedStrategyPart: 'Indicator', rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 0 + angle: -10 } ) menuItemsInitialValues.push( @@ -453,12 +448,12 @@ function newStrategyPartConstructor () { action: 'Add Trading Engine', actionFunction: payload.onMenuItemClick, label: 'Add Trading Engine', - visible: false, + visible: true, relatedStrategyPart: 'Trading Engine', rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 20 + angle: 10 } ) menuItemsInitialValues.push( @@ -468,13 +463,13 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Process', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: +40 + angle: +30 } ) menuItemsInitialValues.push( @@ -482,13 +477,13 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 75 + angle: 65 } ) break @@ -500,7 +495,7 @@ function newStrategyPartConstructor () { action: 'Add Process', actionFunction: payload.onMenuItemClick, label: 'Add Process', - visible: false, + visible: true, relatedStrategyPart: 'Process', rawRadius: 8, targetRadius: 0, @@ -515,7 +510,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Sensor', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -529,7 +524,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -547,7 +542,7 @@ function newStrategyPartConstructor () { action: 'Add Process', actionFunction: payload.onMenuItemClick, label: 'Add Process', - visible: false, + visible: true, relatedStrategyPart: 'Process', rawRadius: 8, targetRadius: 0, @@ -562,7 +557,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Indicator', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -576,7 +571,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -594,7 +589,7 @@ function newStrategyPartConstructor () { action: 'Add Process', actionFunction: payload.onMenuItemClick, label: 'Add Process', - visible: false, + visible: true, relatedStrategyPart: 'Process', rawRadius: 8, targetRadius: 0, @@ -609,7 +604,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Trading Engine', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -623,7 +618,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -646,7 +641,7 @@ function newStrategyPartConstructor () { action: 'Edit Process', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Process', - visible: false, + visible: true, iconPathOn: 'html', iconPathOff: 'html', rawRadius: 8, @@ -663,7 +658,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Process', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -677,7 +672,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -695,7 +690,7 @@ function newStrategyPartConstructor () { action: 'Add Exchange Account', actionFunction: payload.onMenuItemClick, label: 'Add Exchange Account', - visible: false, + visible: true, relatedStrategyPart: 'Exchange Account', rawRadius: 8, targetRadius: 0, @@ -710,7 +705,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Personal Data', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -728,7 +723,7 @@ function newStrategyPartConstructor () { action: 'Add Exchange Account Asset', actionFunction: payload.onMenuItemClick, label: 'Add Asset', - visible: false, + visible: true, relatedStrategyPart: 'Exchange Account Asset', rawRadius: 8, targetRadius: 0, @@ -741,7 +736,7 @@ function newStrategyPartConstructor () { action: 'Add Exchange Account Key', actionFunction: payload.onMenuItemClick, label: 'Add Key', - visible: false, + visible: true, relatedStrategyPart: 'Exchange Account Key', rawRadius: 8, targetRadius: 0, @@ -756,7 +751,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Account', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -776,7 +771,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Asset', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -799,7 +794,7 @@ function newStrategyPartConstructor () { action: 'Edit Key Value', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Key Value', - visible: false, + visible: true, iconPathOn: 'html', iconPathOff: 'html', rawRadius: 8, @@ -816,7 +811,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Key', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -834,7 +829,7 @@ function newStrategyPartConstructor () { action: 'Add Strategy', actionFunction: payload.onMenuItemClick, label: 'Add Strategy', - visible: false, + visible: true, relatedStrategyPart: 'Strategy', rawRadius: 8, targetRadius: 0, @@ -847,7 +842,7 @@ function newStrategyPartConstructor () { action: 'Add Parameters', actionFunction: payload.onMenuItemClick, label: 'Add Parameters', - visible: false, + visible: true, relatedStrategyPart: 'Parameters', rawRadius: 8, targetRadius: 0, @@ -862,7 +857,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Trading System', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -876,7 +871,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -894,7 +889,7 @@ function newStrategyPartConstructor () { action: 'Add Missing Parameters', actionFunction: payload.onMenuItemClick, label: 'Add Missing Params', - visible: false, + visible: true, relatedStrategyPart: 'Parameters', rawRadius: 8, targetRadius: 0, @@ -909,7 +904,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Parameters', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -923,7 +918,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -946,7 +941,7 @@ function newStrategyPartConstructor () { action: 'Edit Base Asset', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Base Asset', - visible: false, + visible: true, iconPathOn: 'settings', iconPathOff: 'settings', rawRadius: 8, @@ -962,7 +957,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Base Asset', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -976,7 +971,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -999,7 +994,7 @@ function newStrategyPartConstructor () { action: 'Edit Time Range', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Time Range', - visible: false, + visible: true, iconPathOn: 'settings', iconPathOff: 'settings', rawRadius: 8, @@ -1015,7 +1010,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Time Range', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1029,7 +1024,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1052,7 +1047,7 @@ function newStrategyPartConstructor () { action: 'Edit Slippage', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Slippage', - visible: false, + visible: true, iconPathOn: 'settings', iconPathOff: 'settings', rawRadius: 8, @@ -1068,7 +1063,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Slippage', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1082,7 +1077,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1105,7 +1100,7 @@ function newStrategyPartConstructor () { action: 'Edit Fee Structure', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Fee Structure', - visible: false, + visible: true, iconPathOn: 'settings', iconPathOff: 'settings', rawRadius: 8, @@ -1121,7 +1116,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Fee Structure', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1135,7 +1130,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1153,7 +1148,7 @@ function newStrategyPartConstructor () { action: 'Add Missing Stages', actionFunction: payload.onMenuItemClick, label: 'Add Missing Stages', - visible: false, + visible: true, relatedStrategyPart: 'Strategy', rawRadius: 8, targetRadius: 0, @@ -1168,7 +1163,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Strategy', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1182,7 +1177,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1200,7 +1195,7 @@ function newStrategyPartConstructor () { action: 'Add Missing Events', actionFunction: payload.onMenuItemClick, label: 'Add Missing Events', - visible: false, + visible: true, relatedStrategyPart: 'Trigger Stage', rawRadius: 8, targetRadius: 0, @@ -1215,7 +1210,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Stage', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1229,7 +1224,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1247,7 +1242,7 @@ function newStrategyPartConstructor () { action: 'Add Initial Definition', actionFunction: payload.onMenuItemClick, label: 'Add Initial Definition', - visible: false, + visible: true, relatedStrategyPart: 'Initial Definition', rawRadius: 8, targetRadius: 0, @@ -1260,7 +1255,7 @@ function newStrategyPartConstructor () { action: 'Add Open Execution', actionFunction: payload.onMenuItemClick, label: 'Add Open Execution', - visible: false, + visible: true, relatedStrategyPart: 'Open Execution', rawRadius: 8, targetRadius: 0, @@ -1275,7 +1270,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Stage', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1289,7 +1284,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1307,7 +1302,7 @@ function newStrategyPartConstructor () { action: 'Add Missing Items', actionFunction: payload.onMenuItemClick, label: 'Add Missing Items', - visible: false, + visible: true, relatedStrategyPart: 'Manage Stage', rawRadius: 8, targetRadius: 0, @@ -1322,7 +1317,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Stage', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1336,7 +1331,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1354,7 +1349,7 @@ function newStrategyPartConstructor () { action: 'Add Close Execution', actionFunction: payload.onMenuItemClick, label: 'Add Close Execution', - visible: false, + visible: true, relatedStrategyPart: 'Close Execution', rawRadius: 8, targetRadius: 0, @@ -1369,7 +1364,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Stage', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1383,7 +1378,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1401,7 +1396,7 @@ function newStrategyPartConstructor () { action: 'Add Formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', - visible: false, + visible: true, relatedStrategyPart: 'Formula', rawRadius: 8, targetRadius: 0, @@ -1416,7 +1411,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Position Size', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1430,7 +1425,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1448,7 +1443,7 @@ function newStrategyPartConstructor () { action: 'Add Formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', - visible: false, + visible: true, relatedStrategyPart: 'Formula', rawRadius: 8, targetRadius: 0, @@ -1463,7 +1458,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete Position Rate', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1477,7 +1472,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1495,7 +1490,7 @@ function newStrategyPartConstructor () { action: 'Add Situation', actionFunction: payload.onMenuItemClick, label: 'Add Situation', - visible: false, + visible: true, relatedStrategyPart: 'Situation', rawRadius: 8, targetRadius: 0, @@ -1510,7 +1505,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Event', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1524,7 +1519,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1542,7 +1537,7 @@ function newStrategyPartConstructor () { action: 'Add Situation', actionFunction: payload.onMenuItemClick, label: 'Add Situation', - visible: false, + visible: true, relatedStrategyPart: 'Situation', rawRadius: 8, targetRadius: 0, @@ -1557,7 +1552,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Event', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1571,7 +1566,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1589,7 +1584,7 @@ function newStrategyPartConstructor () { action: 'Add Situation', actionFunction: payload.onMenuItemClick, label: 'Add Situation', - visible: false, + visible: true, relatedStrategyPart: 'Situation', rawRadius: 8, targetRadius: 0, @@ -1604,7 +1599,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Event', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1618,7 +1613,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1636,7 +1631,7 @@ function newStrategyPartConstructor () { action: 'Add Missing Items', actionFunction: payload.onMenuItemClick, label: 'Add Missing Items', - visible: false, + visible: true, relatedStrategyPart: 'Initial Definition', rawRadius: 8, targetRadius: 0, @@ -1651,7 +1646,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Definition', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1665,7 +1660,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1685,7 +1680,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1699,7 +1694,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1719,7 +1714,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1733,7 +1728,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1751,7 +1746,7 @@ function newStrategyPartConstructor () { action: 'Add Phase', actionFunction: payload.onMenuItemClick, label: 'Add Phase', - visible: false, + visible: true, relatedStrategyPart: 'Phase', rawRadius: 8, targetRadius: 0, @@ -1766,7 +1761,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Item', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1780,7 +1775,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1798,7 +1793,7 @@ function newStrategyPartConstructor () { action: 'Add Phase', actionFunction: payload.onMenuItemClick, label: 'Add Phase', - visible: false, + visible: true, relatedStrategyPart: 'Phase', rawRadius: 8, targetRadius: 0, @@ -1813,7 +1808,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Item', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1827,7 +1822,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1845,7 +1840,7 @@ function newStrategyPartConstructor () { action: 'Add Formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', - visible: false, + visible: true, relatedStrategyPart: 'Formula', rawRadius: 8, targetRadius: 0, @@ -1858,7 +1853,7 @@ function newStrategyPartConstructor () { action: 'Add Next Phase Event', actionFunction: payload.onMenuItemClick, label: 'Add Next Phase Event', - visible: false, + visible: true, relatedStrategyPart: 'Next Phase Event', rawRadius: 8, targetRadius: 0, @@ -1873,7 +1868,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Phase', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1887,7 +1882,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1910,7 +1905,7 @@ function newStrategyPartConstructor () { action: 'Edit Formula', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Formula', - visible: false, + visible: true, iconPathOn: 'html', iconPathOff: 'html', rawRadius: 8, @@ -1927,7 +1922,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Formula', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1941,7 +1936,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -1959,7 +1954,7 @@ function newStrategyPartConstructor () { action: 'Add Situation', actionFunction: payload.onMenuItemClick, label: 'Add Situation', - visible: false, + visible: true, relatedStrategyPart: 'Situation', rawRadius: 8, targetRadius: 0, @@ -1974,7 +1969,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Event', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -1988,7 +1983,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -2006,7 +2001,7 @@ function newStrategyPartConstructor () { action: 'Add Condition', actionFunction: payload.onMenuItemClick, label: 'Add Condition', - visible: false, + visible: true, relatedStrategyPart: 'Condition', rawRadius: 8, targetRadius: 0, @@ -2021,7 +2016,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Situation', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -2035,7 +2030,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -2053,7 +2048,7 @@ function newStrategyPartConstructor () { action: 'Add Code', actionFunction: payload.onMenuItemClick, label: 'Add Code', - visible: false, + visible: true, relatedStrategyPart: 'Code', rawRadius: 8, targetRadius: 0, @@ -2068,7 +2063,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Condition', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -2082,7 +2077,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, @@ -2105,7 +2100,7 @@ function newStrategyPartConstructor () { action: 'Edit Code', actionFunction: strategyPart.codeEditor.activate, label: 'Edit Code', - visible: false, + visible: true, iconPathOn: 'html', iconPathOff: 'html', rawRadius: 8, @@ -2122,7 +2117,7 @@ function newStrategyPartConstructor () { confirmationLabel: 'Confirm to Delete', actionFunction: payload.onMenuItemClick, label: 'Delete This Code', - visible: false, + visible: true, iconPathOn: 'delete', iconPathOff: 'delete', rawRadius: 8, @@ -2136,7 +2131,7 @@ function newStrategyPartConstructor () { action: 'Share', actionFunction: payload.onMenuItemClick, label: 'Share', - visible: false, + visible: true, iconPathOn: 'menu-share', iconPathOff: 'menu-share', rawRadius: 8, diff --git a/SplashScreen.js b/SplashScreen.js index a4c43f411..14293b854 100644 --- a/SplashScreen.js +++ b/SplashScreen.js @@ -125,7 +125,7 @@ function newSplashScreen () { fontSize = 15 - title = 'Trading Bots Competitions Platform' + title = 'Trading Automation System' titlePoint = { x: thisObject.container.frame.width / 2 - title.length / 2 * fontSize * FONT_ASPECT_RATIO - 20, diff --git a/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js b/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js index 86e4d13f1..01e71cdba 100644 --- a/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js +++ b/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js @@ -50,12 +50,24 @@ function newAttachDetach () { return } case 'Task Manager': { - node.payload.parentNode.taskManager = undefined + let payload = node.payload + for (let i = 0; i < payload.parentNode.taskManagers.length; i++) { + let taskManager = payload.parentNode.taskManagers[i] + if (taskManager.id === node.id) { + payload.parentNode.taskManagers.splice(i, 1) + } + } completeDetachment(node, rootNodes) return } case 'Task': { - node.payload.parentNode.task = undefined + let payload = node.payload + for (let i = 0; i < payload.parentNode.tasks.length; i++) { + let task = payload.parentNode.tasks[i] + if (task.id === node.id) { + payload.parentNode.tasks.splice(i, 1) + } + } completeDetachment(node, rootNodes) return } @@ -251,7 +263,7 @@ function newAttachDetach () { case 'Task Manager': { node.payload.parentNode = attachToNode node.payload.chainParent = attachToNode - node.payload.parentNode.taskManager = node + node.payload.parentNode.taskManagers.push(node) completeAttachment(node, rootNodes) } break diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js index df0a8b531..5c6c2b311 100644 --- a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js +++ b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js @@ -145,10 +145,13 @@ function newNodeChildren () { response.childIndex = response.childrenCount } } - if (parentNode.taskManager !== undefined) { - response.childrenCount++ - if (parentNode.taskManager.id === childNode.id) { - response.childIndex = response.childrenCount + if (parentNode.taskManagers !== undefined) { + for (let i = 0; i < parentNode.taskManagers.length; i++) { + let child = parentNode.taskManagers[i] + response.childrenCount++ + if (child.id === childNode.id) { + response.childIndex = response.childrenCount + } } } return response diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js b/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js index 517f705bb..bd0e1cc7d 100644 --- a/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js +++ b/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js @@ -44,149 +44,151 @@ function newNodeDeleter () { } function deleteWorkspace (node, rootNodes) { - while (node.rootNodes.length > 0) { - let rootNode = node.rootNodes[0] - switch (rootNode.type) { + if (node.rootNodes !== undefined) { + while (node.rootNodes.length > 0) { + let rootNode = node.rootNodes[0] + switch (rootNode.type) { - case 'Definition': { - deleteDefinition(rootNode, rootNodes, true) - break - } - case 'Task Manager': { - deleteTaskManager(rootNode, rootNodes) - break - } - case 'Task': { - deleteTask(rootNode, rootNodes) - break - } - case 'Sensor': { - deleteBot(rootNode, rootNodes) - break - } - case 'Indicator': { - deleteBot(rootNode, rootNodes) - break - } - case 'Trading Engine': { - deleteBot(rootNode, rootNodes) - break - } - case 'Process': { - deleteProcess(rootNode, rootNodes) - break - } - case 'Personal Data': { - deletePersonalData(rootNode, rootNodes) - break - } - case 'Exchange Account': { - deleteExchangeAccount(rootNode, rootNodes) - break - } - case 'Exchange Account Asset': { - deleteExchangeAccountAsset(rootNode, rootNodes) - break - } - case 'Exchange Account Key': { - deleteExchangeAccountKey(rootNode, rootNodes) - break - } - case 'Trading System': { - deleteTradingSystem(rootNode, rootNodes) - break - } - case 'Parameters': { - deleteParameters(rootNode, rootNodes) - break - } - case 'Base Asset': { - deleteBaseAsset(rootNode, rootNodes) - break - } - case 'Time Range': { - deleteTimeRange(rootNode, rootNodes) - break - } - case 'Slippage': { - deleteSlippage(rootNode, rootNodes) - break - } - case 'Fee Structure': { - deleteFeeStructure(rootNode, rootNodes) - break - } - case 'Strategy': { - deleteStrategy(rootNode, rootNodes) - break - } - case 'Trigger Stage': { - deleteTriggerStage(rootNode, rootNodes) - break - } - case 'Open Stage': { - deleteOpenStage(rootNode, rootNodes) - break - } - case 'Manage Stage': { - deleteManageStage(rootNode, rootNodes) - break - } - case 'Close Stage': { - deleteCloseStage(rootNode, rootNodes) - break - } - case 'Position Size': { - deletePositionSize(rootNode, rootNodes) - break - } - case 'Position Rate': { - deletePositionRate(rootNode, rootNodes) - break - } - case 'Initial Definition': { - deleteInitialDefinition(rootNode, rootNodes) - break - } - case 'Open Execution': { - deleteOpenExecution(rootNode, rootNodes) - break - } - case 'Close Execution': { - deleteCloseExecution(rootNode, rootNodes) - break - } - case 'Event': { - deleteEvent(rootNode, rootNodes) - break - } - case 'Managed Item': { - deleteManagedItem(rootNode, rootNodes) - break - } - case 'Phase': { - deletePhase(rootNode, rootNodes) - break - } - case 'Formula': { - deleteFormula(rootNode, rootNodes) - break - } - case 'Situation': { - deleteSituation(rootNode, rootNodes) - break - } - case 'Condition': { - deleteCondition(rootNode, rootNodes) - break - } - case 'Code': { - deleteCode(rootNode, rootNodes) - break - } + case 'Definition': { + deleteDefinition(rootNode, rootNodes, true) + break + } + case 'Task Manager': { + deleteTaskManager(rootNode, rootNodes) + break + } + case 'Task': { + deleteTask(rootNode, rootNodes) + break + } + case 'Sensor': { + deleteBot(rootNode, rootNodes) + break + } + case 'Indicator': { + deleteBot(rootNode, rootNodes) + break + } + case 'Trading Engine': { + deleteBot(rootNode, rootNodes) + break + } + case 'Process': { + deleteProcess(rootNode, rootNodes) + break + } + case 'Personal Data': { + deletePersonalData(rootNode, rootNodes) + break + } + case 'Exchange Account': { + deleteExchangeAccount(rootNode, rootNodes) + break + } + case 'Exchange Account Asset': { + deleteExchangeAccountAsset(rootNode, rootNodes) + break + } + case 'Exchange Account Key': { + deleteExchangeAccountKey(rootNode, rootNodes) + break + } + case 'Trading System': { + deleteTradingSystem(rootNode, rootNodes) + break + } + case 'Parameters': { + deleteParameters(rootNode, rootNodes) + break + } + case 'Base Asset': { + deleteBaseAsset(rootNode, rootNodes) + break + } + case 'Time Range': { + deleteTimeRange(rootNode, rootNodes) + break + } + case 'Slippage': { + deleteSlippage(rootNode, rootNodes) + break + } + case 'Fee Structure': { + deleteFeeStructure(rootNode, rootNodes) + break + } + case 'Strategy': { + deleteStrategy(rootNode, rootNodes) + break + } + case 'Trigger Stage': { + deleteTriggerStage(rootNode, rootNodes) + break + } + case 'Open Stage': { + deleteOpenStage(rootNode, rootNodes) + break + } + case 'Manage Stage': { + deleteManageStage(rootNode, rootNodes) + break + } + case 'Close Stage': { + deleteCloseStage(rootNode, rootNodes) + break + } + case 'Position Size': { + deletePositionSize(rootNode, rootNodes) + break + } + case 'Position Rate': { + deletePositionRate(rootNode, rootNodes) + break + } + case 'Initial Definition': { + deleteInitialDefinition(rootNode, rootNodes) + break + } + case 'Open Execution': { + deleteOpenExecution(rootNode, rootNodes) + break + } + case 'Close Execution': { + deleteCloseExecution(rootNode, rootNodes) + break + } + case 'Event': { + deleteEvent(rootNode, rootNodes) + break + } + case 'Managed Item': { + deleteManagedItem(rootNode, rootNodes) + break + } + case 'Phase': { + deletePhase(rootNode, rootNodes) + break + } + case 'Formula': { + deleteFormula(rootNode, rootNodes) + break + } + case 'Situation': { + deleteSituation(rootNode, rootNodes) + break + } + case 'Condition': { + deleteCondition(rootNode, rootNodes) + break + } + case 'Code': { + deleteCode(rootNode, rootNodes) + break + } - default: { - console.log('WARNING this node type is not listed at NodeDeleter: ' + node.type) + default: { + console.log('WARNING this node type is not listed at NodeDeleter: ' + node.type) + } } } } @@ -211,7 +213,7 @@ function newNodeDeleter () { if (counter <= 1) { return } } - if (node.payload.uiObject.isRunning === true) { + if (node.payload.uiObject.isDefault === true) { node.payload.uiObject.setNotRunningStatus() } @@ -221,9 +223,12 @@ function newNodeDeleter () { if (node.personalData !== undefined) { deletePersonalData(node.personalData, rootNodes) } - if (node.taskManager !== undefined) { - deleteTaskManager(node.taskManager, rootNodes) + if (node.taskManagers !== undefined) { + while (node.taskManagers.length > 0) { + deleteTaskManager(node.taskManagers[0], rootNodes) + } } + completeDeletion(node, rootNodes) destroyPart(node) cleanNode(node) @@ -232,10 +237,17 @@ function newNodeDeleter () { function deleteTaskManager (node, rootNodes) { let payload = node.payload if (payload.parentNode !== undefined) { - payload.parentNode.taskManager = undefined + for (let j = 0; j < payload.parentNode.taskManagers.length; j++) { + let taskManager = payload.parentNode.taskManagers[j] + if (taskManager.id === node.id) { + payload.parentNode.taskManagers.splice(j, 1) + } + } } - while (node.tasks.length > 0) { - deleteTask(node.tasks[0], rootNodes) + if (node.tasks !== undefined) { + while (node.tasks.length > 0) { + deleteTask(node.tasks[0], rootNodes) + } } completeDeletion(node, rootNodes) destroyPart(node) @@ -265,9 +277,12 @@ function newNodeDeleter () { if (payload.parentNode !== undefined) { payload.parentNode.bot = undefined } - while (node.processes.length > 0) { - deleteProcess(node.processes[0], rootNodes) + if (node.processes !== undefined) { + while (node.processes.length > 0) { + deleteProcess(node.processes[0], rootNodes) + } } + completeDeletion(node, rootNodes) destroyPart(node) cleanNode(node) @@ -295,8 +310,10 @@ function newNodeDeleter () { payload.parentNode.personalData = undefined } - while (node.exchangeAccounts.length > 0) { - deleteExchangeAccount(node.exchangeAccounts[0], rootNodes) + if (node.exchangeAccounts !== undefined) { + while (node.exchangeAccounts.length > 0) { + deleteExchangeAccount(node.exchangeAccounts[0], rootNodes) + } } completeDeletion(node, rootNodes) @@ -314,12 +331,17 @@ function newNodeDeleter () { } } } - while (node.assets.length > 0) { - deleteExchangeAccountAsset(node.assets[0], rootNodes) + if (node.assets !== undefined) { + while (node.assets.length > 0) { + deleteExchangeAccountAsset(node.assets[0], rootNodes) + } } - while (node.keys.length > 0) { - deleteExchangeAccountKey(node.keys[0], rootNodes) + if (node.keys !== undefined) { + while (node.keys.length > 0) { + deleteExchangeAccountKey(node.keys[0], rootNodes) + } } + completeDeletion(node, rootNodes) destroyPart(node) cleanNode(node) @@ -364,8 +386,10 @@ function newNodeDeleter () { payload.parentNode.tradingSystem = undefined } - while (node.strategies.length > 0) { - deleteStrategy(node.strategies[0], rootNodes) + if (node.strategies !== undefined) { + while (node.strategies.length > 0) { + deleteStrategy(node.strategies[0], rootNodes) + } } if (node.parameters !== undefined) { @@ -640,9 +664,12 @@ function newNodeDeleter () { completeDeletion(node, rootNodes) } - while (node.situations.length > 0) { - deleteSituation(node.situations[0], rootNodes) + if (node.situations !== undefined) { + while (node.situations.length > 0) { + deleteSituation(node.situations[0], rootNodes) + } } + destroyPart(node) cleanNode(node) } @@ -664,9 +691,12 @@ function newNodeDeleter () { completeDeletion(node, rootNodes) } - while (node.phases.length > 0) { - deletePhase(node.phases[0]) + if (node.phases !== undefined) { + while (node.phases.length > 0) { + deletePhase(node.phases[0]) + } } + destroyPart(node) cleanNode(node) } @@ -718,10 +748,13 @@ function newNodeDeleter () { for (let j = 0; j < payload.parentNode.situations.length; j++) { let situation = payload.parentNode.situations[j] if (situation.id === node.id) { - while (situation.conditions.length > 0) { - let condition = situation.conditions[0] - deleteCondition(condition, rootNodes) + if (situation.conditions !== undefined) { + while (situation.conditions.length > 0) { + let condition = situation.conditions[0] + deleteCondition(condition, rootNodes) + } } + situation.conditions = [] payload.parentNode.situations.splice(j, 1) destroyPart(situation) @@ -730,10 +763,13 @@ function newNodeDeleter () { } } } else { - while (node.conditions.length > 0) { - let condition = node.conditions[0] - deleteCondition(condition) + if (node.conditions !== undefined) { + while (node.conditions.length > 0) { + let condition = node.conditions[0] + deleteCondition(condition) + } } + node.conditions = [] completeDeletion(node, rootNodes) destroyPart(node) diff --git a/StrategySpace/Workspace/FunctionLibraries/PartsFromNodes.js b/StrategySpace/Workspace/FunctionLibraries/PartsFromNodes.js index 412d6160e..183843041 100644 --- a/StrategySpace/Workspace/FunctionLibraries/PartsFromNodes.js +++ b/StrategySpace/Workspace/FunctionLibraries/PartsFromNodes.js @@ -333,8 +333,11 @@ function newPartsFromNodes () { if (node.personalData !== undefined) { createPartFromNode(node.personalData, node, node) } - if (node.taskManager !== undefined) { - createPartFromNode(node.taskManager, node, node) + if (node.taskManagers !== undefined) { + for (let m = 0; m < node.taskManagers.length; m++) { + let taskManager = node.taskManagers[m] + createPartFromNode(taskManager, node, node) + } } return } @@ -385,14 +388,16 @@ function newPartsFromNodes () { } function addTaskManager (node) { - if (node.taskManager === undefined) { - node.taskManager = { - tasks: [] - } - createPart('Task Manager', '', node.taskManager, node, node) + let taskManager = { + name: 'New Task Manager' } + if (node.taskManagers === undefined) { + node.taskManagers = [] + } + node.taskManagers.push(taskManager) + createPart('Task Manager', taskManager.name, taskManager, node, node, 'Task Manager') - return node.taskManager + return taskManager } function addTask (node) { diff --git a/StrategySpace/Workspace/FunctionLibraries/ProtocolNode.js b/StrategySpace/Workspace/FunctionLibraries/ProtocolNode.js index b9a9f95f4..9ee0774ed 100644 --- a/StrategySpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/StrategySpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -450,7 +450,11 @@ function newProtocolNode () { name: node.name, tradingSystem: getProtocolNode(node.tradingSystem, removePersonalData, parseJSONStrings, includeIds), personalData: getProtocolNode(node.personalData, removePersonalData, parseJSONStrings, includeIds), - taskManager: getProtocolNode(node.taskManager, removePersonalData, parseJSONStrings, includeIds) + taskManagers: [] + } + for (let m = 0; m < node.taskManagers.length; m++) { + let taskManager = getProtocolNode(node.taskManagers[m], removePersonalData, parseJSONStrings, includeIds) + object.taskManagers.push(taskManager) } return object } diff --git a/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js b/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js index 79a4ed6de..6cdf0dbea 100644 --- a/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js +++ b/StrategySpace/Workspace/FunctionLibraries/StringifyNode.js @@ -435,11 +435,12 @@ function newStringifyNode () { savedPayload: getSavedPayload(node) } - for (let m = 0; m < node.tasks.length; m++) { - let task = prepareForStringify(node.tasks[m], removePersonalData) - taskManager.tasks.push(task) + if (node.tasks !== undefined) { + for (let m = 0; m < node.tasks.length; m++) { + let task = prepareForStringify(node.tasks[m], removePersonalData) + taskManager.tasks.push(task) + } } - return taskManager } case 'Task': { @@ -523,9 +524,15 @@ function newStringifyNode () { name: node.name, tradingSystem: prepareForStringify(node.tradingSystem, removePersonalData), personalData: prepareForStringify(node.personalData, removePersonalData), - taskManager: prepareForStringify(node.taskManager, removePersonalData), + taskManagers: [], savedPayload: getSavedPayload(node) } + if (node.taskManagers !== undefined) { + for (let m = 0; m < node.taskManagers.length; m++) { + let taskManager = prepareForStringify(node.taskManagers[m], removePersonalData) + object.taskManagers.push(taskManager) + } + } return object } } @@ -551,7 +558,7 @@ function newStringifyNode () { isTensed: (node.payload.floatingObject.isTensed && node.payload.floatingObject.tensedManually) }, uiObject: { - isRunning: node.payload.uiObject.isRunning + isDefault: node.payload.uiObject.isDefault } } return savedPayload diff --git a/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js b/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js index df729a1c3..341f386dc 100644 --- a/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js +++ b/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js @@ -8,17 +8,17 @@ function newTaskFunctions () { return thisObject - function runTask (node, functionLibraryProtocolNode) { + function runTask (node, functionLibraryProtocolNode, callBackFunction) { /* Check if it is possible to Run or not */ if (node.bot === undefined) { return } if (node.bot.processes.length === 0) { return } for (let i = 0; i < node.bot.processes.length; i++) { let process = node.bot.processes[i] - process.payload.uiObject.play() + process.payload.uiObject.run() } - node.payload.uiObject.play() + node.payload.uiObject.run(callBackFunction) let event = { taskId: node.id, @@ -28,14 +28,14 @@ function newTaskFunctions () { systemEventHandler.raiseEvent('Task Manager', 'Run Task', event) } - function stopTask (node, functionLibraryProtocolNode) { + function stopTask (node, functionLibraryProtocolNode, callBackFunction) { let event = { taskId: node.id, taskName: node.name } systemEventHandler.raiseEvent('Task Manager', 'Stop Task', event) - node.payload.uiObject.stop() + node.payload.uiObject.stop(callBackFunction) if (node.bot === undefined) { return } if (node.bot.processes.length === 0) { return } @@ -49,14 +49,18 @@ function newTaskFunctions () { function runAllTasks (taskManager, functionLibraryProtocolNode) { for (let i = 0; i < taskManager.tasks.length; i++) { let node = taskManager.tasks[i] - runTask(node, functionLibraryProtocolNode) + let menu = node.payload.uiObject.menu + + menu.internalClick('Run Task') } } function stopAllTasks (taskManager, functionLibraryProtocolNode) { for (let i = 0; i < taskManager.tasks.length; i++) { let node = taskManager.tasks[i] - stopTask(node, functionLibraryProtocolNode) + let menu = node.payload.uiObject.menu + + menu.internalClick('Stop Task') } } } diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index dae445530..0a31a8006 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -93,7 +93,7 @@ function newWorkspace () { thisObject.definition = canvas.strategySpace.strategizerGateway.strategizerData workspaceNode.rootNodes.push(thisObject.definition) functionLibraryPartsFromNodes.createPartFromNode(thisObject.definition, undefined, undefined) - thisObject.definition.payload.uiObject.setRunningStatus() + thisObject.definition.payload.uiObject.setDefaultStatus() thisObject.enabled = true } } @@ -167,7 +167,7 @@ function newWorkspace () { } } - async function onMenuItemClick (payload, action) { + async function onMenuItemClick (payload, action, callBackFunction) { switch (action) { case 'Share Workspace': { @@ -186,7 +186,11 @@ function newWorkspace () { case 'Save Trading System': { let result = await canvas.strategySpace.strategizerGateway.saveToStrategyzer(getSimulationParams()) - return result + if (result === true) { + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) + } else { + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + } break } @@ -223,12 +227,12 @@ function newWorkspace () { break case 'Run Task': { - functionLibraryTaskFunctions.runTask(payload.node, functionLibraryProtocolNode) + functionLibraryTaskFunctions.runTask(payload.node, functionLibraryProtocolNode, callBackFunction) } break case 'Stop Task': { - functionLibraryTaskFunctions.stopTask(payload.node, functionLibraryProtocolNode) + functionLibraryTaskFunctions.stopTask(payload.node, functionLibraryProtocolNode, callBackFunction) } break case 'Run All Tasks': diff --git a/SystemEventHandler.js b/SystemEventHandler.js index 072fa880b..740048d48 100644 --- a/SystemEventHandler.js +++ b/SystemEventHandler.js @@ -30,7 +30,13 @@ function newSystemEventHandler () { function sendCommand (command, responseCallBack, eventsCallBack) { if (command.action === 'listenToEvent') { - eventListeners.set(command.eventHandlerName + '-' + command.eventType, eventsCallBack) + let key + if (command.callerId !== undefined) { + key = command.eventHandlerName + '-' + command.eventType + '-' + command.callerId + } else { + key = command.eventHandlerName + '-' + command.eventType + } + eventListeners.set(key, eventsCallBack) } if (command.callerId && responseCallBack) { responseWaiters.set(command.callerId, responseCallBack) @@ -107,7 +113,13 @@ function newSystemEventHandler () { let message = JSON.parse(e.data) if (message.action === 'Event Raised') { - let handler = eventListeners.get(message.eventHandlerName + '-' + message.eventType) + let key + if (message.callerId !== undefined) { + key = message.eventHandlerName + '-' + message.eventType + '-' + message.callerId + } else { + key = message.eventHandlerName + '-' + message.eventType + } + let handler = eventListeners.get(key) if (handler) { handler(message) }