diff --git a/ChartingSpace/PlottersManager.js b/ChartingSpace/PlottersManager.js index 844a42987..2d3b9c35a 100644 --- a/ChartingSpace/PlottersManager.js +++ b/ChartingSpace/PlottersManager.js @@ -131,7 +131,7 @@ function newPlottersManager () { baseAsset: baseAsset, quotedAsset: quotedAsset } - let product = layer.definition.referenceParent.referenceParent + let productDefinition = layer.definition.referenceParent.referenceParent let bot = layer.definition.referenceParent.referenceParent.parentNode let dataMine = layer.definition.referenceParent.referenceParent.parentNode.parentNode let exchange = layer.definition.referenceParent.parentNode.referenceParent.parentNode.parentNode @@ -171,7 +171,7 @@ function newPlottersManager () { dataMine, bot, session, - product, + productDefinition, exchange, market, datetime, @@ -197,7 +197,7 @@ function newPlottersManager () { plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2 plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2 plotter.fitFunction = thisObject.fitFunction - plotter.initialize(storage, datetime, timeFrame, coordinateSystem, onPlotterInizialized, product) + plotter.initialize(storage, datetime, timeFrame, coordinateSystem, onPlotterInizialized, productDefinition) function onPlotterInizialized () { let connector = { @@ -210,7 +210,7 @@ function newPlottersManager () { /* Lets load now this plotter panels. */ connector.panels = [] - if (product !== undefined) { + if (productDefinition !== undefined) { /* Here we setup the panels associated with this plotter */ for (let i = 0; i < plotterModule.panels.length; i++) { let panel = plotterModule.panels[i] @@ -235,7 +235,7 @@ function newPlottersManager () { /* Next we will check the different types of Plotting related to connecting to an existing node branch. */ - if (plotterModule.nodesHighlights !== undefined) { + if (plotterModule.nodesHighlights !== undefined && plotterModule.config.connectTo !== undefined) { connector.nodesHighlights = newNodesHighlights() switch (plotterModule.config.connectTo) { case 'Trading System': @@ -247,7 +247,7 @@ function newPlottersManager () { } connector.nodesHighlights.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesHighlights.onRecordChange) } - if (plotterModule.nodesValues !== undefined) { + if (plotterModule.nodesValues !== undefined && plotterModule.config.connectTo !== undefined) { connector.nodesValues = newNodesValues() switch (plotterModule.config.connectTo) { case 'Trading System': @@ -259,7 +259,7 @@ function newPlottersManager () { } connector.nodesValues.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesValues.onRecordChange) } - if (plotterModule.nodesErrors !== undefined) { + if (plotterModule.nodesErrors !== undefined && plotterModule.config.connectTo !== undefined) { connector.nodesErrors = newNodesErrors() switch (plotterModule.config.connectTo) { case 'Trading System': @@ -271,7 +271,7 @@ function newPlottersManager () { } connector.nodesErrors.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesErrors.onRecordChange) } - if (plotterModule.nodesRunning !== undefined) { + if (plotterModule.nodesRunning !== undefined && plotterModule.config.connectTo !== undefined) { connector.nodesRunning = newNodesRunning() switch (plotterModule.config.connectTo) { case 'Trading System': @@ -283,7 +283,7 @@ function newPlottersManager () { } connector.nodesRunning.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesRunning.onRecordChange) } - if (plotterModule.nodesStatus !== undefined) { + if (plotterModule.nodesStatus !== undefined && plotterModule.config.connectTo !== undefined) { connector.nodesStatus = newNodesStatus() switch (plotterModule.config.connectTo) { case 'Trading System': @@ -295,7 +295,7 @@ function newPlottersManager () { } connector.nodesStatus.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesStatus.onRecordChange) } - if (plotterModule.nodesProgress !== undefined) { + if (plotterModule.nodesProgress !== undefined && plotterModule.config.connectTo !== undefined) { connector.nodesProgress = newNodesProgress() switch (plotterModule.config.connectTo) { case 'Trading System': @@ -307,6 +307,15 @@ function newPlottersManager () { } connector.nodesProgress.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesProgress.onRecordChange) } + /* + Another type of plotting is with Record Values. This method uses the record definition to find the target node + and from there is looks into its children all based on the Record Definition configuration. + */ + if (plotterModule.recordValues !== undefined) { + connector.recordValues = newRecordValues() + connector.recordValues.initialize(tradingSystem, tradingEngine, productDefinition) + connector.recordValues.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.recordValues.onRecordChange) + } } thisObject.connectors.push(connector) } @@ -383,6 +392,10 @@ function newPlottersManager () { connector.plotter.container.eventHandler.stopListening(connector.nodesRunning.onRecordChangeEventsSubscriptionId) connector.nodesRunning.finalize() } + if (connector.recordValues !== undefined) { + connector.plotter.container.eventHandler.stopListening(connector.recordValues.onRecordChangeEventsSubscriptionId) + connector.recordValues.finalize() + } } function setTimeFrame (pTimeFrame) { diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index cde2688e8..5203cbeaf 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -1432,7 +1432,7 @@ function newUiObject () { label = currentValue if (!isNaN(label)) { if (currentValue.toFixed !== undefined) { - label = dynamicDecimals(currentValue, 2) + label = dynamicDecimals(currentValue) } } diff --git a/Panels/Layer.js b/Panels/Layer.js index 1aa9e003f..45efdedbc 100644 --- a/Panels/Layer.js +++ b/Panels/Layer.js @@ -175,7 +175,7 @@ function newLayer () { 'Polygon Border->Style->Style Condition->Style->' + 'Polygon Vertex->Point->' + 'Plotter Panel->Javascript Code->Panel Data->Data Formula->' + - 'Nodes Highlights->Nodes Values->Nodes Errors->Nodes Status->Nodes Progress->Nodes Running->' + 'Nodes Highlights->Nodes Values->Nodes Errors->Nodes Status->Nodes Progress->Nodes Running->Record Values->' thisObject.definition = functionLibraryProtocolNode.getProtocolNode(thisObject.payload.node, false, true, true, false, false, lightingPath) /* Here we validate that we have all the needed information */ diff --git a/Plotting/RecordValues.js b/Plotting/RecordValues.js new file mode 100644 index 000000000..b66ba150f --- /dev/null +++ b/Plotting/RecordValues.js @@ -0,0 +1,62 @@ +function newRecordValues () { + const MODULE_NAME = 'Record Values' + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + onRecordChange: onRecordChange, + initialize: initialize, + finalize: finalize + } + + let tradingSystem + let tradingEngine + let productDefinition + let productTargetNode + let propertyTargetNodeMap = new Map() + return thisObject + + function finalize () { + tradingSystem = undefined + tradingEngine = undefined + productDefinition = undefined + productTargetNode = undefined + propertyTargetNodeMap = undefined + } + + function initialize (pTradingSystem, pTradingEngine, pProductDefinition) { + tradingSystem = canvas.designSpace.workspace.getHierarchyHeadsById(pTradingSystem.id) + tradingEngine = canvas.designSpace.workspace.getHierarchyHeadsById(pTradingEngine.id) + productDefinition = pProductDefinition + productTargetNode = eval(productDefinition.config.nodePath) + + for (let i = 0; i < productDefinition.record.properties.length; i++) { + let property = productDefinition.record.properties[i] + if (property.config.nodePath !== undefined) { + let propertyRoot = eval(property.config.nodePath) + propertyTargetNodeMap.set(property.id, propertyRoot) + } else { + propertyTargetNodeMap.set(property.id, productTargetNode) + } + } + } + + function onRecordChange (currentRecord) { + if (currentRecord === undefined) { return } + for (let i = 0; i < productDefinition.record.properties.length; i++) { + let property = productDefinition.record.properties[i] + let value = currentRecord[property.config.codeName] + let targetNode = propertyTargetNodeMap.get(property.id) + applyValue(targetNode[property.config.codeName], value) + } + } + + function applyValue (node, value) { + if (node === undefined) { return } + if (node.payload === undefined) { return } + if (node.payload.uiObject === undefined) { return } + if (value === true) { value = 'true' } + if (value === false) { value = 'false' } + node.payload.uiObject.setValue(value, 30) + } +}