diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 266d60252..ebe1c6bc0 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -593,11 +593,11 @@ function newStrategyPart () { thisObject.circularProgressBar.fitFunction = thisObject.fitFunction thisObject.circularProgressBar.container = thisObject.container - /* We will wait to the event that the task was terminated in order to call back the menu item */ + /* We will wait to the event that the execution 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) + systemEventHandler.listenToEvent(key, 'Running', undefined, key, undefined, onExecutionTerminated) - function onTaskTerminated () { + function onExecutionTerminated () { if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) } @@ -605,11 +605,11 @@ function newStrategyPart () { } function stop (callBackFunction) { - /* We will wait to the event that the task was terminated in order to call back the menu item */ + /* We will wait to the event that the execution 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) + let eventSubscriptionId = systemEventHandler.listenToEvent(key, 'Stopped', undefined, key, undefined, onExecutionTerminated) - function onTaskTerminated () { + function onExecutionTerminated () { if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) } @@ -1130,4 +1130,3 @@ function newStrategyPart () { } } } - diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index d00f4a582..620d19777 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -887,7 +887,7 @@ function newStrategyPartConstructor () { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Run Backtesting Session', + action: 'Run Session', actionFunction: payload.onMenuItemClick, label: 'Run', workingLabel: 'Stop', @@ -944,7 +944,7 @@ function newStrategyPartConstructor () { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Run Live Trading Session', + action: 'Run Session', actionFunction: payload.onMenuItemClick, label: 'Run', workingLabel: 'Stop', @@ -1001,7 +1001,7 @@ function newStrategyPartConstructor () { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Run Fordward Testing Session', + action: 'Run Session', actionFunction: payload.onMenuItemClick, label: 'Run', workingLabel: 'Stop', @@ -1058,7 +1058,7 @@ function newStrategyPartConstructor () { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Run Paper Trading Session', + action: 'Run Session', actionFunction: payload.onMenuItemClick, label: 'Run', workingLabel: 'Stop', diff --git a/StrategySpace/Workspace/FunctionLibraries/SessionFunctions.js b/StrategySpace/Workspace/FunctionLibraries/SessionFunctions.js new file mode 100644 index 000000000..8c7ad313a --- /dev/null +++ b/StrategySpace/Workspace/FunctionLibraries/SessionFunctions.js @@ -0,0 +1,33 @@ +function newSessionFunctions () { + thisObject = { + runSession: runSession, + stopSession: stopSession + } + + return thisObject + + function runSession (node, functionLibraryProtocolNode, callBackFunction) { + node.payload.uiObject.run(callBackFunction) + + let event = { + session: JSON.stringify(functionLibraryProtocolNode.getProtocolNode(node, false, false, true)), + definition: getDefinition() + } + + let key = 'Session' + '-' + node.id + '-' + 'Events' + systemEventHandler.raiseEvent(key, 'Run Session', event) + + function getDefinition () { + let definitionNode = canvas.strategySpace.workspace.getProtocolDefinitionNode() + definitionNode.simulationParams = getSimulationParams() + return JSON.stringify(definitionNode) + } + } + + function stopSession (node, functionLibraryProtocolNode, callBackFunction) { + let key = 'Session' + '-' + node.id + '-' + 'Events' + systemEventHandler.raiseEvent(key, 'Stop Session') + + node.payload.uiObject.stop(callBackFunction) + } +} diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index ae255d695..637d9346f 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -46,6 +46,7 @@ function newWorkspace () { let functionLibraryProtocolNode = newProtocolNode() let functionLibraryWorkspaceNodes = newStringifyNode() let functionLibraryTaskFunctions = newTaskFunctions() + let functionLibrarySessionFunctions = newSessionFunctions() thisObject.nodeChildren = newNodeChildren() return thisObject @@ -246,6 +247,16 @@ function newWorkspace () { functionLibraryTaskFunctions.stopAllTasks(payload.node, functionLibraryProtocolNode) } break + case 'Run Session': + { + functionLibrarySessionFunctions.runSession(payload.node, functionLibraryProtocolNode, callBackFunction) + } + break + case 'Stop Session': + { + functionLibrarySessionFunctions.stopSession(payload.node, functionLibraryProtocolNode, callBackFunction) + } + break case 'Add Network': { functionLibraryPartsFromNodes.addNetwork(payload.node)