From dcbe60f5a516d64db6530e2add61905f3ae83b4a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 23 Sep 2019 14:54:07 +0200 Subject: [PATCH 01/11] Sequence Files Initialization Fixed --- Dashboard.js | 9 +++++++++ ProductStorage.js | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Dashboard.js b/Dashboard.js index ac0507ce8..0794dc76f 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -33,6 +33,8 @@ function newDashboard () { function start () { try { + setBrowserEvents() + systemEventHandler = newSystemEventHandler() systemEventHandler.initialize(startCanvas) @@ -107,4 +109,11 @@ function newDashboard () { if (ERROR_LOG === true) { logger.write('[ERROR] browserResized -> err = ' + err.stack) } } } + + function setBrowserEvents () { + window.onbeforeunload = onBrowserClosed + function onBrowserClosed () { + window.alert('My Window is closing') + } + } } diff --git a/ProductStorage.js b/ProductStorage.js index acd829022..371270b90 100644 --- a/ProductStorage.js +++ b/ProductStorage.js @@ -257,10 +257,19 @@ function newProductStorage (pName) { return } } - let event = { - totalValue: pCaller.getExpectedFiles(), - currentValue: pCaller.getFilesLoaded() + let event + if (pCaller !== undefined) { + event = { + totalValue: pCaller.getExpectedFiles(), + currentValue: pCaller.getFilesLoaded() + } + } else { // When there are no data the reference to the caller wont arrive here. + event = { + totalValue: 1, + currentValue: 1 + } } + thisObject.eventHandler.raiseEvent('File Sequence Loaded', event) if (event.currentValue === event.totalValue) { From 432b5c9dcdbd5999428e00109a53069a3c869ece Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 23 Sep 2019 15:02:30 +0200 Subject: [PATCH 02/11] Stopping All Tasks when browser is closed or page refreshed --- Dashboard.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dashboard.js b/Dashboard.js index 0794dc76f..d4cf9d407 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -113,7 +113,11 @@ function newDashboard () { function setBrowserEvents () { window.onbeforeunload = onBrowserClosed function onBrowserClosed () { - window.alert('My Window is closing') + let definition = canvas.strategySpace.workspace.definition + for (let i = 0; i < definition.taskManagers.length; i++) { + taskManager = definition.taskManagers[i] + taskManager.payload.uiObject.menu.internalClick('Stop All Tasks') + } } } } From d331b84c26c746cfdbf57f9fb4b6faa5e1b24785 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 23 Sep 2019 15:40:23 +0200 Subject: [PATCH 03/11] Bug Fixed ViewPort not loading --- Dashboard.js | 10 +-- Spaces/TopSpace.js | 27 +------ TopSpace/Login.js | 187 --------------------------------------------- 3 files changed, 5 insertions(+), 219 deletions(-) delete mode 100644 TopSpace/Login.js diff --git a/Dashboard.js b/Dashboard.js index d4cf9d407..f2de0d950 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -2,16 +2,7 @@ let canvas let markets let ecosystem = newEcosystem() let systemEventHandler - let viewPort -try { - viewPort = newViewPort() -} catch (e) { - setTimeout(() => { - console.log('Loading deferred.') - viewPort = newViewPort() - }, 1000) -} function newDashboard () { const MODULE_NAME = 'Dashboard' @@ -34,6 +25,7 @@ function newDashboard () { function start () { try { setBrowserEvents() + viewPort = newViewPort() systemEventHandler = newSystemEventHandler() systemEventHandler.initialize(startCanvas) diff --git a/Spaces/TopSpace.js b/Spaces/TopSpace.js index c67effb91..ed96650ac 100644 --- a/Spaces/TopSpace.js +++ b/Spaces/TopSpace.js @@ -3,14 +3,11 @@ function newTopSpace () { let thisObject = { container: undefined, draw: draw, - getContainer: getContainer, // returns the inner most container that holds the point received by parameter. - endUser: undefined, - currentEvent: undefined, - login: undefined, + getContainer: getContainer, initialize: initialize } - var container = newContainer() + let container = newContainer() container.initialize() thisObject.container = container @@ -20,19 +17,7 @@ function newTopSpace () { return thisObject - async function initialize () { - let sharedStatus = { - currentDevTeamIndex: 0, - currentEventIndex: 0, - currentUserBotIndex: 0, - currentProcessIndex: 0, - currentBotType: '', - eventHandler: newEventHandler() - } - - thisObject.login = newLogin() - await thisObject.login.initialize(sharedStatus) - + function initialize () { window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize) } @@ -43,7 +28,7 @@ function newTopSpace () { container.frame.position.x = 0 try { container.frame.position.y = viewPort.visibleArea.bottomLeft.y - } catch(e) { } + } catch (e) { } } function getContainer (point) { @@ -66,10 +51,6 @@ function newTopSpace () { drawBackground() return - - thisObject.endUser.draw() - thisObject.currentEvent.draw() - thisObject.login.draw() } function drawBackground () { diff --git a/TopSpace/Login.js b/TopSpace/Login.js deleted file mode 100644 index 79b09d25a..000000000 --- a/TopSpace/Login.js +++ /dev/null @@ -1,187 +0,0 @@ - -function newLogin () { - const MODULE_NAME = 'Login' - const ERROR_LOG = true - const logger = newWebDebugLog() - logger.fileName = MODULE_NAME - - let thisObject = { - container: undefined, - draw: draw, - getContainer: getContainer, - initialize: initialize - } - - let container = newContainer() - container.initialize() - thisObject.container = container - - thisObject.container.frame.width = 200 - thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT - - container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1 - container.frame.position.y = viewPort.visibleArea.bottomLeft.y + BREAKPOINT_HEIGHT - - container.isDraggeable = false - container.isClickeable = true - - return thisObject - - async function initialize (sharedStatus) { - try { - if (window.canvasApp.executingAt === 'Local') { return } - - const accessToken = window.localStorage.getItem('access_token') - - if (accessToken) { - await getEvents(accessToken, sharedStatus) - // await getClones(accessToken) - } - - thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) } - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err.stack = ' + err.stack) } - } - } - - async function getEvents (accessToken, sharedStatus) { - var d = new Date() - var nowSeconds = Math.round(d.getTime() / 1000) - var twoWeeksAgoSeconds = nowSeconds - 1209600 - - let response = await axios({ - url: window.canvasApp.graphQL.masterAppApiUrl, - method: 'post', - data: { - query: - `query events($maxStartDate: Int, $minEndDate: Int){ - events_Events(maxStartDate: $maxStartDate, minEndDate: $minEndDate){ - id - title - startDatetime - endDatetime - participants{ - clone{ - id - team{ - slug - } - bot{ - slug - } - } - } - } - }` - }, - variables: { - variables: { maxStartDate: nowSeconds, minEndDate: twoWeeksAgoSeconds } - }, - headers: { - authorization: 'Bearer ' + accessToken - } - }) - - if (response.data.errors) { - console.log('Error getting events: ' + JSON.stringify(response.data.errors)) - throw 'Error getting events: ' + JSON.stringify(response.data.errors) - } else { - window.localStorage.setItem('currentEvents', JSON.stringify(response.data.data.events_Events)) - currentEvent = window.localStorage.getItem('currentEventObject') - if (currentEvent === null || currentEvent === '[]' || currentEvent === '') { - sharedStatus.currentEventIndex = -1 - } else { - currentEvent = JSON.parse(currentEvent) - sharedStatus.currentEventIndex = response.data.data.events_Events.findIndex(function (element) { - return element.id == currentEvent.id - }) - } - } - } - - async function getClones (accessToken) { - let response = await axios({ - url: window.canvasApp.graphQL.masterAppApiUrl, - method: 'post', - data: { - query: - `query Operations_Clones{ - operations_Clones { - id - authId - teamId - botId - mode - resumeExecution - beginDatetime - endDatetime - waitTime - state - stateDatetime - createDatetime - lastLogs - summaryDate - buyAverage - sellAverage - marketRate - combinedProfitsA - combinedProfitsB - assetA - assetB - botType - teamName - botName - botAvatar - teamAvatar - processName - keyId - botSlug - } - } - ` - }, - headers: { - authorization: 'Bearer ' + accessToken - } - }) - - if (response.data.errors) { - console.log('Error getting clones: ' + JSON.stringify(response.data.errors)) - throw 'Error getting clones: ' + JSON.stringify(response.data.errors) - } else { - window.localStorage.setItem('userClones', JSON.stringify(response.data.data.operations_Clones)) - let clones = response.data.data.operations_Clones - for (let i = 0; i < clones.length; i++) { - let clone = clones[i] - if (clone.botType === 'Trading') { - let teamSlug = clone.teamName.toLowerCase() - teamSlug = teamSlug.replace(' ', '-') - let devTeam = ecosystem.getTeam(teamSlug) - let bot = ecosystem.getBot(devTeam, clone.botSlug) - if (bot !== undefined) { - bot.cloneId = clone.id - } - } - } - } - } - - function onClick () { - - } - - function getContainer (point) { - /* First we check if this point is inside this object UI. */ - if (thisObject.container.frame.isThisPointHere(point, true) === true) { - return this.container - } else { - /* This point does not belong to this space. */ - return undefined - } - } - - function draw () { - return // nothing to show. - } -} From f82c7725de5ad624afa82ddc893d2efb0567551c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 23 Sep 2019 18:04:19 +0200 Subject: [PATCH 04/11] Backtesting and Live Trading labels --- CockpitSpace/RestartSimulation.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index b73e1a75e..aa2cb36e9 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -78,7 +78,10 @@ function newRestartSimulation () { } function getContainer (point, purpose) { - if (thisObject.visible !== true || (thisObject.status !== 'Ready' && thisObject.status !== 'Calculating') || executionFocusExists === false) { return } + if ( + thisObject.visible !== true || + (thisObject.status !== 'Ready' && thisObject.status !== 'Backtesting' && thisObject.status !== 'Live Trading') || + executionFocusExists === false) { return } if (thisObject.container.frame.isThisPointHere(point, true) === true) { return thisObject.container @@ -125,14 +128,15 @@ function newRestartSimulation () { definition: getDefinition() } systemEventHandler.raiseEvent('Cockpit-Restart-Button', 'Live-Trading Started', event) + thisObject.status = 'Live Trading' } else { let event = { definition: getDefinition() } systemEventHandler.raiseEvent('Cockpit-Restart-Button', 'Backstesting Started', event) + thisObject.status = 'Backtesting' } - thisObject.status = 'Calculating' isRunning = true } } else { @@ -190,9 +194,6 @@ function newRestartSimulation () { break case 'Saving': - break - case 'Calculating': - break case 'Stopping': @@ -269,7 +270,10 @@ function newRestartSimulation () { case 'Saving': params.backgroundColor = UI_COLOR.GREY break - case 'Calculating': + case 'Backtesting': + params.backgroundColor = UI_COLOR.GREEN + break + case 'Live Trading': params.backgroundColor = UI_COLOR.TITANIUM_YELLOW break case 'Stopping': @@ -304,8 +308,11 @@ function newRestartSimulation () { case 'Saving': label = 'SAVING STRATEGIES CHANGES...' break - case 'Calculating': - label = 'STOP CALCULATING' + case 'Backtesting': + label = 'STOP BACKTESTING' + break + case 'Live Trading': + label = 'STOP LIVE TRADING' break case 'Stopping': label = 'STOPPING...' From 09a400c15fa6c72d1613291e6703fb3e0ac24fa0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 24 Sep 2019 22:34:54 +0200 Subject: [PATCH 05/11] Clear logs for all --- CockpitSpace/RestartSimulation.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index aa2cb36e9..c1089f3fc 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -115,15 +115,15 @@ function newRestartSimulation () { thisObject.status = 'Error' counterTillNextState = 500 } else { - if (idleLabel === 'START LIVE TRADING') { - callServer('', 'ResetLogsAndData', onSaved) - function onSaved (err) { - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - logger.write('[INFO] Restart Simulation -> Logs and Simulation data Deleted.') - } else { - logger.write('[ERROR] Restart Simulation -> Can not delete Logs and Simulation data. err = ' + err.messsage) - } + callServer('', 'ResetLogsAndData', onSaved) + function onSaved (err) { + if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { + logger.write('[INFO] Restart Simulation -> Logs and Simulation data Deleted.') + } else { + logger.write('[ERROR] Restart Simulation -> Can not delete Logs and Simulation data. err = ' + err.messsage) } + } + if (idleLabel === 'START LIVE TRADING') { let event = { definition: getDefinition() } From 3418fb799848c309fec8b1dcbc2a1e0d88799020 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 24 Sep 2019 22:57:47 +0200 Subject: [PATCH 06/11] Bug Fixed Browser Frozen --- .../Workspace/FunctionLibraries/NodeDeleter.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js b/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js index bd0e1cc7d..46dbd37a7 100644 --- a/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js +++ b/StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js @@ -157,7 +157,19 @@ function newNodeDeleter () { deleteCloseExecution(rootNode, rootNodes) break } - case 'Event': { + case 'Trigger On Event': { + deleteEvent(rootNode, rootNodes) + break + } + case 'Trigger Off Event': { + deleteEvent(rootNode, rootNodes) + break + } + case 'Take Position Event': { + deleteEvent(rootNode, rootNodes) + break + } + case 'Next Phase Event': { deleteEvent(rootNode, rootNodes) break } @@ -187,7 +199,7 @@ function newNodeDeleter () { } default: { - console.log('WARNING this node type is not listed at NodeDeleter: ' + node.type) + console.log('WARNING this node type is not listed at NodeDeleter: ' + rootNode.type) } } } From 3e70cd3c64d8193b91dd12954b579712fe17fe96 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 24 Sep 2019 23:21:51 +0200 Subject: [PATCH 07/11] Stopping all tasks when workspace is replaced --- Dashboard.js | 14 +++++++++----- StrategySpace/Workspace/Workspace.js | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Dashboard.js b/Dashboard.js index f2de0d950..61142d631 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -105,11 +105,15 @@ function newDashboard () { function setBrowserEvents () { window.onbeforeunload = onBrowserClosed function onBrowserClosed () { - let definition = canvas.strategySpace.workspace.definition - for (let i = 0; i < definition.taskManagers.length; i++) { - taskManager = definition.taskManagers[i] - taskManager.payload.uiObject.menu.internalClick('Stop All Tasks') - } + stopAllRunningTasks() } } } + +function stopAllRunningTasks () { + let definition = canvas.strategySpace.workspace.definition + for (let i = 0; i < definition.taskManagers.length; i++) { + taskManager = definition.taskManagers[i] + taskManager.payload.uiObject.menu.internalClick('Stop All Tasks') + } +} diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index 0a31a8006..0dd9e4c87 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -150,6 +150,7 @@ function newWorkspace () { let droppedNode = JSON.parse(nodeText) if (droppedNode.type === 'Workspace') { + stopAllRunningTasks() functionLibraryNodeDeleter.deleteWorkspace(workspaceNode, workspaceNode.rootNodes) workspaceNode = droppedNode functionLibraryPartsFromNodes.createPartFromNode(workspaceNode, undefined, undefined) From 87007f3456eebd956d3c129df15d5614ebbaa863 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Sep 2019 09:33:42 +0200 Subject: [PATCH 08/11] Was inverted --- FloatingSpace/StrategyPartConstructor.js | 4 ++-- StrategySpace/Workspace/FunctionLibraries/AttachDetach.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 87db6c451..5f84cf0b3 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -124,8 +124,8 @@ function newStrategyPartConstructor () { currentStatus: true, label: undefined, visible: true, - iconPathOn: 'menu-mobility-freeze', - iconPathOff: 'menu-mobility-unfreeze', + iconPathOn: 'menu-mobility-unfreeze', + iconPathOff: 'menu-mobility-freeze', rawRadius: 8, targetRadius: 0, currentRadius: 0, diff --git a/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js b/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js index 01e71cdba..82fe0caf0 100644 --- a/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js +++ b/StrategySpace/Workspace/FunctionLibraries/AttachDetach.js @@ -116,6 +116,11 @@ function newAttachDetach () { completeDetachment(node, rootNodes) return } + case 'Parameters': { + node.payload.parentNode.parameters = undefined + completeDetachment(node, rootNodes) + return + } case 'Strategy': { let payload = node.payload for (let i = 0; i < payload.parentNode.strategies.length; i++) { From e5a02fb988736f3db55849a240cce43195ad4450 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Sep 2019 09:45:17 +0200 Subject: [PATCH 09/11] Bug Fixed with icon status --- FloatingSpace/StrategyPartConstructor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 5f84cf0b3..90f802865 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -136,7 +136,7 @@ function newStrategyPartConstructor () { { action: 'Collapse / Uncollapse', actionFunction: floatingObject.collapseToggle, - actionStatus: floatingObject.getCollapeseStatus, + actionStatus: floatingObject.getCollapseStatus, currentStatus: false, label: undefined, visible: true, From c4fb8e00708a8d5eec602545d678344f2281ee08 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Sep 2019 13:14:55 +0200 Subject: [PATCH 10/11] Dates issues fixed --- Utilities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utilities.js b/Utilities.js index 1639bdb62..7325e599f 100644 --- a/Utilities.js +++ b/Utilities.js @@ -8,7 +8,7 @@ function getSimulationParams () { let timePeriod = timePeriodArray[currentTimePeriod.timePeriodIndex][1] let simulationParams = { - beginDatetime: dateAtScreenCorner.valueOf(), + beginDatetime: dateAtScreenCorner, timePeriod: timePeriod, timestamp: (new Date()).valueOf() } From 4e064c5f325f215905008d675ea633b6c18ea67e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Sep 2019 17:38:16 +0200 Subject: [PATCH 11/11] Unnecesario logging --- CockpitSpace/RestartSimulation.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index c1089f3fc..26f44c099 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -117,9 +117,7 @@ function newRestartSimulation () { } else { callServer('', 'ResetLogsAndData', onSaved) function onSaved (err) { - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - logger.write('[INFO] Restart Simulation -> Logs and Simulation data Deleted.') - } else { + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { logger.write('[ERROR] Restart Simulation -> Can not delete Logs and Simulation data. err = ' + err.messsage) } }