diff --git a/Spaces/StrategySpace.js b/Spaces/StrategySpace.js index 69aa27093..c0a9dcad7 100644 --- a/Spaces/StrategySpace.js +++ b/Spaces/StrategySpace.js @@ -3,7 +3,7 @@ function newStrategySpace () { const MODULE_NAME = 'Strategy Space' let thisObject = { sidePanel: undefined, - tradingSystemWorkspace: undefined, + workplace: undefined, container: undefined, draw: draw, getContainer: getContainer, @@ -24,17 +24,17 @@ function newStrategySpace () { // thisObject.sidePanel = newSidePanel() // thisObject.sidePanel.initialize() - thisObject.tradingSystemWorkspace = newWorkspace() - // thisObject.tradingSystemWorkspace.container.connectToParent(thisObject.sidePanel.container, true, true) - thisObject.tradingSystemWorkspace.initialize() - await thisObject.tradingSystemWorkspace.loadFromStrategyzer() + thisObject.workplace = newWorkspace() + // thisObject.workplace.container.connectToParent(thisObject.sidePanel.container, true, true) + thisObject.workplace.initialize() + await thisObject.workplace.loadFromStrategyzer() - // thisObject.sidePanel.areas.push(thisObject.tradingSystemWorkspace) + // thisObject.sidePanel.areas.push(thisObject.workplace) } function makeVisible () { - if (thisObject.tradingSystemWorkspace.isDeployed !== true) { - thisObject.tradingSystemWorkspace.deploydTradingSystem() + if (thisObject.workplace.isDeployed !== true) { + thisObject.workplace.deploydTradingSystem() } canvas.floatingSpace.makeVisible() visible = true @@ -47,8 +47,8 @@ function newStrategySpace () { function getContainer (point) { let container - if (thisObject.tradingSystemWorkspace !== undefined) { - container = thisObject.tradingSystemWorkspace.getContainer(point) + if (thisObject.workplace !== undefined) { + container = thisObject.workplace.getContainer(point) if (container !== undefined) { return container } } diff --git a/StrategySpace/TradingSystem.js b/StrategySpace/TradingSystem.js index 9b8e38174..aaae4beb6 100644 --- a/StrategySpace/TradingSystem.js +++ b/StrategySpace/TradingSystem.js @@ -245,6 +245,9 @@ function newTradingSystem () { function onMenuItemClick (payload, action) { switch (action) { + case 'Save Trading System': + canvas.strategySpace.workplace.saveToStrategyzer() + break case 'Open Settings': break diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 27ec027d2..ef566381f 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -9,7 +9,9 @@ function newWorkspace () { isDeployed: false, strategies: undefined, container: undefined, + tradingSystem: undefined, loadFromStrategyzer: loadFromStrategyzer, + saveToStrategyzer: saveToStrategyzer, deploydTradingSystem: deploydTradingSystem, draw: draw, getContainer: getContainer, @@ -37,6 +39,182 @@ function newWorkspace () { } + function saveToStrategyzer () { + let graphQL_Mutation = '' + + graphQL_Mutation = graphQL_Mutation + 'strategy: { ' + graphQL_Mutation = graphQL_Mutation + 'subStrategies: [ ' + + for (m = 0; m < thisObject.tradingSystem.protocolData.strategies.length; m++) { + let strategy = thisObject.tradingSystem.protocolData.strategies[m] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'active: true ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + strategy.name + '" ' + + graphQL_Mutation = graphQL_Mutation + 'entryPoint: { ' + graphQL_Mutation = graphQL_Mutation + 'situations: [ ' + + for (let k = 0; k < strategy.entryPoint.situations.length; k++) { + let situation = strategy.entryPoint.situations[k] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + situation.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'conditions: [ ' + + for (let m = 0; m < situation.conditions.length; m++) { + let condition = situation.conditions[m] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + condition.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'code: "' + condition.code + '" ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + + graphQL_Mutation = graphQL_Mutation + 'exitPoint: { ' + graphQL_Mutation = graphQL_Mutation + 'situations: [ ' + + for (let k = 0; k < strategy.exitPoint.situations.length; k++) { + let situation = strategy.exitPoint.situations[k] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + situation.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'conditions: [ ' + + for (let m = 0; m < situation.conditions.length; m++) { + let condition = situation.conditions[m] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + condition.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'code: "' + condition.code + '" ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + + graphQL_Mutation = graphQL_Mutation + 'sellPoint: { ' + graphQL_Mutation = graphQL_Mutation + 'situations: [ ' + + for (let k = 0; k < strategy.sellPoint.situations.length; k++) { + let situation = strategy.sellPoint.situations[k] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + situation.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'conditions: [ ' + + for (let m = 0; m < situation.conditions.length; m++) { + let condition = situation.conditions[m] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + condition.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'code: "' + condition.code + '" ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + + graphQL_Mutation = graphQL_Mutation + 'stopLoss: { ' + graphQL_Mutation = graphQL_Mutation + 'phases: [ ' + + for (let p = 0; p < strategy.stopLoss.phases.length; p++) { + let phase = strategy.stopLoss.phases[p] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + phase.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'code: "' + phase.code + '" ' + graphQL_Mutation = graphQL_Mutation + 'situations: [ ' + + for (let k = 0; k < phase.situations.length; k++) { + let situation = phase.situations[k] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + situation.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'conditions: [ ' + + for (let m = 0; m < situation.conditions.length; m++) { + let condition = situation.conditions[m] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + condition.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'code: "' + condition.code + '" ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + + graphQL_Mutation = graphQL_Mutation + 'buyOrder: { ' + graphQL_Mutation = graphQL_Mutation + 'phases: [ ' + + for (let p = 0; p < strategy.buyOrder.phases.length; p++) { + let phase = strategy.buyOrder.phases[p] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + phase.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'code: "' + phase.code + '" ' + graphQL_Mutation = graphQL_Mutation + 'situations: [ ' + + for (let k = 0; k < phase.situations.length; k++) { + let situation = phase.situations[k] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + situation.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'conditions: [ ' + + for (let m = 0; m < situation.conditions.length; m++) { + let condition = situation.conditions[m] + + graphQL_Mutation = graphQL_Mutation + '{ ' + graphQL_Mutation = graphQL_Mutation + 'name: "' + condition.name + '" ' + graphQL_Mutation = graphQL_Mutation + 'code: "' + condition.code + '" ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + + graphQL_Mutation = graphQL_Mutation + '} ' + } + + graphQL_Mutation = graphQL_Mutation + '] ' + graphQL_Mutation = graphQL_Mutation + '} ' + + console.log(graphQL_Mutation) + } + async function loadFromStrategyzer () { try { const accessToken = window.localStorage.getItem('xaccess_token')