HUGE Refactoring Superalgos Project to Foundations Project done
This commit is contained in:
1 parent
c9c0aeaca7
commit
87edcc043d
3557 files changed
+10791
-10789
No files matched your search
@@ -0,0 +1,737 @@
|
||||
function newFoundationsActionSwitch() {
|
||||
|
||||
let thisObject = {
|
||||
executeAction: executeAction,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
/* Nothing to initialize since a Function Library does not hold any state. */
|
||||
}
|
||||
|
||||
async function executeAction(action) {
|
||||
switch (action.name) {
|
||||
case 'Get Node On Focus': {
|
||||
return UI.projects.foundations.functionLibraries.onFocus.getNodeThatIsOnFocus(action.node)
|
||||
}
|
||||
|
||||
case 'Get Node By Shortcut Key': {
|
||||
return UI.projects.foundations.functionLibraries.shortcutKeys.getNodeByShortcutKey(action.node, action.extraParameter)
|
||||
}
|
||||
|
||||
case 'Get Node Data Structure': {
|
||||
return UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(action.node, action.extraParameter, false, true, true, true)
|
||||
}
|
||||
|
||||
case 'Create UI Object': {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.createUiObjectFromNode(action.node, undefined, undefined, action.extraParameter)
|
||||
}
|
||||
break
|
||||
case 'Connect Children to Reference Parents': {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.tryToConnectChildrenWithReferenceParents()
|
||||
}
|
||||
break
|
||||
case 'Get Node By Id': {
|
||||
return UI.projects.foundations.functionLibraries.uiObjectsFromNodes.getNodeById(action.relatedNodeId)
|
||||
}
|
||||
|
||||
case 'Syncronize Tasks': {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.syncronizeTasksFoundAtWorkspaceWithBackEnd()
|
||||
}
|
||||
break
|
||||
case 'Syncronize Trading Sessions': {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd()
|
||||
}
|
||||
break
|
||||
case 'Syncronize Learning Sessions': {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd()
|
||||
}
|
||||
break
|
||||
case 'Play Tutorials': {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.playTutorials()
|
||||
}
|
||||
break
|
||||
case 'Recreate Workspace': {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.recreateWorkspace(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Delete Workspace': {
|
||||
return UI.projects.foundations.functionLibraries.nodeDeleter.deleteWorkspace(action.node, action.rootNodes, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Copy Node Path':
|
||||
{
|
||||
let nodePath = UI.projects.foundations.functionLibraries.nodePath.getNodePath(action.node)
|
||||
|
||||
UI.projects.foundations.utilities.clipboard.copyTextToClipboard(nodePath)
|
||||
|
||||
UI.projects.foundations.spaces.cockpitSpace.setStatus(
|
||||
nodePath + ' copied to the Clipboard.'
|
||||
, 50, UI.projects.foundations.spaces.cockpitSpace.statusTypes.ALL_GOOD)
|
||||
}
|
||||
break
|
||||
case 'Copy Node Value':
|
||||
{
|
||||
let value = action.node.payload.uiObject.getValue()
|
||||
|
||||
UI.projects.foundations.utilities.clipboard.copyTextToClipboard(value)
|
||||
|
||||
UI.projects.foundations.spaces.cockpitSpace.setStatus(
|
||||
value + ' copied to the Clipboard.'
|
||||
, 50, UI.projects.foundations.spaces.cockpitSpace.statusTypes.ALL_GOOD)
|
||||
}
|
||||
break
|
||||
case 'Copy Node Type':
|
||||
{
|
||||
let value = action.node.type
|
||||
|
||||
UI.projects.foundations.utilities.clipboard.copyTextToClipboard(value)
|
||||
|
||||
UI.projects.foundations.spaces.cockpitSpace.setStatus(
|
||||
value + ' copied to the Clipboard.'
|
||||
, 50, UI.projects.foundations.spaces.cockpitSpace.statusTypes.ALL_GOOD)
|
||||
}
|
||||
break
|
||||
case 'Add UI Object':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(action.node, action.relatedNodeType, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Children':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addMissingChildren(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Delete UI Object':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Edit Code':
|
||||
|
||||
break
|
||||
case 'Share':
|
||||
{
|
||||
let text = JSON.stringify(UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(action.node, true, false, true, true, true))
|
||||
|
||||
let nodeName = action.node.name
|
||||
if (nodeName === undefined) {
|
||||
nodeName = ''
|
||||
} else {
|
||||
nodeName = '.' + nodeName
|
||||
}
|
||||
let fileName = 'Share - ' + action.node.type + ' - ' + nodeName + '.json'
|
||||
UI.projects.foundations.utilities.download.downloadText(fileName, text)
|
||||
}
|
||||
|
||||
break
|
||||
case 'Backup':
|
||||
{
|
||||
let text = JSON.stringify(UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(action.node, false, false, true, true, true))
|
||||
|
||||
let nodeName = action.node.name
|
||||
if (nodeName === undefined) {
|
||||
nodeName = ''
|
||||
} else {
|
||||
nodeName = ' ' + nodeName
|
||||
}
|
||||
let fileName = 'Backup - ' + action.node.type + ' - ' + nodeName + '.json'
|
||||
UI.projects.foundations.utilities.download.downloadText(fileName, text)
|
||||
}
|
||||
|
||||
break
|
||||
case 'Clone':
|
||||
{
|
||||
let text = JSON.stringify(UI.projects.foundations.functionLibraries.nodeCloning.getNodeClone(action.node))
|
||||
|
||||
let nodeName = action.node.name
|
||||
if (nodeName === undefined) {
|
||||
nodeName = ''
|
||||
} else {
|
||||
nodeName = ' ' + nodeName
|
||||
}
|
||||
let fileName = 'Clone - ' + action.node.type + ' - ' + nodeName + '.json'
|
||||
UI.projects.foundations.utilities.download.downloadText(fileName, text)
|
||||
}
|
||||
|
||||
break
|
||||
case 'Debug Task':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runTask(action.node, true, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Task':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runTask(action.node, false, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Stop Task':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopTask(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run All Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Task Managers':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllTaskManagers(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Task Managers':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllTaskManagers(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Exchange Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllExchangeDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Exchange Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllExchangeDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Exchange Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllExchangeTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Exchange Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllExchangeTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Exchange Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllExchangeLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Exchange Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllExchangeLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Project Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllProjectDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Project Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllProjectDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Project Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllProjectTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Project Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllProjectTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Project Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllProjectLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Project Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllProjectLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Market Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllMarketDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Market Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllMarketDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Market Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllMarketTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Market Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllMarketTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Market Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllMarketLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Market Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllMarketLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Data Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllDataMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Data Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllDataMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Trading Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllTradingMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Trading Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllTradingMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Learning Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.runAllLearningMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Learning Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.stopAllLearningMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Project Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingProjectDataTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingExchangeDataTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Data Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingMarketDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Data Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingDataMineTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Project Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingProjectTradingTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingExchangeTradingTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Trading Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingMarketTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Trading Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingTradingMineTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Project Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingProjectLearningTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingExchangeLearningTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Learning Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingMarketLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Learning Mine Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addMissingLearningMineTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Tasks':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.addAllTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Crypto Exchanges':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.cryptoEcosystemFunctions.addMissingExchanges(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Assets':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.cryptoEcosystemFunctions.addMissingAssets(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Markets':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.cryptoEcosystemFunctions.addMissingMarkets(action.node)
|
||||
}
|
||||
break
|
||||
case 'Install Market':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.cryptoEcosystemFunctions.installMarket(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Uninstall Market':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.cryptoEcosystemFunctions.uninstallMarket(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Output Datasets':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.mineFunctions.addAllOutputDatasets(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addAllDataProducts(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Mine Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addAllDataMineProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Learning Mine Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addAllLearningMineProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Trading Mine Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addAllTradingMineProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Trading Session References':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingTradingSessionReferences(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Learning Session References':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingLearningSessionReferences(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Data Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingMarketDataProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Trading Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingMarketTradingProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Learning Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingMarketLearningProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Learning Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingExchangeLearningProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Trading Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingExchangeTradingProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Data Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingExchangeDataProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Project Learning Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingProjectLearningProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Project Trading Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingProjectTradingProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Project Data Products':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.addMissingProjectDataProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Dependencies':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.mineFunctions.addAllDataDependencies(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Mine Dependencies':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.mineFunctions.addAllDataMineDataDependencies(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Layer Panels':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.chartingSpaceFunctions.addAllLayerPanels(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Layer Polygons':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.chartingSpaceFunctions.addAllLayerPolygons(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Mine Layers':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.chartingSpaceFunctions.addAllMineLayers(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Time Machines':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.chartingSpaceFunctions.addMissingTimeMachines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Dashboards':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.chartingSpaceFunctions.addMissingDashboards(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Project Dashboards':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.chartingSpaceFunctions.addMissingProjectDashboards(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Play Tutorial':
|
||||
{
|
||||
UI.projects.education.spaces.tutorialSpace.playTutorial(action.node)
|
||||
}
|
||||
break
|
||||
case 'Play Tutorial Topic':
|
||||
{
|
||||
UI.projects.education.spaces.tutorialSpace.playTutorialTopic(action.node)
|
||||
}
|
||||
break
|
||||
case 'Play Tutorial Step':
|
||||
{
|
||||
UI.projects.education.spaces.tutorialSpace.playTutorialStep(action.node)
|
||||
}
|
||||
break
|
||||
case 'Resume Tutorial':
|
||||
{
|
||||
UI.projects.education.spaces.tutorialSpace.resumeTutorial(action.node)
|
||||
}
|
||||
break
|
||||
case 'Resume Tutorial Topic':
|
||||
{
|
||||
UI.projects.education.spaces.tutorialSpace.resumeTutorialTopic(action.node)
|
||||
}
|
||||
break
|
||||
case 'Resume Tutorial Step':
|
||||
{
|
||||
UI.projects.education.spaces.tutorialSpace.resumeTutorialStep(action.node)
|
||||
}
|
||||
break
|
||||
case 'Reset Tutorial Progress':
|
||||
{
|
||||
UI.projects.education.spaces.tutorialSpace.resetTutorialProgress(action.node)
|
||||
}
|
||||
break
|
||||
case 'Send Webhook Test Message':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.webhookFunctions.sendTestMessage(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Trading Session':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.tradingSessionFunctions.runSession(action.node, false, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Resume Trading Session':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.tradingSessionFunctions.runSession(action.node, true, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Stop Trading Session':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.tradingSessionFunctions.stopSession(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Learning Session':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.learningSessionFunctions.runSession(action.node, false, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Resume Learning Session':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.learningSessionFunctions.runSession(action.node, true, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Stop Learning Session':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.learningSessionFunctions.stopSession(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Super Action':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.superScriptsFunctions.runSuperScript(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Parent Attach': {
|
||||
UI.projects.foundations.functionLibraries.chainAttachDetach.chainAttachNode(action.node, action.relatedNode, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Reference Attach': {
|
||||
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(action.node, action.relatedNode, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Parent Detach':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.chainAttachDetach.chainDetachNode(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Reference Detach':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.attachDetach.referenceDetachNode(action.node)
|
||||
}
|
||||
break
|
||||
case 'Push Code to Javascript Code':
|
||||
{
|
||||
action.node.javascriptCode.code = action.node.code
|
||||
}
|
||||
break
|
||||
case 'Fetch Code to Javascript Code':
|
||||
{
|
||||
action.node.code = action.node.javascriptCode.code
|
||||
}
|
||||
break
|
||||
case 'Open Documentation':
|
||||
{
|
||||
let definition = getSchemaDocument(action.node)
|
||||
if (definition !== undefined) {
|
||||
UI.projects.education.spaces.docsSpace.openSpaceAreaAndNavigateTo(action.node.project, 'Node', action.node.type)
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Projects':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingProjects(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Data Mines':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingDataMines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Trading Mines':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingTradingMines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Trading Systems':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingTradingSystems(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Trading Engines':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingTradingEngines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Learning Mines':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingLearningMines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Learning Systems':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingLearningSystems(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Learning Engines':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingLearningEngines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Tutorials':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingTutorials(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin API Maps':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.pluginsFunctions.pluginMissingApiMaps(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Workspace Projects':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.workspaceFunctions.addMissingWorkspaceProjects(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Switch To Forward Testing':
|
||||
{
|
||||
action.node.type = "Forward Testing Session"
|
||||
UI.projects.foundations.spaces.floatingSpace.uiObjectConstructor.createUiObject(true, action.node.payload)
|
||||
}
|
||||
break
|
||||
case 'Switch To Live Trading':
|
||||
{
|
||||
action.node.type = "Live Trading Session"
|
||||
UI.projects.foundations.spaces.floatingSpace.uiObjectConstructor.createUiObject(true, action.node.payload)
|
||||
}
|
||||
break
|
||||
case 'Switch To Paper Trading':
|
||||
{
|
||||
action.node.type = "Paper Trading Session"
|
||||
UI.projects.foundations.spaces.floatingSpace.uiObjectConstructor.createUiObject(true, action.node.payload)
|
||||
}
|
||||
break
|
||||
case 'Switch To Backtesting':
|
||||
{
|
||||
action.node.type = "Backtesting Session"
|
||||
UI.projects.foundations.spaces.floatingSpace.uiObjectConstructor.createUiObject(true, action.node.payload)
|
||||
}
|
||||
break
|
||||
case 'Send Telegram Test Message':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.socialBotsFunctions.sendTelegramTestMessage(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Send Discord Test Message':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.socialBotsFunctions.sendDiscordTestMessage(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Send Slack Test Message':
|
||||
{
|
||||
UI.projects.foundations.functionLibraries.socialBotsFunctions.sendSlackTestMessage(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
function newFoundationsFunctionLibraryChainAttachDetach() {
|
||||
let thisObject = {
|
||||
chainDetachNode: chainDetachNode,
|
||||
chainAttachNode: chainAttachNode
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function chainDetachNode(node, rootNodes) {
|
||||
if (node.payload.parentNode === undefined) { return }
|
||||
switch (node.type) {
|
||||
case 'Phase': {
|
||||
let payload = node.payload
|
||||
for (let i = 0; i < payload.parentNode.phases.length; i++) {
|
||||
let phase = payload.parentNode.phases[i]
|
||||
if (phase.id === node.id) {
|
||||
if (i < payload.parentNode.phases.length - 1) {
|
||||
let nextPhase = payload.parentNode.phases[i + 1]
|
||||
if (i > 0) {
|
||||
let previousPhase = payload.parentNode.phases[i - 1]
|
||||
nextPhase.payload.chainParent = previousPhase
|
||||
} else {
|
||||
nextPhase.payload.chainParent = payload.parentNode
|
||||
}
|
||||
}
|
||||
payload.parentNode.phases.splice(i, 1)
|
||||
completeDetachment(node, rootNodes)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
default: {
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
/* Detach from parent */
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
let parentSchemaDocument = getSchemaDocument(node.payload.parentNode)
|
||||
if (parentSchemaDocument !== undefined) {
|
||||
if (parentSchemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < parentSchemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = parentSchemaDocument.childrenNodesProperties[i]
|
||||
if (schemaDocument.propertyNameAtParent === property.name) {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
node.payload.parentNode[property.name] = undefined
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = node.payload.parentNode[property.name]
|
||||
if (nodePropertyArray !== undefined) {
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let arrayItem = nodePropertyArray[j]
|
||||
if (arrayItem.id === node.id) {
|
||||
nodePropertyArray.splice(j, 1)
|
||||
j--
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
completeDetachment(node, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function chainAttachNode(node, attachToNode, rootNodes) {
|
||||
switch (node.type) {
|
||||
|
||||
case 'Exchange Account Key': {
|
||||
node.payload.parentNode = attachToNode
|
||||
node.payload.chainParent = attachToNode
|
||||
if (node.payload.parentNode.keys !== undefined) {
|
||||
node.payload.parentNode.keys.push(node)
|
||||
} else {
|
||||
node.payload.parentNode.key = node
|
||||
}
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Phase': {
|
||||
switch (attachToNode.type) {
|
||||
case 'Stop': {
|
||||
node.payload.parentNode = attachToNode
|
||||
if (attachToNode.phases.length > 0) {
|
||||
let phase = attachToNode.phases[attachToNode.phases.length - 1]
|
||||
node.payload.chainParent = phase
|
||||
} else {
|
||||
node.payload.chainParent = attachToNode
|
||||
}
|
||||
attachToNode.phases.push(node)
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Take Profit': {
|
||||
node.payload.parentNode = attachToNode
|
||||
if (attachToNode.phases.length > 0) {
|
||||
let phase = attachToNode.phases[attachToNode.phases.length - 1]
|
||||
node.payload.chainParent = phase
|
||||
} else {
|
||||
node.payload.chainParent = attachToNode
|
||||
}
|
||||
attachToNode.phases.push(node)
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Initial Stop': {
|
||||
if (attachToNode.phases.length >= 1) {
|
||||
return
|
||||
}
|
||||
|
||||
node.payload.parentNode = attachToNode
|
||||
if (attachToNode.phases.length > 0) {
|
||||
let phase = attachToNode.phases[attachToNode.phases.length - 1]
|
||||
node.payload.chainParent = phase
|
||||
} else {
|
||||
node.payload.chainParent = attachToNode
|
||||
}
|
||||
attachToNode.phases.push(node)
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Initial Take Profit': {
|
||||
if (attachToNode.phases.length >= 1) {
|
||||
return
|
||||
}
|
||||
node.payload.parentNode = attachToNode
|
||||
if (attachToNode.phases.length > 0) {
|
||||
let phase = attachToNode.phases[attachToNode.phases.length - 1]
|
||||
node.payload.chainParent = phase
|
||||
} else {
|
||||
node.payload.chainParent = attachToNode
|
||||
}
|
||||
attachToNode.phases.push(node)
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Phase': {
|
||||
node.payload.parentNode = attachToNode.payload.parentNode
|
||||
for (let i = 0; i < node.payload.parentNode.phases.length; i++) {
|
||||
let phase = node.payload.parentNode.phases[i]
|
||||
if (attachToNode.id === phase.id) {
|
||||
if (i === node.payload.parentNode.phases.length - 1) {
|
||||
node.payload.chainParent = attachToNode
|
||||
node.payload.parentNode.phases.push(node)
|
||||
completeAttachment(node, rootNodes)
|
||||
} else {
|
||||
node.payload.chainParent = attachToNode
|
||||
let nextPhase = node.payload.parentNode.phases[i + 1]
|
||||
nextPhase.payload.chainParent = node
|
||||
node.payload.parentNode.phases.splice(i + 1, 0, node)
|
||||
completeAttachment(node, rootNodes)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
default: {
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
node.payload.parentNode = attachToNode
|
||||
node.payload.chainParent = attachToNode
|
||||
/* Attach to new parent */
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
let parentSchemaDocument = getSchemaDocument(node.payload.parentNode)
|
||||
if (parentSchemaDocument !== undefined) {
|
||||
if (parentSchemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < parentSchemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = parentSchemaDocument.childrenNodesProperties[i]
|
||||
if (schemaDocument.propertyNameAtParent === property.name) {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
node.payload.parentNode[property.name] = node
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
if (node.payload.parentNode[property.name] === undefined) {
|
||||
node.payload.parentNode[property.name] = []
|
||||
}
|
||||
let nodePropertyArray = node.payload.parentNode[property.name]
|
||||
nodePropertyArray.push(node)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function completeDetachment(node, rootNodes) {
|
||||
node.payload.parentNode = undefined
|
||||
node.payload.chainParent = undefined
|
||||
rootNodes.push(node)
|
||||
}
|
||||
|
||||
function completeAttachment(node, rootNodes) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.id === node.id) {
|
||||
rootNodes.splice(i, 1)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,430 @@
|
||||
function newFoundationsFunctionLibraryChartingSpaceFunctions() {
|
||||
let thisObject = {
|
||||
addAllLayerPanels: addAllLayerPanels,
|
||||
addAllLayerPolygons: addAllLayerPolygons,
|
||||
addAllMineLayers: addAllMineLayers,
|
||||
addMissingDashboards: addMissingDashboards,
|
||||
addMissingProjectDashboards: addMissingProjectDashboards,
|
||||
addMissingTimeMachines: addMissingTimeMachines,
|
||||
createTimeMachine: createTimeMachine
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function addAllMineLayers(node, rootNodes) {
|
||||
|
||||
/* Validations to see if we can do this or not. */
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.uiObject === undefined) { return }
|
||||
if (node.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (node.payload.referenceParent.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
We are going to go through the referenced branch and recreate the structure
|
||||
we find there inside the layers manager. We will end up having at the end
|
||||
all layers referencing the data products inside the referenced branch.
|
||||
*/
|
||||
let mine = node.payload.referenceParent
|
||||
scanBotArray(mine.botProducts)
|
||||
|
||||
function scanBotArray(botArray) {
|
||||
for (let i = 0; i < botArray.length; i++) {
|
||||
let bot = botArray[i]
|
||||
let botLayers = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Bot Layers')
|
||||
botLayers.name = bot.name
|
||||
|
||||
UI.projects.foundations.utilities.folders.asymetricalFolderStructureCloning(
|
||||
bot,
|
||||
botLayers,
|
||||
'dataProducts',
|
||||
'dataProductFolders',
|
||||
'layerFolders',
|
||||
'Layer',
|
||||
'Layer Folder',
|
||||
undefined
|
||||
)
|
||||
/*
|
||||
There are some layers that should not exist, for example the ones related to Data Products
|
||||
that do not have a plotter module. Since our previous action created all layers no matter
|
||||
what, we need now to delete all the ones that do not have a plotter module.
|
||||
*/
|
||||
let allLayers = UI.projects.foundations.utilities.branches.nodeBranchToArray(botLayers, 'Layer')
|
||||
for (let j = 0; j < allLayers.length; j++) {
|
||||
let layer = allLayers[j]
|
||||
layer.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45
|
||||
|
||||
let plotterModule = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(layer, 'Plotter Module', undefined, true, false, false, true)
|
||||
if (plotterModule === undefined) {
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(layer, rootNodes)
|
||||
}
|
||||
}
|
||||
/*
|
||||
For each of the layers we will not create the Layer Panels and Layer Polygons.
|
||||
*/
|
||||
allLayers = UI.projects.foundations.utilities.branches.nodeBranchToArray(botLayers, 'Layer')
|
||||
for (let j = 0; j < allLayers.length; j++) {
|
||||
let layer = allLayers[j]
|
||||
let menu = layer.payload.uiObject.menu
|
||||
menu.internalClick('Add Missing Children')
|
||||
|
||||
layer.layerPanels.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
layer.layerPolygons.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
|
||||
menu = layer.layerPanels.payload.uiObject.menu
|
||||
menu.internalClick('Add All Layer Panels')
|
||||
|
||||
menu = layer.layerPolygons.payload.uiObject.menu
|
||||
menu.internalClick('Add All Layer Polygons')
|
||||
|
||||
layer.layerPanels.payload.floatingObject.collapseToggle()
|
||||
layer.layerPolygons.payload.floatingObject.collapseToggle()
|
||||
layer.payload.floatingObject.collapseToggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingTimeMachines(node, rootNodes) {
|
||||
if (node.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('This node needs to have a Reference Parent for this command tu run.')
|
||||
return
|
||||
}
|
||||
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Network') {
|
||||
let networkNode = rootNode
|
||||
scanNetworkNode(networkNode)
|
||||
}
|
||||
}
|
||||
|
||||
function scanNetworkNode(networkNode) {
|
||||
if (networkNode === undefined) { return }
|
||||
|
||||
let backtestingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Backtesting Session')
|
||||
let fordwardTestingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Forward Testing Session')
|
||||
let paperTradingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Paper Trading Session')
|
||||
let liveTradingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Live Trading Session')
|
||||
let backLearningSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Back Learning Session')
|
||||
let liveLearningSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Live Learning Session')
|
||||
|
||||
scanSessionArray(backtestingSessionsArray)
|
||||
scanSessionArray(fordwardTestingSessionsArray)
|
||||
scanSessionArray(paperTradingSessionsArray)
|
||||
scanSessionArray(liveTradingSessionsArray)
|
||||
scanSessionArray(backLearningSessionsArray)
|
||||
scanSessionArray(liveLearningSessionsArray)
|
||||
|
||||
function scanSessionArray(sessionsArray) {
|
||||
for (let i = 0; i < sessionsArray.length; i++) {
|
||||
let session = sessionsArray[i]
|
||||
let environment = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, node.payload.referenceParent.type, undefined, true, false, true, false)
|
||||
if (environment === undefined) { continue }
|
||||
if (environment.id !== node.payload.referenceParent.id) { continue }
|
||||
let market = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false)
|
||||
if (market.payload.referenceParent === undefined) { continue }
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, session, true) === true) {
|
||||
createTimeMachine(node, session, market.payload.referenceParent, networkNode, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createTimeMachine(dashboard, session, market, networkNode, rootNodes) {
|
||||
let mineProducts
|
||||
let timeMachine = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(dashboard, 'Time Machine')
|
||||
let exchange = market.payload.parentNode.payload.parentNode
|
||||
timeMachine.payload.referenceParent = session
|
||||
timeMachine.name = session.name + ' ' + session.type + ' ' + networkNode.name + ' ' + exchange.name + ' ' + market.name
|
||||
timeMachine.payload.floatingObject.collapseToggle()
|
||||
timeMachine.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
timeMachine.timeFrameScale.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
timeMachine.timeScale.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
timeMachine.rateScale.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
/*
|
||||
We will create 3 Time Line Charts for the Trading Mine Products
|
||||
*/
|
||||
mineProducts = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Trading Mine Products')
|
||||
for (let j = 0; j < mineProducts.length; j++) {
|
||||
let mineProduct = mineProducts[j]
|
||||
/*
|
||||
The mine products found so far, belongs to any session. To filter all the sessions
|
||||
that are not the one we are interested in, we do the following:
|
||||
*/
|
||||
if (mineProduct.payload.parentNode === undefined) { continue }
|
||||
if (mineProduct.payload.parentNode.payload.referenceParent.id !== session.id) { continue }
|
||||
/*
|
||||
At the current version of Superalgos, beta 6, there is only one Trading Mine,
|
||||
with only one bot, and it has so many data products that we want to put them
|
||||
in 3 different timeline charts. So we will create 3 charts, connect them,
|
||||
and delete from each one 1/3 of the layers. We do all that next:
|
||||
*/
|
||||
|
||||
for (let k = 0; k < 3; k++) {
|
||||
let timelineChart = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(timeMachine, 'Timeline Chart')
|
||||
|
||||
timelineChart.layerManager.payload.referenceParent = mineProduct
|
||||
timelineChart.payload.floatingObject.collapseToggle()
|
||||
timelineChart.layerManager.payload.floatingObject.collapseToggle()
|
||||
timelineChart.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
timelineChart.layerManager.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
|
||||
let menu = timelineChart.layerManager.payload.uiObject.menu
|
||||
menu.internalClick('Add All Mine Layers')
|
||||
menu.internalClick('Add All Mine Layers')
|
||||
|
||||
switch (k) {
|
||||
case 0: {
|
||||
timelineChart.name = 'Trading Engine'
|
||||
deleteNodeByName('Trading System')
|
||||
deleteNodeByName('Simulation Objects')
|
||||
break
|
||||
}
|
||||
case 1: {
|
||||
timelineChart.name = 'Trading System'
|
||||
deleteNodeByName('Trading Engine')
|
||||
deleteNodeByName('Simulation Objects')
|
||||
break
|
||||
}
|
||||
case 2: {
|
||||
timelineChart.name = 'Simulation Objects'
|
||||
deleteNodeByName('Trading Engine')
|
||||
deleteNodeByName('Trading System')
|
||||
break
|
||||
}
|
||||
}
|
||||
function deleteNodeByName(nodeName) {
|
||||
let nodeToDelete = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(timelineChart.layerManager, undefined, nodeName, true, true, false, false)
|
||||
if (nodeToDelete === undefined) { return }
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(nodeToDelete, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
We will create 3 Time Line Charts for the Learning Mine Products
|
||||
*/
|
||||
mineProducts = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Learning Mine Products')
|
||||
for (let j = 0; j < mineProducts.length; j++) {
|
||||
let mineProduct = mineProducts[j]
|
||||
/*
|
||||
The mine products found so far, belongs to any session. To filter all the sessions
|
||||
that are not the one we are interested in, we do the following:
|
||||
*/
|
||||
if (mineProduct.payload.parentNode === undefined) { continue }
|
||||
if (mineProduct.payload.parentNode.payload.referenceParent.id !== session.id) { continue }
|
||||
/*
|
||||
At the current version of Superalgos, beta 6, there is only one Learning Mine,
|
||||
with only one bot, and it has so many data products that we want to put them
|
||||
in 3 different timeline charts. So we will create 3 charts, connect them,
|
||||
and delete from each one 1/3 of the layers. We do all that next:
|
||||
*/
|
||||
|
||||
for (let k = 0; k < 3; k++) {
|
||||
let timelineChart = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(timeMachine, 'Timeline Chart')
|
||||
|
||||
timelineChart.layerManager.payload.referenceParent = mineProduct
|
||||
timelineChart.payload.floatingObject.collapseToggle()
|
||||
timelineChart.layerManager.payload.floatingObject.collapseToggle()
|
||||
timelineChart.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
timelineChart.layerManager.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
|
||||
let menu = timelineChart.layerManager.payload.uiObject.menu
|
||||
menu.internalClick('Add All Mine Layers')
|
||||
menu.internalClick('Add All Mine Layers')
|
||||
|
||||
switch (k) {
|
||||
case 0: {
|
||||
timelineChart.name = 'Learning Engine'
|
||||
deleteNodeByName('Learning System')
|
||||
deleteNodeByName('Simulation Objects')
|
||||
break
|
||||
}
|
||||
case 1: {
|
||||
timelineChart.name = 'Learning System'
|
||||
deleteNodeByName('Learning Engine')
|
||||
deleteNodeByName('Simulation Objects')
|
||||
break
|
||||
}
|
||||
case 2: {
|
||||
timelineChart.name = 'Simulation Objects'
|
||||
deleteNodeByName('Learning Engine')
|
||||
deleteNodeByName('Learning System')
|
||||
break
|
||||
}
|
||||
}
|
||||
function deleteNodeByName(nodeName) {
|
||||
let nodeToDelete = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(timelineChart.layerManager, undefined, nodeName, true, true, false, false)
|
||||
if (nodeToDelete === undefined) { return }
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(nodeToDelete, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
We need to create a Timeline Chart for each Data Mine Products.
|
||||
*/
|
||||
mineProducts = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Data Mine Products')
|
||||
for (let j = 0; j < mineProducts.length; j++) {
|
||||
let mineProduct = mineProducts[j]
|
||||
/*
|
||||
We need to filter out the ones that do not belong to the market where
|
||||
the session is running at.
|
||||
*/
|
||||
if (mineProduct.payload.parentNode.payload.referenceParent === undefined) { continue }
|
||||
if (mineProduct.payload.parentNode.payload.referenceParent.id !== market.id) { continue }
|
||||
|
||||
let timelineChart = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(timeMachine, 'Timeline Chart')
|
||||
/*
|
||||
The Mine Product Node might be collapesd and since its creation it never
|
||||
received the physics call, so we will do the call so that it properly
|
||||
sets its own name, which we are going to reuse here.
|
||||
*/
|
||||
mineProduct.payload.uiObject.invisiblePhysics()
|
||||
timelineChart.name = mineProduct.name + ' Data'
|
||||
timelineChart.layerManager.payload.referenceParent = mineProduct
|
||||
timelineChart.payload.floatingObject.collapseToggle()
|
||||
timelineChart.layerManager.payload.floatingObject.collapseToggle()
|
||||
timelineChart.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
timelineChart.layerManager.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
|
||||
let menu = timelineChart.layerManager.payload.uiObject.menu
|
||||
menu.internalClick('Add All Mine Layers')
|
||||
menu.internalClick('Add All Mine Layers')
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingDashboards(node, rootNodes) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Network') {
|
||||
let network = rootNode
|
||||
scanNetwork(network)
|
||||
}
|
||||
}
|
||||
|
||||
function scanNetwork(network) {
|
||||
if (network === undefined) { return }
|
||||
|
||||
for (let j = 0; j < network.networkNodes.length; j++) {
|
||||
let networkNode = network.networkNodes[j]
|
||||
scanNetworkNode(networkNode)
|
||||
}
|
||||
|
||||
function scanNetworkNode(networkNode) {
|
||||
let testingTradingTasks = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Testing Trading Tasks', node, true)
|
||||
let productionTradingTasks = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Production Trading Tasks', node, true)
|
||||
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, testingTradingTasks, true) === true) {
|
||||
let dashboard = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Dashboard')
|
||||
dashboard.payload.referenceParent = testingTradingTasks
|
||||
dashboard.name = testingTradingTasks.type + ' ' + networkNode.name
|
||||
}
|
||||
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, productionTradingTasks, true) === true) {
|
||||
let dashboard = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Dashboard')
|
||||
dashboard.payload.referenceParent = productionTradingTasks
|
||||
dashboard.name = productionTradingTasks.type + ' ' + networkNode.name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingProjectDashboards(node, rootNodes) {
|
||||
for (let k = 0; k < PROJECTS_SCHEMA.length; k++) {
|
||||
let projectDefinition = PROJECTS_SCHEMA[k]
|
||||
let project = projectDefinition.name
|
||||
|
||||
for (let j = 0; j < rootNodes.length; j++) {
|
||||
let rootNode = rootNodes[j]
|
||||
if (rootNode.type === project + ' Project') {
|
||||
let projectDefinition = rootNode.projectDefinition
|
||||
if (projectDefinition !== undefined) {
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, projectDefinition, true) === true) {
|
||||
let projectTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Project Dashboards', undefined, project)
|
||||
projectTasks.payload.referenceParent = projectDefinition
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAllLayerPanels(node) {
|
||||
if (validateReferences(node) !== true) { return }
|
||||
let layerNode = node.payload.parentNode
|
||||
|
||||
let plotterModule = layerNode.payload.referenceParent.payload.referenceParent.payload.referenceParent
|
||||
for (let i = 0; i < plotterModule.panels.length; i++) {
|
||||
let plotterPanel = plotterModule.panels[i]
|
||||
let layerPanel = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Layer Panel')
|
||||
layerPanel.payload.referenceParent = plotterPanel
|
||||
}
|
||||
}
|
||||
|
||||
function addAllLayerPolygons(node) {
|
||||
if (validateReferences(node) !== true) { return }
|
||||
let layerNode = node.payload.parentNode
|
||||
|
||||
let plotterModule = layerNode.payload.referenceParent.payload.referenceParent.payload.referenceParent
|
||||
|
||||
if (plotterModule.shapes === undefined) {
|
||||
node.payload.uiObject.setWarningMessage('Referenced Plotter Module does not have a Shapes child.')
|
||||
return
|
||||
}
|
||||
|
||||
for (let i = 0; i < plotterModule.shapes.polygons.length; i++) {
|
||||
let polygon = plotterModule.shapes.polygons[i]
|
||||
let layerPolygon = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Layer Polygon')
|
||||
layerPolygon.payload.referenceParent = polygon
|
||||
}
|
||||
}
|
||||
|
||||
function validateReferences(node) {
|
||||
/* Validations to see if we can do this or not. */
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.uiObject === undefined) { return }
|
||||
|
||||
if (node.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a Layer node as a parent to execute this action.')
|
||||
return
|
||||
}
|
||||
if (node.payload.parentNode.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a Layer node as a parent to execute this action.')
|
||||
return
|
||||
}
|
||||
let layerNode = node.payload.parentNode
|
||||
|
||||
if (layerNode.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('The Layer node needs to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (layerNode.payload.referenceParent.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('The Layer node needs to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (layerNode.payload.referenceParent.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('The Layer node needs to have a reference grand parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (layerNode.payload.referenceParent.payload.referenceParent.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('The Layer node needs to have a reference grand parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (layerNode.payload.referenceParent.payload.referenceParent.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('The Layer node to have a reference grand grand parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (layerNode.payload.referenceParent.payload.referenceParent.payload.referenceParent.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('The Layer node to have a reference grand grand parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,738 @@
|
||||
function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
|
||||
let thisObject = {
|
||||
addMissingExchanges: addMissingExchanges,
|
||||
addMissingAssets: addMissingAssets,
|
||||
addMissingMarkets: addMissingMarkets,
|
||||
installMarket: installMarket,
|
||||
uninstallMarket: uninstallMarket
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function addMissingExchanges(node) {
|
||||
currentExchanges = new Map()
|
||||
let parent = node.payload.parentNode
|
||||
if (parent !== undefined) {
|
||||
for (let i = 0; i < parent.cryptoExchanges.length; i++) {
|
||||
let cryptoExchanges = parent.cryptoExchanges[i]
|
||||
for (let j = 0; j < cryptoExchanges.exchanges.length; j++) {
|
||||
let exchange = cryptoExchanges.exchanges[j]
|
||||
let codeName = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(exchange.payload, 'codeName')
|
||||
currentExchanges.set(codeName, exchange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let params = {
|
||||
method: 'listExchanges',
|
||||
has: {
|
||||
fetchOHLCV: true,
|
||||
fetchMarkets: true
|
||||
}
|
||||
}
|
||||
|
||||
httpRequest(JSON.stringify(params), 'CCXT', onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange')
|
||||
return
|
||||
}
|
||||
|
||||
let exchanges = JSON.parse(data)
|
||||
for (let i = 0; i < exchanges.length; i++) {
|
||||
let exchange = exchanges[i]
|
||||
let existingExchange = currentExchanges.get(exchange.id)
|
||||
if (existingExchange === undefined) {
|
||||
let newExchange = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Crypto Exchange')
|
||||
newExchange.name = exchange.name
|
||||
newExchange.config = '{ \n\"codeName\": \"' + exchange.id + '\"\n}'
|
||||
newExchange.payload.floatingObject.collapseToggle()
|
||||
newExchange.exchangeAssets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
newExchange.exchangeMarkets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
newExchange.exchangeAccounts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
newExchange.exchangeAssets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_050X
|
||||
newExchange.exchangeMarkets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X
|
||||
newExchange.exchangeAccounts.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_025X
|
||||
newExchange.exchangeAssets.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE
|
||||
newExchange.exchangeMarkets.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE
|
||||
newExchange.exchangeAccounts.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingAssets(node) {
|
||||
if (node.payload.parentNode === undefined) { return }
|
||||
|
||||
let currentAssets = new Map()
|
||||
for (let j = 0; j < node.assets.length; j++) {
|
||||
let asset = node.assets[j]
|
||||
let codeName = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(asset.payload, 'codeName')
|
||||
currentAssets.set(codeName, asset)
|
||||
}
|
||||
|
||||
let exchangeId = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload.parentNode.payload, 'codeName')
|
||||
|
||||
try {
|
||||
let params = {
|
||||
exchangeId: exchangeId,
|
||||
method: 'fetchMarkets'
|
||||
}
|
||||
httpRequest(JSON.stringify(params), 'CCXT', onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange')
|
||||
return
|
||||
}
|
||||
let queryParams = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'addMissingAssetsFilter')
|
||||
|
||||
let markets = JSON.parse(data)
|
||||
|
||||
let totalAdded = 0
|
||||
for (let i = 0; i < markets.length; i++) {
|
||||
let market = markets[i]
|
||||
|
||||
if (queryParams !== undefined) {
|
||||
if (queryParams.baseAsset !== undefined) {
|
||||
if (market.base.indexOf(queryParams.baseAsset) < 0) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (queryParams.quotedAsset !== undefined) {
|
||||
if (market.quote.indexOf(queryParams.quotedAsset) < 0) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentAssets.get(market.base) === undefined) {
|
||||
addAsset(market.base)
|
||||
totalAdded++
|
||||
currentAssets.set(market.base, market.base)
|
||||
}
|
||||
if (currentAssets.get(market.quote) === undefined) {
|
||||
addAsset(market.quote)
|
||||
totalAdded++
|
||||
currentAssets.set(market.quote, market.quote)
|
||||
}
|
||||
|
||||
function addAsset(name) {
|
||||
let newAsseet = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Asset')
|
||||
newAsseet.name = name
|
||||
newAsseet.config = '{ \n\"codeName\": \"' + name + '\"\n}'
|
||||
}
|
||||
}
|
||||
node.payload.uiObject.setInfoMessage(node.payload.parentNode.name + ' supports ' + markets.length + ' markets. Applying the filters at this node config ' + node.config + ' this process added ' + totalAdded + ' assets.', 4)
|
||||
|
||||
}
|
||||
} catch (err) {
|
||||
node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange')
|
||||
console.log(err.stack)
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingMarkets(node) {
|
||||
if (node.payload.parentNode === undefined) { return }
|
||||
if (node.payload.parentNode.exchangeAssets === undefined) { return }
|
||||
if (node.payload.parentNode.payload.parentNode === undefined) { return }
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { return }
|
||||
|
||||
let currentAssets = new Map()
|
||||
let exchangeAssets = node.payload.parentNode.exchangeAssets
|
||||
for (let j = 0; j < exchangeAssets.assets.length; j++) {
|
||||
let asset = exchangeAssets.assets[j]
|
||||
let codeName = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(asset.payload, 'codeName')
|
||||
currentAssets.set(codeName, asset)
|
||||
}
|
||||
|
||||
let currentMarkets = new Map()
|
||||
let exchangeMarkets = node
|
||||
for (let j = 0; j < exchangeMarkets.markets.length; j++) {
|
||||
let asset = exchangeMarkets.markets[j]
|
||||
let codeName = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(asset.payload, 'codeName')
|
||||
currentMarkets.set(codeName, asset)
|
||||
}
|
||||
|
||||
let exchangeId = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload.parentNode.payload, 'codeName')
|
||||
|
||||
try {
|
||||
let params = {
|
||||
exchangeId: exchangeId,
|
||||
method: 'fetchMarkets'
|
||||
}
|
||||
httpRequest(JSON.stringify(params), 'CCXT', onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange')
|
||||
return
|
||||
}
|
||||
|
||||
let markets = JSON.parse(data)
|
||||
for (let i = 0; i < markets.length; i++) {
|
||||
let market = markets[i]
|
||||
let baseAsset = currentAssets.get(market.base)
|
||||
let quotedAsset = currentAssets.get(market.quote)
|
||||
|
||||
if (baseAsset === undefined) {
|
||||
continue
|
||||
}
|
||||
if (quotedAsset === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (currentMarkets.get(market.symbol) === undefined) {
|
||||
addMarket(market.symbol, baseAsset, quotedAsset)
|
||||
}
|
||||
|
||||
function addMarket(name, baseAsset, quotedAsset) {
|
||||
let newMarket = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Market')
|
||||
newMarket.name = name
|
||||
newMarket.config = '{ \n\"codeName\": \"' + name + '\"\n}'
|
||||
newMarket.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
newMarket.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X
|
||||
newMarket.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE
|
||||
newMarket.baseAsset.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45
|
||||
newMarket.quotedAsset.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45
|
||||
newMarket.baseAsset.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X
|
||||
newMarket.quotedAsset.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X
|
||||
newMarket.baseAsset.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE
|
||||
newMarket.quotedAsset.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE
|
||||
newMarket.baseAsset.payload.referenceParent = baseAsset
|
||||
newMarket.quotedAsset.payload.referenceParent = quotedAsset
|
||||
|
||||
currentMarkets.set(name, newMarket)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange')
|
||||
console.log(err.stack)
|
||||
}
|
||||
}
|
||||
|
||||
function installMarket(
|
||||
node,
|
||||
rootNodes
|
||||
) {
|
||||
|
||||
let market = node
|
||||
let cryptoExchange = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(node, 'Crypto Exchange', undefined, true, false, true, false)
|
||||
if (cryptoExchange === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Market must be a descendant of a Crypto Exchange')
|
||||
return
|
||||
}
|
||||
node.payload.uiObject.setInfoMessage('This market is being installed. This might take a minute or two. Please hold on while we connect all the dots for you. ')
|
||||
|
||||
setTimeout(installMarketProcedure, 500)
|
||||
|
||||
function installMarketProcedure() {
|
||||
let dashboardsArray = []
|
||||
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Network') {
|
||||
installInNetwork(rootNode)
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Charting Space') {
|
||||
installInChartingSpace(rootNode)
|
||||
}
|
||||
}
|
||||
|
||||
node.payload.uiObject.setInfoMessage('Market installation is complete.')
|
||||
|
||||
function installInNetwork(network) {
|
||||
|
||||
for (let j = 0; j < network.networkNodes.length; j++) {
|
||||
let networkNode = network.networkNodes[j]
|
||||
installInNetworkNode(networkNode)
|
||||
}
|
||||
|
||||
function installInNetworkNode(networkNode) {
|
||||
|
||||
let tradingSessionsCreatedArray = []
|
||||
let learningSessionsCreatedArray = []
|
||||
|
||||
installDataTasksTasks()
|
||||
installLearningTasksTasks()
|
||||
isntallTradingTasksTasks()
|
||||
|
||||
installDataMinesData()
|
||||
installLearningMinesData()
|
||||
installTradingMineData()
|
||||
|
||||
function installDataTasksTasks() {
|
||||
/*
|
||||
Here we complete the missing stuff at Data Tasks
|
||||
*/
|
||||
let dataTasks = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Data Tasks', node, true)
|
||||
if (dataTasks === undefined) {
|
||||
dataTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(networkNode, 'Data Tasks')
|
||||
}
|
||||
/*
|
||||
We will make ourserves sure that the Project Data Tasks nodes are there.
|
||||
*/
|
||||
dataTasks.payload.uiObject.menu.internalClick('Add Missing Project Data Tasks')
|
||||
dataTasks.payload.uiObject.menu.internalClick('Add Missing Project Data Tasks')
|
||||
|
||||
for (let i = 0; i < dataTasks.projectDataTasks.length; i++) {
|
||||
let projectDataTasks = dataTasks.projectDataTasks[i]
|
||||
projectDataTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
|
||||
if (projectDataTasks.project === "Foundations") {
|
||||
installTheRestOfTheBranch(projectDataTasks)
|
||||
}
|
||||
}
|
||||
|
||||
function installTheRestOfTheBranch(projectDataTasks) {
|
||||
let exchangeDataTasks = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectDataTasks, 'Exchange Data Tasks', cryptoExchange)
|
||||
exchangeDataTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketDataTask = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeDataTasks, 'Market Data Tasks', market, rootNodes)
|
||||
|
||||
UI.projects.foundations.utilities.menu.menuClick(marketDataTask, 'Add Missing Data Mine Tasks', true)
|
||||
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(marketDataTask.dataMineTasks, 'Add All Tasks', true)
|
||||
}
|
||||
}
|
||||
|
||||
function installLearningTasksTasks() {
|
||||
/*
|
||||
Here we complete the missing stuff at Learning Tasks
|
||||
*/
|
||||
let learningTasks = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Learning Tasks', node, true)
|
||||
if (learningTasks === undefined) {
|
||||
learningTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(networkNode, 'Learning Tasks')
|
||||
}
|
||||
/*
|
||||
We will make ourserves sure that the Project Learning Tasks nodes are there.
|
||||
*/
|
||||
learningTasks.payload.uiObject.menu.internalClick('Add Missing Project Learning Tasks')
|
||||
learningTasks.payload.uiObject.menu.internalClick('Add Missing Project Learning Tasks')
|
||||
|
||||
for (let i = 0; i < learningTasks.projectLearningTasks.length; i++) {
|
||||
let projectLearningTasks = learningTasks.projectLearningTasks[i]
|
||||
projectLearningTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
|
||||
if (projectLearningTasks.project === "Foundations") {
|
||||
installTheRestOfTheBranch(projectLearningTasks)
|
||||
}
|
||||
}
|
||||
|
||||
function installTheRestOfTheBranch(projectLearningTasks) {
|
||||
let exchangeLearningTasks = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectLearningTasks, 'Exchange Learning Tasks', cryptoExchange)
|
||||
exchangeLearningTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketLearningTask = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeLearningTasks, 'Market Learning Tasks', market, rootNodes)
|
||||
|
||||
UI.projects.foundations.utilities.menu.menuClick(marketLearningTask, 'Add Missing Learning Mine Tasks', true)
|
||||
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(marketLearningTask.learningMineTasks, 'Add All Tasks', true)
|
||||
|
||||
/* This will be needed at the charting space, for creating Dashboards */
|
||||
let backLearningSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(marketLearningTask, 'Back Learning Session')
|
||||
let liveLearningSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(marketLearningTask, 'Live Learning Session')
|
||||
|
||||
let allSessionsArray = backLearningSessionsArray
|
||||
.concat(liveLearningSessionsArray)
|
||||
|
||||
learningSessionsCreatedArray = learningSessionsCreatedArray.concat(allSessionsArray)
|
||||
|
||||
dashboardsArray.push({ environmentNode: learningTasks, networkNode: networkNode, sessionsArray: allSessionsArray })
|
||||
}
|
||||
}
|
||||
|
||||
function isntallTradingTasksTasks() {
|
||||
/*
|
||||
Next we complete the missing stuff at Testing Trading Tasks
|
||||
*/
|
||||
installEnvironment('Testing Trading Tasks')
|
||||
/*
|
||||
Next we complete the missing stuff at Production Trading Tasks
|
||||
*/
|
||||
installEnvironment('Production Trading Tasks')
|
||||
|
||||
function installEnvironment(environmentType) {
|
||||
/*
|
||||
Now we install the environmnet at the current Network Node
|
||||
*/
|
||||
let tradingTasks = UI.projects.foundations.utilities.branches.findInBranch(networkNode, environmentType, node, true)
|
||||
if (tradingTasks === undefined) {
|
||||
tradingTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(networkNode, environmentType)
|
||||
}
|
||||
/*
|
||||
We will make ourserves sure that the Project Trading Tasks nodes are there.
|
||||
*/
|
||||
tradingTasks.payload.uiObject.menu.internalClick('Add Missing Project Trading Tasks')
|
||||
tradingTasks.payload.uiObject.menu.internalClick('Add Missing Project Trading Tasks')
|
||||
|
||||
for (let i = 0; i < tradingTasks.projectTradingTasks.length; i++) {
|
||||
let projectTradingTasks = tradingTasks.projectTradingTasks[i]
|
||||
projectTradingTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
|
||||
if (projectTradingTasks.project === "Foundations") {
|
||||
installTheRestOfTheBranch(projectTradingTasks)
|
||||
}
|
||||
}
|
||||
|
||||
function installTheRestOfTheBranch(projectTradingTasks) {
|
||||
let exchangeTradingTasks = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectTradingTasks, 'Exchange Trading Tasks', cryptoExchange)
|
||||
exchangeTradingTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketTradingTask = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeTradingTasks, 'Market Trading Tasks', market, rootNodes)
|
||||
|
||||
UI.projects.foundations.utilities.menu.menuClick(marketTradingTask, 'Add Missing Trading Mine Tasks', true)
|
||||
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(marketTradingTask.tradingMineTasks, 'Add All Tasks', true)
|
||||
|
||||
/* This will be needed at the charting space, for creating Dashboards */
|
||||
let backtestingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(marketTradingTask, 'Backtesting Session')
|
||||
let liveTradingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(marketTradingTask, 'Live Trading Session')
|
||||
let paperTradingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(marketTradingTask, 'Paper Trading Session')
|
||||
let forwardSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(marketTradingTask, 'Forward Testing Session')
|
||||
let allSessionsArray = backtestingSessionsArray
|
||||
.concat(liveTradingSessionsArray)
|
||||
.concat(paperTradingSessionsArray)
|
||||
.concat(forwardSessionsArray)
|
||||
tradingSessionsCreatedArray = tradingSessionsCreatedArray.concat(allSessionsArray)
|
||||
|
||||
dashboardsArray.push({ environmentNode: tradingTasks, networkNode: networkNode, sessionsArray: allSessionsArray })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function installDataMinesData() {
|
||||
/*
|
||||
Here we complete the missing stuff at Data Mines Data
|
||||
*/
|
||||
let dataStorage = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Data Storage', node, true)
|
||||
if (dataStorage === undefined) {
|
||||
dataStorage = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(networkNode, 'Data Storage')
|
||||
}
|
||||
let dataMinesData = UI.projects.foundations.utilities.branches.findInBranch(dataStorage, 'Data Mines Data', node, true)
|
||||
if (dataMinesData === undefined) {
|
||||
dataMinesData = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(dataStorage, 'Data Mines Data')
|
||||
}
|
||||
dataMinesData.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
/*
|
||||
We will make ourserves sure that the Project Data Products nodes are there.
|
||||
*/
|
||||
dataMinesData.payload.uiObject.menu.internalClick('Add Missing Project Data Products')
|
||||
dataMinesData.payload.uiObject.menu.internalClick('Add Missing Project Data Products')
|
||||
|
||||
for (let i = 0; i < dataMinesData.projectDataProducts.length; i++) {
|
||||
let projectDataProducts = dataMinesData.projectDataProducts[i]
|
||||
projectDataProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45
|
||||
|
||||
if (projectDataProducts.project === "Foundations") {
|
||||
installTheRestOfTheBranch(projectDataProducts)
|
||||
}
|
||||
}
|
||||
|
||||
function installTheRestOfTheBranch(projectDataProducts) {
|
||||
let exchangeDataProducts = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectDataProducts, 'Exchange Data Products', cryptoExchange)
|
||||
exchangeDataProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketDataProducts = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeDataProducts, 'Market Data Products', market, rootNodes)
|
||||
marketDataProducts.payload.floatingObject.collapseToggle()
|
||||
|
||||
UI.projects.foundations.utilities.menu.menuClick(marketDataProducts, 'Add All Data Mine Products', true)
|
||||
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(marketDataProducts.dataMineProducts, 'Add All Data Products', true)
|
||||
}
|
||||
}
|
||||
|
||||
function installLearningMinesData() {
|
||||
/*
|
||||
Here we complete the missing stuff at Data Mines Data
|
||||
*/
|
||||
let dataStorage = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Data Storage', node, true)
|
||||
if (dataStorage === undefined) {
|
||||
dataStorage = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(networkNode, 'Data Storage')
|
||||
}
|
||||
let learningMinesData = UI.projects.foundations.utilities.branches.findInBranch(dataStorage, 'Learning Mines Data', node, true)
|
||||
if (learningMinesData === undefined) {
|
||||
learningMinesData = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(dataStorage, 'Learning Mines Data')
|
||||
}
|
||||
learningMinesData.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
/*
|
||||
We will make ourserves sure that the Project Learning Products nodes are there.
|
||||
*/
|
||||
learningMinesData.payload.uiObject.menu.internalClick('Add Missing Project Learning Products')
|
||||
learningMinesData.payload.uiObject.menu.internalClick('Add Missing Project Learning Products')
|
||||
|
||||
for (let i = 0; i < learningMinesData.projectLearningProducts.length; i++) {
|
||||
let projectLearningProducts = learningMinesData.projectLearningProducts[i]
|
||||
projectLearningProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45
|
||||
|
||||
if (projectLearningProducts.project === "Foundations") {
|
||||
installTheRestOfTheBranch(projectLearningProducts)
|
||||
}
|
||||
}
|
||||
|
||||
function installTheRestOfTheBranch(projectLearningProducts) {
|
||||
|
||||
let exchangeLearningProducts = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectLearningProducts, 'Exchange Learning Products', cryptoExchange)
|
||||
exchangeLearningProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketLearningProducts = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeLearningProducts, 'Market Learning Products', market, rootNodes)
|
||||
marketLearningProducts.payload.floatingObject.collapseToggle()
|
||||
/*
|
||||
Create the new session references.
|
||||
*/
|
||||
for (let i = 0; i < learningSessionsCreatedArray.length; i++) {
|
||||
let session = learningSessionsCreatedArray[i]
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(marketLearningProducts, session, true) === true) {
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.createSessionReference(marketLearningProducts, session, 'Learning Session Reference')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Create everything inside the session references.
|
||||
*/
|
||||
for (let j = 0; j < marketLearningProducts.learningSessionReferences.length; j++) {
|
||||
let sessionReference = marketLearningProducts.learningSessionReferences[j]
|
||||
UI.projects.foundations.utilities.menu.menuClick(sessionReference, 'Add All Learning Mine Products', true)
|
||||
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(sessionReference.learningMineProducts, 'Add All Data Products', true)
|
||||
sessionReference.payload.floatingObject.collapseToggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function installTradingMineData() {
|
||||
/*
|
||||
Here we complete the missing stuff at Data Mines Data
|
||||
*/
|
||||
let dataStorage = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Data Storage', node, true)
|
||||
if (dataStorage === undefined) {
|
||||
dataStorage = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(networkNode, 'Data Storage')
|
||||
}
|
||||
let tradingMinesData = UI.projects.foundations.utilities.branches.findInBranch(dataStorage, 'Trading Mines Data', node, true)
|
||||
if (tradingMinesData === undefined) {
|
||||
tradingMinesData = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(dataStorage, 'Trading Mines Data')
|
||||
}
|
||||
tradingMinesData.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
/*
|
||||
We will make ourserves sure that the Project Trading Products nodes are there.
|
||||
*/
|
||||
tradingMinesData.payload.uiObject.menu.internalClick('Add Missing Project Trading Products')
|
||||
tradingMinesData.payload.uiObject.menu.internalClick('Add Missing Project Trading Products')
|
||||
|
||||
for (let i = 0; i < tradingMinesData.projectTradingProducts.length; i++) {
|
||||
let projectTradingProducts = tradingMinesData.projectTradingProducts[i]
|
||||
projectTradingProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45
|
||||
|
||||
if (projectTradingProducts.project === "Foundations") {
|
||||
installTheRestOfTheBranch(projectTradingProducts)
|
||||
}
|
||||
}
|
||||
|
||||
function installTheRestOfTheBranch(projectTradingProducts) {
|
||||
|
||||
let exchangeTradingProducts = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectTradingProducts, 'Exchange Trading Products', cryptoExchange)
|
||||
exchangeTradingProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketTradingProducts = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeTradingProducts, 'Market Trading Products', market, rootNodes)
|
||||
marketTradingProducts.payload.floatingObject.collapseToggle()
|
||||
/*
|
||||
Create the new session references.
|
||||
*/
|
||||
for (let i = 0; i < tradingSessionsCreatedArray.length; i++) {
|
||||
let session = tradingSessionsCreatedArray[i]
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(marketTradingProducts, session, true) === true) {
|
||||
UI.projects.foundations.functionLibraries.dataStorageFunctions.createSessionReference(marketTradingProducts, session, 'Trading Session Reference')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Create everything inside the session references.
|
||||
*/
|
||||
for (let j = 0; j < marketTradingProducts.tradingSessionReferences.length; j++) {
|
||||
let sessionReference = marketTradingProducts.tradingSessionReferences[j]
|
||||
UI.projects.foundations.utilities.menu.menuClick(sessionReference, 'Add All Trading Mine Products', true)
|
||||
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(sessionReference.tradingMineProducts, 'Add All Data Products', true)
|
||||
sessionReference.payload.floatingObject.collapseToggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function installInChartingSpace(chartingSpace) {
|
||||
/*
|
||||
We will make ourserves sure that the Project Data Tasks nodes are there.
|
||||
*/
|
||||
chartingSpace.payload.uiObject.menu.internalClick('Add Missing Project Dashboards')
|
||||
chartingSpace.payload.uiObject.menu.internalClick('Add Missing Project Dashboards')
|
||||
|
||||
for (let i = 0; i < chartingSpace.projectDashboards.length; i++) {
|
||||
let projectDashboards = chartingSpace.projectDashboards[i]
|
||||
projectDashboards.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
|
||||
if (projectDashboards.project === "Foundations") {
|
||||
installTheRestOfTheBranch(projectDashboards)
|
||||
}
|
||||
}
|
||||
|
||||
function installTheRestOfTheBranch(projectDashboards) {
|
||||
|
||||
for (let i = 0; i < dashboardsArray.length; i++) {
|
||||
/*
|
||||
If the Dashboard we need is not already there we create a new one.
|
||||
*/
|
||||
let arrayItem = dashboardsArray[i]
|
||||
let dashboard = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectDashboards, 'Dashboard', arrayItem.environmentNode)
|
||||
dashboard.name = arrayItem.environmentNode.type + ' ' + arrayItem.networkNode.name
|
||||
/*
|
||||
We delete all the existing Time Machines related to the market we are currently installing.
|
||||
For that, we make a new array with the existing Time Machines so that the deleting
|
||||
of each node does not affect the proccessing of the whole set.
|
||||
*/
|
||||
let timeMachines = []
|
||||
for (let i = 0; i < dashboard.timeMachines.length; i++) {
|
||||
let timeMachine = dashboard.timeMachines[i]
|
||||
timeMachines.push(timeMachine)
|
||||
}
|
||||
for (let i = 0; i < timeMachines.length; i++) {
|
||||
let timeMachine = timeMachines[i]
|
||||
let session = timeMachine.payload.referenceParent
|
||||
if (session === undefined || session.cleaned === true) {
|
||||
/*
|
||||
This is what usually happens, that the intall process make these
|
||||
time machines to lose their reference parent since the install
|
||||
process deletes them.
|
||||
*/
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(timeMachine, rootNodes)
|
||||
continue
|
||||
}
|
||||
let marketTradingTasks = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false)
|
||||
if (marketTradingTasks === undefined) { continue }
|
||||
if (marketTradingTasks.payload === undefined) { continue }
|
||||
if (marketTradingTasks.payload.referenceParent === undefined) { continue }
|
||||
if (marketTradingTasks.payload.referenceParent.id === market.id) {
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(timeMachine, rootNodes)
|
||||
}
|
||||
}
|
||||
/*
|
||||
We create a time machine for each session added during the previous processing.
|
||||
*/
|
||||
for (let j = 0; j < arrayItem.sessionsArray.length; j++) {
|
||||
let session = arrayItem.sessionsArray[j]
|
||||
UI.projects.foundations.functionLibraries.chartingSpaceFunctions.createTimeMachine(dashboard, session, node, arrayItem.networkNode, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function uninstallMarket(node, rootNodes) {
|
||||
|
||||
node.payload.uiObject.setInfoMessage('This market is being uninstalled. Please hold on that it might take a while.')
|
||||
|
||||
setTimeout(uninstallMarketProcedure, 500)
|
||||
|
||||
function uninstallMarketProcedure() {
|
||||
let market = node
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Charting Space') {
|
||||
uninstallInChartingSpace(rootNode)
|
||||
}
|
||||
}
|
||||
|
||||
node.payload.uiObject.setInfoMessage('Market uninstall is complete.')
|
||||
|
||||
function uninstallInChartingSpace(chartingSpace) {
|
||||
|
||||
/* Delete all time machines which are referencing sessions inside the market being unistalled. */
|
||||
let timeMachines = UI.projects.foundations.utilities.branches.nodeBranchToArray(chartingSpace, 'Time Machine')
|
||||
for (let i = 0; i < timeMachines.length; i++) {
|
||||
let timeMachine = timeMachines[i]
|
||||
let session = timeMachine.payload.referenceParent
|
||||
if (session === undefined) { continue }
|
||||
let marketTradingTasks = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false)
|
||||
if (marketTradingTasks === undefined) { continue }
|
||||
if (marketTradingTasks.payload === undefined) { continue }
|
||||
if (marketTradingTasks.payload.referenceParent === undefined) { continue }
|
||||
if (marketTradingTasks.payload.referenceParent.id === market.id) {
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(timeMachine, rootNodes)
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete all Dashboards that does not have time machines inside. */
|
||||
let dashboardArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(chartingSpace, 'Dashboard')
|
||||
for (let i = 0; i < dashboardArray.length; i++) {
|
||||
let dashboard = dashboardArray[i]
|
||||
if (dashboard.timeMachines.length === 0) {
|
||||
/*
|
||||
If possible, after we delete the dashboards, we will also
|
||||
delete the project reference.
|
||||
*/
|
||||
let projectReference = dashboard.payload.parentNode
|
||||
schemaDocument = getSchemaDocument(dashboard)
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(dashboard, rootNodes)
|
||||
if (projectReference !== undefined && schemaDocument.propertyNameAtParent !== undefined) {
|
||||
if (projectReference[schemaDocument.propertyNameAtParent] !== undefined) {
|
||||
if (projectReference[schemaDocument.propertyNameAtParent].length === 0) {
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(projectReference, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan Networks for the market being unistalled to delete it. */
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Network') {
|
||||
uninstallInNetwork(rootNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function uninstallInNetwork(network) {
|
||||
|
||||
let marketDataTasksArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(network, 'Market Data Tasks')
|
||||
let marketTradingTasksArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(network, 'Market Trading Tasks')
|
||||
let marketLearningTasksArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(network, 'Market Learning Tasks')
|
||||
let marketDataProductsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(network, 'Market Data Products')
|
||||
let marketTradingProductsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(network, 'Market Trading Products')
|
||||
let marketLearningProductsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(network, 'Market Learning Products')
|
||||
|
||||
uninstalMarketArray(marketDataTasksArray)
|
||||
uninstalMarketArray(marketTradingTasksArray)
|
||||
uninstalMarketArray(marketLearningTasksArray)
|
||||
uninstalMarketArray(marketDataProductsArray)
|
||||
uninstalMarketArray(marketTradingProductsArray)
|
||||
uninstalMarketArray(marketLearningProductsArray)
|
||||
|
||||
function uninstalMarketArray(marketArray) {
|
||||
for (let i = 0; i < marketArray.length; i++) {
|
||||
let marketReference = marketArray[i]
|
||||
if (marketReference.payload === undefined) { continue }
|
||||
if (marketReference.payload.referenceParent === undefined) { continue }
|
||||
if (marketReference.payload.referenceParent.id === market.id) {
|
||||
/*
|
||||
If possible, after we delete the market reference, we will also
|
||||
delete the exchange reference.
|
||||
*/
|
||||
let exchangeReference = marketReference.payload.parentNode
|
||||
let schemaDocument = getSchemaDocument(marketReference)
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(marketReference, rootNodes)
|
||||
if (exchangeReference !== undefined && schemaDocument.propertyNameAtParent !== undefined) {
|
||||
if (exchangeReference[schemaDocument.propertyNameAtParent].length === 0) {
|
||||
/*
|
||||
If possible, after we delete the exchange reference, we will also
|
||||
delete the project reference.
|
||||
*/
|
||||
let projectReference = exchangeReference.payload.parentNode
|
||||
schemaDocument = getSchemaDocument(exchangeReference)
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(exchangeReference, rootNodes)
|
||||
if (projectReference !== undefined && schemaDocument.propertyNameAtParent !== undefined) {
|
||||
if (projectReference[schemaDocument.propertyNameAtParent].length === 0) {
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(projectReference, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
function newFoundationsFunctionLibraryDataStorageFunctions() {
|
||||
let thisObject = {
|
||||
addAllDataProducts: addAllDataProducts,
|
||||
addAllDataMineProducts: addAllDataMineProducts,
|
||||
addAllTradingMineProducts: addAllTradingMineProducts,
|
||||
addAllLearningMineProducts: addAllLearningMineProducts,
|
||||
addMissingTradingSessionReferences: addMissingTradingSessionReferences,
|
||||
addMissingLearningSessionReferences: addMissingLearningSessionReferences,
|
||||
addMissingMarketDataProducts: addMissingMarketDataProducts,
|
||||
addMissingMarketTradingProducts: addMissingMarketTradingProducts,
|
||||
addMissingMarketLearningProducts: addMissingMarketLearningProducts,
|
||||
addMissingExchangeDataProducts: addMissingExchangeDataProducts,
|
||||
addMissingExchangeTradingProducts: addMissingExchangeTradingProducts,
|
||||
addMissingExchangeLearningProducts: addMissingExchangeLearningProducts,
|
||||
addMissingProjectDataProducts: addMissingProjectDataProducts,
|
||||
addMissingProjectTradingProducts: addMissingProjectTradingProducts,
|
||||
addMissingProjectLearningProducts: addMissingProjectLearningProducts,
|
||||
createSessionReference: createSessionReference
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function addAllDataProducts(node) {
|
||||
|
||||
/* Validations to see if we can do this or not. */
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.uiObject === undefined) { return }
|
||||
if (node.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (node.payload.referenceParent.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Next, we are going to scan through all the bots of the Data Mine referenced, and for each bot we will
|
||||
create a Bots Products node. Later we will scan all the Products Definitions of each bot, and for each one
|
||||
we will create a Data Product. In case we find Product Definition Folders, we will recreate that structure
|
||||
too, using in this case Data Product Folders.
|
||||
*/
|
||||
let mine = node.payload.referenceParent
|
||||
scanBotArray(mine.sensorBots)
|
||||
scanBotArray(mine.apiDataFetcherBots)
|
||||
scanBotArray(mine.indicatorBots)
|
||||
scanBotArray(mine.tradingBots)
|
||||
scanBotArray(mine.learningBots)
|
||||
|
||||
function scanBotArray(botArray) {
|
||||
if (botArray === undefined) { return }
|
||||
|
||||
for (let i = 0; i < botArray.length; i++) {
|
||||
let bot = botArray[i]
|
||||
let botProducts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Bot Products')
|
||||
botProducts.name = bot.name
|
||||
botProducts.payload.floatingObject.collapseToggle()
|
||||
|
||||
UI.projects.foundations.utilities.folders.asymetricalFolderStructureCloning(
|
||||
bot,
|
||||
botProducts,
|
||||
'products',
|
||||
'productDefinitionFolders',
|
||||
'dataProductFolders',
|
||||
'Data Product',
|
||||
'Data Product Folder',
|
||||
undefined
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAllDataMineProducts(node, rootNodes) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
|
||||
if (rootNode.type === 'Data Mine') {
|
||||
let dataMineProducts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Data Mine Products')
|
||||
dataMineProducts.payload.referenceParent = rootNode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAllTradingMineProducts(node, rootNodes) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
|
||||
if (rootNode.type === 'Trading Mine') {
|
||||
let tradingMineProducts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Trading Mine Products')
|
||||
tradingMineProducts.payload.referenceParent = rootNode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAllLearningMineProducts(node, rootNodes) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
|
||||
if (rootNode.type === 'Learning Mine') {
|
||||
let learningMineProducts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Learning Mine Products')
|
||||
learningMineProducts.payload.referenceParent = rootNode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingTradingSessionReferences(node, rootNodes) {
|
||||
let networkNode = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(node, 'Network Node', undefined, true, false, true, false)
|
||||
if (networkNode === undefined) { return }
|
||||
|
||||
let backtestingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Backtesting Session')
|
||||
let fordwardTestingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Forward Testing Session')
|
||||
let paperTradingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Paper Trading Session')
|
||||
let liveTradingSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Live Trading Session')
|
||||
|
||||
addMissingSession(backtestingSessionsArray)
|
||||
addMissingSession(fordwardTestingSessionsArray)
|
||||
addMissingSession(paperTradingSessionsArray)
|
||||
addMissingSession(liveTradingSessionsArray)
|
||||
|
||||
function addMissingSession(sessionsArray) {
|
||||
for (let i = 0; i < sessionsArray.length; i++) {
|
||||
let session = sessionsArray[i]
|
||||
/* We will filter out all the sessions that does not belong to the market we are in */
|
||||
let marketTradingTasks = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false)
|
||||
if (node.payload.referenceParent.id !== marketTradingTasks.payload.referenceParent.id) { continue }
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, session, true) === true) {
|
||||
createSessionReference(node, session, 'Trading Session Reference')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingLearningSessionReferences(node, rootNodes) {
|
||||
let networkNode = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(node, 'Network Node', undefined, true, false, true, false)
|
||||
if (networkNode === undefined) { return }
|
||||
|
||||
let backLearningSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Back Learning Session')
|
||||
let liveLearningSessionsArray = UI.projects.foundations.utilities.branches.nodeBranchToArray(networkNode, 'Live Learning Session')
|
||||
|
||||
addMissingSession(backLearningSessionsArray)
|
||||
addMissingSession(liveLearningSessionsArray)
|
||||
|
||||
function addMissingSession(sessionsArray) {
|
||||
for (let i = 0; i < sessionsArray.length; i++) {
|
||||
let session = sessionsArray[i]
|
||||
/* We will filter out all the sessions that does not belong to the market we are in */
|
||||
let marketLearningTasks = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Learning Tasks', undefined, true, false, true, false)
|
||||
if (node.payload.referenceParent.id !== marketLearningTasks.payload.referenceParent.id) { continue }
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, session, true) === true) {
|
||||
createSessionReference(node, session, 'Learning Session Reference')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createSessionReference(node, session, nodeType) {
|
||||
let sessionReference = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, nodeType)
|
||||
sessionReference.payload.referenceParent = session
|
||||
}
|
||||
|
||||
function addMissingMarketDataProducts(node, rootNodes) {
|
||||
addMissingMarketProducts(node, rootNodes, 'Market Data Products')
|
||||
}
|
||||
|
||||
function addMissingMarketTradingProducts(node, rootNodes) {
|
||||
addMissingMarketProducts(node, rootNodes, 'Market Trading Products')
|
||||
}
|
||||
|
||||
function addMissingMarketLearningProducts(node, rootNodes) {
|
||||
addMissingMarketProducts(node, rootNodes, 'Market Learning Products')
|
||||
}
|
||||
|
||||
function addMissingMarketProducts(node, rootNodes, newNodeType) {
|
||||
if (node.payload.referenceParent === undefined) { return }
|
||||
if (node.payload.referenceParent.exchangeMarkets === undefined) { return }
|
||||
let marketsArray = node.payload.referenceParent.exchangeMarkets.markets
|
||||
|
||||
for (let i = 0; i < marketsArray.length; i++) {
|
||||
let market = marketsArray[i]
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, market, true) === true) {
|
||||
let marketDataProducts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
|
||||
marketDataProducts.payload.referenceParent = market
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingExchangeDataProducts(node, rootNodes) {
|
||||
addMissingExchange(node, rootNodes, 'Exchange Data Products')
|
||||
}
|
||||
|
||||
function addMissingExchangeTradingProducts(node, rootNodes) {
|
||||
addMissingExchange(node, rootNodes, 'Exchange Trading Products')
|
||||
}
|
||||
|
||||
function addMissingExchangeLearningProducts(node, rootNodes) {
|
||||
addMissingExchange(node, rootNodes, 'Exchange Learning Products')
|
||||
}
|
||||
|
||||
function addMissingExchange(node, rootNodes, newNodeType) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Crypto Ecosystem') {
|
||||
let cryptoEcosystem = rootNode
|
||||
for (let j = 0; j < cryptoEcosystem.cryptoExchanges.length; j++) {
|
||||
let cryptoExchanges = cryptoEcosystem.cryptoExchanges[j]
|
||||
for (let k = 0; k < cryptoExchanges.exchanges.length; k++) {
|
||||
let cryptoExchange = cryptoExchanges.exchanges[k]
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, cryptoExchange, true) === true) {
|
||||
let exchange = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
|
||||
exchange.payload.referenceParent = cryptoExchange
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function addMissingProjectDataProducts(node, rootNodes) {
|
||||
addMissingProject(node, rootNodes, 'Project Data Products')
|
||||
}
|
||||
|
||||
function addMissingProjectTradingProducts(node, rootNodes) {
|
||||
addMissingProject(node, rootNodes, 'Project Trading Products')
|
||||
}
|
||||
|
||||
function addMissingProjectLearningProducts(node, rootNodes) {
|
||||
addMissingProject(node, rootNodes, 'Project Learning Products')
|
||||
}
|
||||
|
||||
function addMissingProject(node, rootNodes, newNodeType) {
|
||||
for (let k = 0; k < PROJECTS_SCHEMA.length; k++) {
|
||||
let projectDefinition = PROJECTS_SCHEMA[k]
|
||||
let project = projectDefinition.name
|
||||
|
||||
for (let j = 0; j < rootNodes.length; j++) {
|
||||
let rootNode = rootNodes[j]
|
||||
if (rootNode.type === project + ' Project') {
|
||||
let projectDefinition = rootNode.projectDefinition
|
||||
if (projectDefinition !== undefined) {
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, projectDefinition, true) === true) {
|
||||
let projectTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType, undefined, project)
|
||||
projectTasks.payload.referenceParent = projectDefinition
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
function newFoundationsFunctionLibraryDependenciesFilter() {
|
||||
/*
|
||||
A Dependency Filter is list of Indicators a Strategy depends
|
||||
on, that is later used to filter out all the other indicators
|
||||
the Trading Bot depends on.
|
||||
|
||||
The function will scen a node branch, most likely a Trading System,
|
||||
looking into the code property of each node. It will analyze it's
|
||||
content and try to make a list of all indicators mentioned at the code
|
||||
text and at which time frames they are mentioned.
|
||||
|
||||
It is important to note that all nodes that are not of the type
|
||||
Javascript Code or Formula are going to be ignored.
|
||||
*/
|
||||
let thisObject = {
|
||||
createDependencyFilter: createDependencyFilter
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function createDependencyFilter(defaultExchange, defaultMarket, tradingSystem) {
|
||||
let filters = {
|
||||
market: {
|
||||
list: new Map()
|
||||
},
|
||||
exchange: {
|
||||
list: new Map(),
|
||||
markets: new Map(),
|
||||
products: new Map(),
|
||||
timeFrames: new Map()
|
||||
}
|
||||
}
|
||||
recursiveFilter(tradingSystem)
|
||||
|
||||
/* Transform the Map into arrays */
|
||||
filters.market.list = Array.from(filters.market.list.keys())
|
||||
|
||||
filters.exchange.list = Array.from(filters.exchange.list.keys())
|
||||
filters.exchange.markets = Array.from(filters.exchange.markets.keys())
|
||||
filters.exchange.products = Array.from(filters.exchange.products.keys())
|
||||
filters.exchange.timeFrames = Array.from(filters.exchange.timeFrames.keys())
|
||||
|
||||
return filters
|
||||
|
||||
function recursiveFilter(node) {
|
||||
if (node.type === 'Javascript Code' || node.type === 'Formula' || node.type === 'Feature Formula' || node.type === 'Data Formula') {
|
||||
filter(node.code)
|
||||
}
|
||||
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (node[property.name] !== undefined) {
|
||||
recursiveFilter(node[property.name])
|
||||
}
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = node[property.name]
|
||||
if (nodePropertyArray !== undefined) {
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let nodeProperty = nodePropertyArray[j]
|
||||
recursiveFilter(nodeProperty)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filter(code) {
|
||||
if (code === undefined) { return }
|
||||
/*
|
||||
We will clean the code from symbols that we do not need during our dependency analysis.
|
||||
*/
|
||||
code = code.replaceAll(',', '')
|
||||
code = code.replaceAll('(', '')
|
||||
code = code.replaceAll(')', '')
|
||||
code = code.replaceAll('{', '')
|
||||
code = code.replaceAll('}', '')
|
||||
code = code.replaceAll('!', '')
|
||||
code = code.replaceAll('|', '')
|
||||
code = code.replaceAll('<', '')
|
||||
code = code.replaceAll('>', '')
|
||||
code = code.replaceAll('=', '')
|
||||
code = code.replaceAll('\n', ' ')
|
||||
/*
|
||||
We will analyze each instruction of the code.
|
||||
*/
|
||||
let instructionsArray = code.split(' ')
|
||||
for (let i = 0; i < instructionsArray.length; i++) {
|
||||
let instruction = instructionsArray[i]
|
||||
/*
|
||||
The first kind of instruction we will handle are the ones
|
||||
related to the chart structure. For that we need the
|
||||
instruction to start with the keyword 'chart'.
|
||||
*/
|
||||
if (instruction.indexOf('chart') === 0) { // Example: chart.at01hs.popularSMA.sma200 - chart.at01hs.popularSMA.sma100 < 10
|
||||
let parts = instruction.split('.')
|
||||
let timeFrame = parts[1]
|
||||
let product = parts[2]
|
||||
/*
|
||||
From the instruction syntax we will get the timeFrame
|
||||
*/
|
||||
if (timeFrame !== 'atAnyTimeFrame') {
|
||||
timeFrame = timeFrame.substring(2, 4) + '-' + timeFrame.substring(4, 7)
|
||||
}
|
||||
filters.market.list.set(defaultMarket, true)
|
||||
|
||||
filters.exchange.timeFrames.set(defaultExchange + '-' + defaultMarket + '-' + product + '-' + timeFrame, true)
|
||||
filters.exchange.products.set(defaultExchange + '-' + defaultMarket + '-' + product, true)
|
||||
filters.exchange.markets.set(defaultExchange + '-' + defaultMarket, true)
|
||||
filters.exchange.list.set(defaultExchange, true)
|
||||
}
|
||||
/*
|
||||
The second kind of instruction we will handle are the ones
|
||||
related to the market data structure. For that we need
|
||||
the instruction to start with the keyword 'market'
|
||||
*/
|
||||
if (instruction.indexOf('market') === 0) { // Example: market.BTC.USDT.chart.at01hs.popularSMA.sma200 - market.ETC.USDT.chart.at01hs.popularSMA.sma100 < 10
|
||||
let parts = instruction.split('.')
|
||||
let baseAsset = parts[1]
|
||||
let quotedAsset = parts[2]
|
||||
let timeFrame = parts[4]
|
||||
let product = parts[5]
|
||||
/*
|
||||
From the instruction syntax we will get the timeFrame
|
||||
*/
|
||||
if (timeFrame !== 'atAnyTimeFrame') {
|
||||
timeFrame = timeFrame.substring(2, 4) + '-' + timeFrame.substring(4, 7)
|
||||
}
|
||||
filters.market.list.set(baseAsset + '-' + quotedAsset, true)
|
||||
|
||||
filters.exchange.timeFrames.set(defaultExchange + '-' + baseAsset + '-' + quotedAsset + '-' + product + '-' + timeFrame, true)
|
||||
filters.exchange.products.set(defaultExchange + '-' + baseAsset + '-' + quotedAsset + '-' + product, true)
|
||||
filters.exchange.markets.set(defaultExchange + '-' + baseAsset + '-' + quotedAsset, true)
|
||||
filters.exchange.list.set(defaultExchange, true)
|
||||
}
|
||||
/*
|
||||
The third kind of instruction we will handle are the ones
|
||||
related to the exchange data structure. For that we need
|
||||
the instruction to start with the keyword 'market'
|
||||
*/
|
||||
if (instruction.indexOf('exchange') === 0) { // Example: exchange.binance.market.BTC.USDT.chart.at01hs.popularSMA.sma200 - exchange.poloniex.market.ETC.USDT.chart.at01hs.popularSMA.sma100 < 10
|
||||
let parts = instruction.split('.')
|
||||
let exchange = parts[1]
|
||||
let baseAsset = parts[3]
|
||||
let quotedAsset = parts[4]
|
||||
let timeFrame = parts[6]
|
||||
let product = parts[7]
|
||||
/*
|
||||
From the instruction syntax we will get the timeFrame
|
||||
*/
|
||||
if (timeFrame !== 'atAnyTimeFrame') {
|
||||
timeFrame = timeFrame.substring(2, 4) + '-' + timeFrame.substring(4, 7)
|
||||
}
|
||||
filters.market.list.set(baseAsset + '-' + quotedAsset, true)
|
||||
|
||||
filters.exchange.timeFrames.set(exchange + '-' + baseAsset + '-' + quotedAsset + '-' + product + '-' + timeFrame, true)
|
||||
filters.exchange.products.set(exchange + '-' + baseAsset + '-' + quotedAsset + '-' + product, true)
|
||||
filters.exchange.markets.set(exchange + '-' + baseAsset + '-' + quotedAsset, true)
|
||||
filters.exchange.list.set(exchange, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
function newFoundationsFunctionLibraryLearningSessionFunctions() {
|
||||
let thisObject = {
|
||||
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
|
||||
runSession: runSession,
|
||||
stopSession: stopSession
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function syncronizeSessionWithBackEnd(node) {
|
||||
let validationsResult = validations(node)
|
||||
if (validationsResult === undefined) {
|
||||
/* If something fails at validations we just quit. */
|
||||
return
|
||||
}
|
||||
let networkNode = validationsResult.networkNode
|
||||
if (networkNode === undefined) {
|
||||
/* Nodes that do not belong to a network can not get ready. */
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
/* First we setup everything so as to listen to the response from the Task Server */
|
||||
let eventSubscriptionIdOnStatus
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
eventsServerClient.listenToEvent(key, 'Status Response', undefined, node.id, onResponse, onStatus)
|
||||
|
||||
function onResponse(message) {
|
||||
eventSubscriptionIdOnStatus = message.eventSubscriptionId
|
||||
}
|
||||
|
||||
function onStatus(message) {
|
||||
eventsServerClient.stopListening(key, eventSubscriptionIdOnStatus, node.id)
|
||||
if (message.event.status === 'Learning Session Runnning') {
|
||||
node.payload.uiObject.menu.internalClick('Run Learning Session')
|
||||
}
|
||||
}
|
||||
|
||||
/* Second we ask the Task Server if this Session is Running. */
|
||||
eventsServerClient.raiseEvent(key, 'Learning Session Status')
|
||||
}
|
||||
|
||||
function runSession(node, resume, callBackFunction) {
|
||||
let validationsResult = validations(node)
|
||||
if (validationsResult === undefined) {
|
||||
/* If something fails at validations we just quit. */
|
||||
return
|
||||
}
|
||||
let networkNode = validationsResult.networkNode
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
node.payload.uiObject.run(eventsServerClient, callBackFunction)
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
|
||||
let lightingPath = '' +
|
||||
'Learning System->' +
|
||||
'TensorFlow Library->' +
|
||||
'Execution Environment->Supervised Learning->Unsupervised Learning->Self Learning->Reinforcement Learning->' +
|
||||
'WebGL Backend->NodeJS Backend->WASM Backend->CPU Backend->' +
|
||||
'Environment Flags->Debug Mode->Production Mode->' +
|
||||
'Supervised Learning->Unsupervised Learning->Self Learning->Reinforcement Learning->' +
|
||||
'Artificial Neural Network->Model->' +
|
||||
'Compile->Optimizer->Loss Function->Metrics->' +
|
||||
'Fit Dataset->Verbose->Epochs->Callbacks->' +
|
||||
'Layers API->Code API->' +
|
||||
'Sequential Model->Functional Model->' +
|
||||
'Input Layer->Sequential layer->Output Layer->'+
|
||||
'Input Shape->Batch Input Shape->Input Features->Data Feature->Feature Formula->' +
|
||||
'Output Labels->Data Label->Label Formula->' +
|
||||
'Advanced Activation Layers->Basic Layers->Convolutional Layers->' +
|
||||
'Conv 1D Layer->Conv 2D Layer->Conv 2D Transpose Layer->Conv 3D Layer->Cropping 2D Layer->Depthwise Convo 2D Layer->Separable Convo 2D Layer->Up Sampling 2D Layer->' +
|
||||
'Activation Layer->Dense Layer->Dropout Layer->Embedding Layer->Flatten Layer->Permutable Layer->Rrepeat Vector Layer->Reshape Layer->Spatial Dropout 1D Layer->' +
|
||||
'Elu Layer->Leaky Relu Layer->Prelu Layer->Relu Layer->Softmax Layer->Thresholded Relu Layer->'+
|
||||
'Dimensionality Units->Activation Function->Batch Size->Dtype->Trainable->Weights->Tensor->Kernel->Bias->' +
|
||||
'Kernel Initializer->Kernel Constraint->Kernel Regularizer->' +
|
||||
'Bias Initializer->Bias Constraint->Bias Regularizer->'
|
||||
|
||||
let learningSystem = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(node.learningSystemReference.payload.referenceParent, false, true, true, false, false, lightingPath)
|
||||
|
||||
lightingPath = '' +
|
||||
'Learning Engine->' +
|
||||
'Learning Current->Learning Last->Previous->' +
|
||||
'Learning Episode->' +
|
||||
'Episode Base Asset->Episode Quoted Asset->Learning Episode Counters->Learning Episode Statistics->' +
|
||||
'Strategies->Positions->Orders->Hits->Fails->' +
|
||||
'Profit Loss->Hit Ratio->Hit Fail->Days->ROI->Annualized Rate Of Return->User Defined Statistic->' +
|
||||
'Candle->Cycle->' +
|
||||
'Begin->End->Last Begin->Last End->Open->Close->Min->Max->Index->' +
|
||||
'Distance To Learning Event->' +
|
||||
'Head Of The Market->Process Date->' +
|
||||
'Trigger On->Trigger Off->Take Position->Close Position->Next Phase->Move To Phase->Create Order->Cancel Order->Close Order->' +
|
||||
'Strategy->' +
|
||||
'Strategy Counters->' +
|
||||
'Position->' +
|
||||
'Entry Target Rate->Exit Target Rate->' +
|
||||
'Stop Loss->Stop Loss Phase->Stop Loss Position->Begin->End->Initial Value->Final Value->' +
|
||||
'Take Profit->Take Profit Phase->Take Profit Position->Begin->End->Initial Value->Final Value->' +
|
||||
'Position Counters->' +
|
||||
'Position Statistics->Days->User Defined Statistic->' +
|
||||
'Position Base Asset->Position Quoted Asset->Entry Target Size->Exit Target Size->' +
|
||||
'Profit Loss->ROI->Hit Fail->' +
|
||||
'Exchange Orders->Market Buy Orders->Market Sell Orders->Limit Buy Orders->Limit Sell Orders->' +
|
||||
'Market Order->Limit Order->' +
|
||||
'Exchange Id->Rate->Order Name->Algorithm Name->Lock->' +
|
||||
'Order Counters->' +
|
||||
'Order Base Asset->Order Quoted Asset->' +
|
||||
'Actual Size->Size->Size Filled->Amount Received->Fees Paid->Fees To Be Paid->' +
|
||||
'Order Statistics->Percentage Filled->Actual Rate->Days->User Defined Statistic->' +
|
||||
'Strategy Trigger Stage->Strategy Open Stage->Strategy Manage Stage->Strategy Close Stage->' +
|
||||
'Begin->End->Exit Type->Status->Begin Rate->End Rate->Stage Base Asset->Stage Quoted Asset->Size Placed->Target Size->Size Filled->Fees Paid->Stage Defined In->' +
|
||||
'Serial Number->Identifier->Begin->End->Begin Rate->End Rate->Strategy Name->Status->Exit Type->' +
|
||||
'Balance->Begin Balance->End Balance->' +
|
||||
'Index->Situation Name->Formula->Periods->' +
|
||||
'Features->Feature->Begin->End->Feature Value->'+
|
||||
'Labels->Label->Begin->End->Label Value->'+
|
||||
'Predictions->Prediction->Begin->End->Prediction Value->'
|
||||
|
||||
let learningEngine = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(node.learningEngineReference.payload.referenceParent, false, true, true, false, false, lightingPath)
|
||||
|
||||
lightingPath = '' +
|
||||
'Back Learning Session->Live Learning Session->' +
|
||||
'Learning Parameters->' +
|
||||
'Learning Algorithm->Time Range->Time Frame->Heartbeats->User Defined Parameters->' +
|
||||
'Social Bots->Telegram Bot->Discord Bot->Slack Bot->'
|
||||
|
||||
let session = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(node, false, true, true, false, false, lightingPath)
|
||||
|
||||
let defaultExchange = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(validationsResult.exchange.payload, 'codeName')
|
||||
let defaultMarket =
|
||||
UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(validationsResult.market.baseAsset.payload.referenceParent.payload, 'codeName')
|
||||
+ '-' +
|
||||
UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(validationsResult.market.quotedAsset.payload.referenceParent.payload, 'codeName')
|
||||
|
||||
let dependencyFilter = UI.projects.foundations.functionLibraries.dependenciesFilter.createDependencyFilter(
|
||||
defaultExchange,
|
||||
defaultMarket,
|
||||
node.learningSystemReference.payload.referenceParent
|
||||
)
|
||||
|
||||
/* Raise event to run the session */
|
||||
let event = {
|
||||
session: JSON.stringify(session),
|
||||
learningSystem: JSON.stringify(learningSystem),
|
||||
learningEngine: JSON.stringify(learningEngine),
|
||||
dependencyFilter: JSON.stringify(dependencyFilter),
|
||||
resume: resume
|
||||
}
|
||||
|
||||
if (resume !== true) {
|
||||
eventsServerClient.raiseEvent(key, 'Run Learning Session', event)
|
||||
} else {
|
||||
eventsServerClient.raiseEvent(key, 'Resume Learning Session', event)
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function stopSession(node, callBackFunction) {
|
||||
let validationsResult = validations(node)
|
||||
if (validationsResult === undefined) {
|
||||
/* If something fails at validations we just quit. */
|
||||
return
|
||||
}
|
||||
let networkNode = validationsResult.networkNode
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
eventsServerClient.raiseEvent(key, 'Stop Learning Session')
|
||||
|
||||
node.payload.uiObject.stop(callBackFunction, undefined, true)
|
||||
}
|
||||
|
||||
function validations(node) {
|
||||
|
||||
let result = {}
|
||||
|
||||
if (node.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs a Process Instance parent to be able to run.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Process Instance node.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Task.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Task Manager.')
|
||||
return
|
||||
}
|
||||
|
||||
result.taskManager = node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
|
||||
if (result.taskManager.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Mine Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Market Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Exchange Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Testing or Production Learning Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Network Node.')
|
||||
return
|
||||
}
|
||||
|
||||
result.networkNode = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(result.taskManager, 'Network Node', undefined, true, false, true, false)
|
||||
|
||||
if (node.learningSystemReference === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs a child Learning System Reference.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.learningEngineReference === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs a child Learning Engine Reference.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.learningSystemReference.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Learning System Reference needs to reference a Learning System.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.learningEngineReference.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Learning Engine Reference needs to reference a Learning Engine.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to have a Default Market.')
|
||||
return
|
||||
}
|
||||
|
||||
result.market = result.taskManager.payload.parentNode.payload.parentNode.payload.referenceParent
|
||||
|
||||
if (result.market.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Default Market needs to be a child of Exchange Markets.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Exchange Markets neeed to be a child of Crypto Exchange.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.baseAsset === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Default Market needs to have a Base Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.quotedAsset === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Default Market needs to have a Quoted Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.baseAsset.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Market Base Asset needs to reference an Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.quotedAsset.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Market Quoted Asset needs to reference an Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
result.exchange = result.market.payload.parentNode.payload.parentNode
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
function newFoundationsFunctionLibraryMineFunctions() {
|
||||
let thisObject = {
|
||||
addAllOutputDatasets: addAllOutputDatasets,
|
||||
addAllDataDependencies: addAllDataDependencies,
|
||||
addAllDataMineDataDependencies: addAllDataMineDataDependencies
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function addAllOutputDatasets(node) {
|
||||
|
||||
/* Validations to see if we can do this or not. */
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.uiObject === undefined) { return }
|
||||
if (node.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (node.payload.parentNode.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (node.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a grand parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Next, we are going to scan recursively through all nodes of type Product Definition Folder
|
||||
and Product Definition. For each Product Definition Folder we will create a counterpart
|
||||
Output Dataset Folder, and for each Product Definition found we will create a Output Definition
|
||||
for each Dataset defined inside the Product Definition.
|
||||
*/
|
||||
UI.projects.foundations.utilities.folders.asymetricalFolderStructureCloning(
|
||||
node.payload.parentNode.payload.parentNode,
|
||||
node,
|
||||
'products',
|
||||
'productDefinitionFolders',
|
||||
'outputDatasetFolders',
|
||||
'Output Dataset',
|
||||
'Output Dataset Folder',
|
||||
'datasets'
|
||||
)
|
||||
}
|
||||
|
||||
function addAllDataDependencies(node) {
|
||||
|
||||
/* Validations to see if we can do this or not. */
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.uiObject === undefined) { return }
|
||||
if (node.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
if (node.payload.referenceParent.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.')
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Next, we are going to scan through all the bots of the Data Mine referenced, and for each bot we will
|
||||
create a Bots Data Dependency node. Later we will scan all the Products Definitions of each bot, and for each
|
||||
Dataset of each Product we will create a Data Dependency. In case we find Product Definition Folders, we will
|
||||
recreate that structure too, using in this case Data Dependency Folders.
|
||||
*/
|
||||
let dataMine = node.payload.referenceParent
|
||||
scanBotArray(dataMine.sensorBots)
|
||||
scanBotArray(dataMine.apiDataFetcherBots)
|
||||
scanBotArray(dataMine.indicatorBots)
|
||||
scanBotArray(dataMine.tradingBots)
|
||||
scanBotArray(dataMine.learningBots)
|
||||
|
||||
function scanBotArray(botArray) {
|
||||
for (let i = 0; i < botArray.length; i++) {
|
||||
let bot = botArray[i]
|
||||
let botProducts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Bot Data Dependencies')
|
||||
botProducts.name = bot.name
|
||||
|
||||
UI.projects.foundations.utilities.folders.asymetricalFolderStructureCloning(
|
||||
bot,
|
||||
botProducts,
|
||||
'products',
|
||||
'productDefinitionFolders',
|
||||
'dataDependencyFolders',
|
||||
'Data Dependency',
|
||||
'Data Dependency Folder',
|
||||
'datasets'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAllDataMineDataDependencies(node, rootNodes) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
|
||||
if (rootNode.type === 'Data Mine') {
|
||||
let dataMineDataDependencies = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Data Mine Data Dependencies')
|
||||
dataMineDataDependencies.payload.referenceParent = rootNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
function newNodeChildren() {
|
||||
let thisObject = {
|
||||
childrenCount: childrenCount
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function childrenCount(parentNode, childNode) {
|
||||
return countChildrenUiObject(parentNode, childNode)
|
||||
}
|
||||
|
||||
function countChildrenUiObject(parentNode, childNode) {
|
||||
let response = {
|
||||
childrenCount: 0,
|
||||
childIndex: undefined
|
||||
}
|
||||
let parentSchemaDocument = getSchemaDocument(parentNode)
|
||||
if (parentSchemaDocument !== undefined) {
|
||||
if (parentSchemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
|
||||
for (let i = 0; i < parentSchemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = parentSchemaDocument.childrenNodesProperties[i]
|
||||
if (parentNode[property.name] !== undefined) {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
response.childrenCount++
|
||||
if (parentNode[property.name].id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
}
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let schemaDocument = getSchemaDocument(childNode)
|
||||
if (schemaDocument !== undefined) {
|
||||
let nodePropertyArray = parentNode[property.name]
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let child = nodePropertyArray[j]
|
||||
if (schemaDocument.chainedToSameType === true) {
|
||||
if (j < 1) {
|
||||
response.childrenCount++
|
||||
if (child.id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
}
|
||||
}
|
||||
} else {
|
||||
response.childrenCount++
|
||||
if (child.id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
function newFoundationsFunctionLibraryNodeCloning() {
|
||||
const MODULE_NAME = 'Node Cloning'
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
|
||||
|
||||
let thisObject = {
|
||||
getNodeClone: getNodeClone
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getNodeClone(node) {
|
||||
let idConversionMap = new Map()
|
||||
|
||||
let inmatureClone = cloneNode(node)
|
||||
let matureClone = redirectReferenceParents(inmatureClone)
|
||||
|
||||
return matureClone
|
||||
|
||||
function cloneNode(node) {
|
||||
if (node === undefined) { return }
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
let object = {
|
||||
type: node.type,
|
||||
name: node.name,
|
||||
code: node.code,
|
||||
config: node.config,
|
||||
project: node.project
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (node[property.name] !== undefined) {
|
||||
object[property.name] = cloneNode(node[property.name])
|
||||
}
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'array': {
|
||||
if (node[property.name] !== undefined) {
|
||||
let nodePropertyArray = node[property.name]
|
||||
object[property.name] = []
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let protocolNode = cloneNode(nodePropertyArray[m])
|
||||
if (protocolNode !== undefined) {
|
||||
object[property.name].push(protocolNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object.id = newUniqueId()
|
||||
idConversionMap.set(node.id, object.id)
|
||||
|
||||
object.savedPayload = getSavedPayload(node)
|
||||
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
function redirectReferenceParents(node) {
|
||||
if (node === undefined) { return }
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
let object = {
|
||||
type: node.type,
|
||||
name: node.name,
|
||||
code: node.code,
|
||||
config: node.config,
|
||||
project: node.project
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (node[property.name] !== undefined) {
|
||||
object[property.name] = redirectReferenceParents(node[property.name])
|
||||
}
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'array': {
|
||||
if (node[property.name] !== undefined) {
|
||||
let nodePropertyArray = node[property.name]
|
||||
object[property.name] = []
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let protocolNode = redirectReferenceParents(nodePropertyArray[m])
|
||||
if (protocolNode !== undefined) {
|
||||
object[property.name].push(protocolNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object.id = node.id
|
||||
|
||||
object.savedPayload = node.savedPayload
|
||||
|
||||
if (object.savedPayload !== undefined) {
|
||||
if (object.savedPayload.referenceParent !== undefined) {
|
||||
let newId = idConversionMap.get(object.savedPayload.referenceParent.id)
|
||||
if (newId !== undefined) {
|
||||
object.savedPayload.referenceParent.id = newId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return object
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSavedPayload(node) {
|
||||
if (node.payload === undefined) { return }
|
||||
let savedPayload = {
|
||||
position: {
|
||||
x: node.payload.position.x,
|
||||
y: node.payload.position.y
|
||||
},
|
||||
targetPosition: {
|
||||
x: node.payload.targetPosition.x,
|
||||
y: node.payload.targetPosition.y
|
||||
},
|
||||
floatingObject: {
|
||||
isPinned: node.payload.floatingObject.isPinned,
|
||||
isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually),
|
||||
isCollapsed: (node.payload.floatingObject.isCollapsed && node.payload.floatingObject.collapsedManually),
|
||||
angleToParent: (node.payload.floatingObject.angleToParent),
|
||||
distanceToParent: (node.payload.floatingObject.distanceToParent),
|
||||
arrangementStyle: (node.payload.floatingObject.arrangementStyle)
|
||||
},
|
||||
uiObject: {
|
||||
isPlaying: node.payload.uiObject.isPlaying,
|
||||
isRunning: node.payload.uiObject.isRunning,
|
||||
shortcutKey: node.payload.uiObject.shortcutKey
|
||||
}
|
||||
}
|
||||
|
||||
/* Next for the ones that have a reference parent, we include it */
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
savedPayload.referenceParent = {
|
||||
type: node.payload.referenceParent.type,
|
||||
name: node.payload.referenceParent.name,
|
||||
id: node.payload.referenceParent.id
|
||||
}
|
||||
} else {
|
||||
/* The referenceParent property can be inherited from the previous saved payload. */
|
||||
if (node.savedPayload !== undefined) {
|
||||
savedPayload.referenceParent = node.savedPayload.referenceParent
|
||||
}
|
||||
}
|
||||
|
||||
return savedPayload
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
function newFoundationsFunctionLibraryNodeDeleter() {
|
||||
let thisObject = {
|
||||
deleteWorkspace: deleteWorkspace,
|
||||
deleteUIObject: deleteUIObject
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function destroyUiObject(node) {
|
||||
UI.projects.foundations.spaces.floatingSpace.uiObjectConstructor.destroyUiObject(node.payload)
|
||||
}
|
||||
|
||||
function deleteWorkspace(node, rootNodes, callBackFuntion) {
|
||||
if (node.rootNodes !== undefined) {
|
||||
|
||||
let totalDeleted = 0
|
||||
let totalToBeDeleted = node.rootNodes.length
|
||||
|
||||
for (let i = 0; i < node.rootNodes.length; i++) {
|
||||
let rootNode = node.rootNodes[i]
|
||||
setTimeout(deleteRootNode, 100, rootNode)
|
||||
}
|
||||
|
||||
function deleteRootNode(rootNode) {
|
||||
let result = deleteUIObject(rootNode, rootNodes)
|
||||
if (result === false) {
|
||||
return false
|
||||
} else {
|
||||
totalDeleted++
|
||||
if (totalDeleted === totalToBeDeleted) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function finish() {
|
||||
completeDeletion(node, rootNodes)
|
||||
destroyUiObject(node)
|
||||
cleanNode(node)
|
||||
callBackFuntion()
|
||||
}
|
||||
}
|
||||
|
||||
function deleteUIObject(node, rootNodes) {
|
||||
|
||||
/* First we restore the reference parent to its default state */
|
||||
if (node.payload !== undefined && node.payload.referenceParent !== undefined && node.payload.referenceParent.payload !== undefined && node.payload.referenceParent.payload.uiObject !== undefined) {
|
||||
node.payload.referenceParent.payload.uiObject.isShowing = false
|
||||
}
|
||||
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
/* Remove all of its own children nodes. */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (node[property.name] !== undefined) {
|
||||
let result = deleteUIObject(node[property.name], rootNodes)
|
||||
if (result === false) { return false }
|
||||
}
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = node[property.name]
|
||||
if (nodePropertyArray !== undefined) {
|
||||
while (nodePropertyArray.length > 0) {
|
||||
let result = deleteUIObject(nodePropertyArray[0], rootNodes)
|
||||
if (result === false) { return false }
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove node from parent */
|
||||
if (schemaDocument.propertyNameAtParent !== undefined) {
|
||||
let removedFromParent = false
|
||||
if (node.payload !== undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
let parentSchemaDocument = getSchemaDocument(node.payload.parentNode)
|
||||
if (parentSchemaDocument !== undefined) {
|
||||
if (parentSchemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < parentSchemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = parentSchemaDocument.childrenNodesProperties[i]
|
||||
if (schemaDocument.propertyNameAtParent === property.name) {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
node.payload.parentNode[property.name] = undefined
|
||||
removedFromParent = true
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = node.payload.parentNode[property.name]
|
||||
if (nodePropertyArray !== undefined) {
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let arrayItem = nodePropertyArray[j]
|
||||
if (arrayItem.id === node.id) {
|
||||
/* If this object is chained to the ones of the same type we need to give the next in the chain the reference to the current chain parent */
|
||||
if (schemaDocument.chainedToSameType === true) {
|
||||
if (j < nodePropertyArray.length - 1) {
|
||||
let nextArrayItem = nodePropertyArray[j + 1]
|
||||
nextArrayItem.payload.chainParent = node.payload.chainParent
|
||||
}
|
||||
}
|
||||
|
||||
nodePropertyArray.splice(j, 1)
|
||||
removedFromParent = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (removedFromParent === false) {
|
||||
console.log('[ERROR] Deleting Node: ' + node.type + ' ' + node.name + '. This node could not be deleted from its parent node (' + node.payload.parentNode.type + ') because its configured propertyNameAtParent (' + schemaDocument.propertyNameAtParent + ') does not match any of the properties of its parent.')
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
completeDeletion(node, rootNodes)
|
||||
destroyUiObject(node)
|
||||
cleanNode(node)
|
||||
}
|
||||
}
|
||||
|
||||
function completeDeletion(node, rootNodes) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.id === node.id) {
|
||||
rootNodes.splice(i, 1)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cleanNode(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
|
||||
node.payload.targetPosition.x = undefined
|
||||
node.payload.targetPosition.y = undefined
|
||||
node.payload.visible = undefined
|
||||
node.payload.title = undefined
|
||||
node.payload.node = undefined
|
||||
node.payload.parentNode = undefined
|
||||
node.payload.chainParent = undefined
|
||||
node.payload.executeAction = undefined
|
||||
node.handle = undefined
|
||||
node.payload = undefined
|
||||
node.cleaned = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
function newFoundationsFunctionLibraryNodePath() {
|
||||
let thisObject = {
|
||||
getNodePath: getNodePath
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function getNodePath(node) {
|
||||
|
||||
let nodePath = 'value'
|
||||
|
||||
recursiveGet(node)
|
||||
|
||||
return 'tradingEngine.' + nodePath
|
||||
|
||||
function recursiveGet(node) {
|
||||
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.parentNode === undefined) { return }
|
||||
|
||||
let schemaDocument = getSchemaDocument(node.payload.parentNode)
|
||||
if (schemaDocument === undefined) { return }
|
||||
if (schemaDocument.childrenNodesProperties === undefined) { return }
|
||||
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
let parentProperty = node.payload.parentNode[property.name]
|
||||
if (parentProperty === undefined) { continue }
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (parentProperty.id === node.id) {
|
||||
/* We found it */
|
||||
nodePath = property.name + '.' + nodePath
|
||||
recursiveGet(node.payload.parentNode)
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
for (let j = 0; j < parentProperty.length; j++) {
|
||||
let arrayProperty = parentProperty[j]
|
||||
if (arrayProperty === undefined) {continue}
|
||||
if (arrayProperty.id === node.id) {
|
||||
/* We found it */
|
||||
nodePath = property.name + '[' + j + ']' + '.' + nodePath
|
||||
recursiveGet(node.payload.parentNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
function newFoundationsFunctionLibraryOnFocus() {
|
||||
let thisObject = {
|
||||
getNodeThatIsOnFocus: getNodeThatIsOnFocus
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getNodeThatIsOnFocus(node) {
|
||||
if (node === undefined || node === null) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
/* First we ask the question to ourself */
|
||||
if (node.payload.uiObject.isOnFocus === true) {
|
||||
return node
|
||||
}
|
||||
|
||||
/* Then we check all of its own children nodes. */
|
||||
if (node.payload.floatingObject.isCollapsed !== true) {
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (node[property.name] !== undefined) {
|
||||
let child = getNodeThatIsOnFocus(node[property.name])
|
||||
if (child !== undefined) {
|
||||
return child
|
||||
}
|
||||
}
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = node[property.name]
|
||||
if (nodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let child = getNodeThatIsOnFocus(nodePropertyArray[m])
|
||||
if (child !== undefined) {
|
||||
return child
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
function newFoundationsFunctionLibraryPluginsFunctions() {
|
||||
let thisObject = {
|
||||
pluginMissingProjects: pluginMissingProjects,
|
||||
pluginMissingDataMines: pluginMissingDataMines,
|
||||
pluginMissingTradingMines: pluginMissingTradingMines,
|
||||
pluginMissingTradingSystems: pluginMissingTradingSystems,
|
||||
pluginMissingTradingEngines: pluginMissingTradingEngines,
|
||||
pluginMissingLearningMines: pluginMissingLearningMines,
|
||||
pluginMissingLearningSystems: pluginMissingLearningSystems,
|
||||
pluginMissingLearningEngines: pluginMissingLearningEngines,
|
||||
pluginMissingTutorials: pluginMissingTutorials,
|
||||
pluginMissingApiMaps: pluginMissingApiMaps
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getPluginFileNames(projectName, pluginType, callBack) {
|
||||
httpRequest(undefined, 'PluginFileNames/' + projectName + '/' + pluginType, onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
console.log('Failed to Fetch Plugin ' + pluginType + ' from the Client')
|
||||
return
|
||||
}
|
||||
|
||||
let pluginFileNames = JSON.parse(data)
|
||||
callBack(pluginFileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function addPluginFileIfNeeded(node, fileNames) {
|
||||
for (let i = 0; i < fileNames.length; i++) {
|
||||
let fileName = fileNames[i]
|
||||
fileName = fileName.replace('.json', '')
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildrenByName(node, fileName) === true) {
|
||||
let child = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Plugin File')
|
||||
child.name = fileName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingProjects(node, rootNodes) {
|
||||
for (let k = 0; k < PROJECTS_SCHEMA.length; k++) {
|
||||
let projectDefinition = PROJECTS_SCHEMA[k]
|
||||
let project = projectDefinition.name
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildrenByName(node, project) === true) {
|
||||
let child = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Plugin Project')
|
||||
child.name = project
|
||||
let config = JSON.parse(child.config)
|
||||
config.codeName = project
|
||||
child.config = JSON.stringify(config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getProjectName(node) {
|
||||
/* Validations to see if we can do this or not. */
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.uiObject === undefined) { return }
|
||||
|
||||
if (node.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a Plugin Project node as a parent to execute this action.')
|
||||
return
|
||||
}
|
||||
if (node.payload.parentNode.payload === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('You need to have a Plugin Project node as a parent to execute this action.')
|
||||
return
|
||||
}
|
||||
let pluginProject = node.payload.parentNode
|
||||
let config = JSON.parse(pluginProject.config)
|
||||
|
||||
return config.codeName
|
||||
}
|
||||
|
||||
function pluginMissingDataMines(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Data-Mines', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingTradingMines(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Trading-Mines', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingTradingSystems(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Trading-Systems', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingTradingEngines(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Trading-Engines', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingLearningMines(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Learning-Mines', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingLearningSystems(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Learning-Systems', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingLearningEngines(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Learning-Engines', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingTutorials(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'Tutorials', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingApiMaps(node, rootNodes) {
|
||||
let projectName = getProjectName(node)
|
||||
if (projectName === "" || projectName === undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
getPluginFileNames(projectName, 'API-Maps', onNamesArrived)
|
||||
|
||||
function onNamesArrived(fileNames) {
|
||||
addPluginFileIfNeeded(node, fileNames)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
function newFoundationsFunctionLibraryProtocolNode() {
|
||||
const MODULE_NAME = 'Protocol Node'
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
|
||||
|
||||
let thisObject = {
|
||||
getProtocolNode: getProtocolNode
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getProtocolNode(
|
||||
node,
|
||||
removePersonalData,
|
||||
parseConfig,
|
||||
includeIds,
|
||||
includePayload,
|
||||
includeReferencesInSavedPayload,
|
||||
lightingPath,
|
||||
excludeChildrenOfType
|
||||
) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
if (removePersonalData === true && schemaDocument.isPersonalData === true) { return }
|
||||
let object = {
|
||||
type: node.type,
|
||||
name: node.name,
|
||||
code: node.code,
|
||||
config: node.config,
|
||||
project: node.project
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
if (property.childType === excludeChildrenOfType) {
|
||||
continue
|
||||
}
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (node[property.name] !== undefined) {
|
||||
if (lightingPath === undefined) {
|
||||
object[property.name] = getProtocolNode(
|
||||
node[property.name],
|
||||
removePersonalData,
|
||||
parseConfig,
|
||||
includeIds,
|
||||
includeReferencesInSavedPayload,
|
||||
includePayload
|
||||
)
|
||||
} else {
|
||||
let newLightingPath = getNewLightingPath(lightingPath, node.type, property.childType)
|
||||
if (newLightingPath !== undefined) {
|
||||
object[property.name] = getProtocolNode(
|
||||
node[property.name],
|
||||
removePersonalData,
|
||||
parseConfig,
|
||||
includeIds,
|
||||
includePayload,
|
||||
includeReferencesInSavedPayload,
|
||||
newLightingPath
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'array': {
|
||||
if (node[property.name] !== undefined) {
|
||||
if (lightingPath === undefined) {
|
||||
let nodePropertyArray = node[property.name]
|
||||
object[property.name] = []
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let protocolNode = getProtocolNode(
|
||||
nodePropertyArray[m],
|
||||
removePersonalData,
|
||||
parseConfig,
|
||||
includeIds,
|
||||
includeReferencesInSavedPayload,
|
||||
includePayload
|
||||
)
|
||||
if (protocolNode !== undefined) {
|
||||
object[property.name].push(protocolNode)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let newLightingPath = getNewLightingPath(lightingPath, node.type, property.childType)
|
||||
if (newLightingPath !== undefined) {
|
||||
let nodePropertyArray = node[property.name]
|
||||
object[property.name] = []
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let protocolNode = getProtocolNode(
|
||||
nodePropertyArray[m],
|
||||
removePersonalData,
|
||||
parseConfig,
|
||||
includeIds,
|
||||
includePayload,
|
||||
includeReferencesInSavedPayload,
|
||||
newLightingPath
|
||||
)
|
||||
if (protocolNode !== undefined) {
|
||||
object[property.name].push(protocolNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Parent Nodes */
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
let newLightingPath = getNewLightingPath(lightingPath, node.type, node.payload.parentNode.type)
|
||||
if (newLightingPath !== undefined) {
|
||||
object.parentNode = getProtocolNode(
|
||||
node.payload.parentNode,
|
||||
removePersonalData,
|
||||
parseConfig,
|
||||
includeIds,
|
||||
includePayload,
|
||||
includeReferencesInSavedPayload,
|
||||
newLightingPath,
|
||||
node.type
|
||||
)
|
||||
} else {
|
||||
let newLightingPath = getNewLightingPath(lightingPath, node.type, node.payload.parentNode.type)
|
||||
}
|
||||
}
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
let newLightingPath = getNewLightingPath(lightingPath, node.type, node.payload.referenceParent.type)
|
||||
if (newLightingPath !== undefined) {
|
||||
object.referenceParent = getProtocolNode(
|
||||
node.payload.referenceParent,
|
||||
removePersonalData,
|
||||
parseConfig,
|
||||
includeIds,
|
||||
includePayload,
|
||||
includeReferencesInSavedPayload,
|
||||
newLightingPath
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (parseConfig && object.config !== undefined && schemaDocument.editors !== undefined) {
|
||||
if (schemaDocument.editors.config === true) {
|
||||
try {
|
||||
object.config = JSON.parse(node.config)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> err = ' + err.stack) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.type = ' + node.type) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.name = ' + node.name) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.config = ' + node.config) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.id = ' + node.id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
if (includePayload) {
|
||||
object.savedPayload = getSavedPayload(node, includeReferencesInSavedPayload)
|
||||
}
|
||||
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
function getNewLightingPath(lightingPath, currentNodeType, nextNodeType) {
|
||||
if (lightingPath === undefined) { return }
|
||||
|
||||
if (currentNodeType === undefined) { return }
|
||||
if (nextNodeType === undefined) { return }
|
||||
|
||||
let currentNodePosition = lightingPath.indexOf('->' + currentNodeType + '->')
|
||||
let nextNodePosition = lightingPath.indexOf('->' + nextNodeType + '->')
|
||||
|
||||
/*
|
||||
In some situations, the current and next node are of the same type.
|
||||
When that happens, we need to search for the second instance of that type
|
||||
at the lighting path, and then remove one of the strings for the returning path.
|
||||
*/
|
||||
if (currentNodeType === nextNodeType) {
|
||||
let tempLightingPath = lightingPath.substring(currentNodePosition + currentNodeType.length + 2, lightingPath.length + 1)
|
||||
nextNodePosition = tempLightingPath.indexOf('->' + nextNodeType + '->')
|
||||
|
||||
let newLightingPath = lightingPath.substring(nextNodePosition, lightingPath.length + 1)
|
||||
|
||||
if (nextNodePosition >= currentNodePosition) {
|
||||
return newLightingPath
|
||||
}
|
||||
} else {
|
||||
let newLightingPath = lightingPath.substring(nextNodePosition, lightingPath.length + 1)
|
||||
|
||||
if (nextNodePosition > currentNodePosition) {
|
||||
return newLightingPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSavedPayload(node, includeReferencesInSavedPayload) {
|
||||
if (node.payload === undefined) { return }
|
||||
let savedPayload = {
|
||||
position: {
|
||||
x: node.payload.position.x,
|
||||
y: node.payload.position.y
|
||||
},
|
||||
targetPosition: {
|
||||
x: node.payload.targetPosition.x,
|
||||
y: node.payload.targetPosition.y
|
||||
},
|
||||
floatingObject: {
|
||||
isPinned: node.payload.floatingObject.isPinned,
|
||||
isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually),
|
||||
isCollapsed: (node.payload.floatingObject.isCollapsed && node.payload.floatingObject.collapsedManually),
|
||||
angleToParent: (node.payload.floatingObject.angleToParent),
|
||||
distanceToParent: (node.payload.floatingObject.distanceToParent),
|
||||
arrangementStyle: (node.payload.floatingObject.arrangementStyle)
|
||||
},
|
||||
uiObject: {
|
||||
isPlaying: node.payload.uiObject.isPlaying,
|
||||
isRunning: node.payload.uiObject.isRunning,
|
||||
shortcutKey: node.payload.uiObject.shortcutKey
|
||||
}
|
||||
}
|
||||
|
||||
if (node.payload.frame !== undefined) {
|
||||
savedPayload.frame = {
|
||||
position: {
|
||||
x: node.payload.frame.position.x,
|
||||
y: node.payload.frame.position.y
|
||||
},
|
||||
width: node.payload.frame.width,
|
||||
height: node.payload.frame.height,
|
||||
radius: node.payload.frame.radius
|
||||
}
|
||||
}
|
||||
|
||||
if (node.payload.tutorial !== undefined) {
|
||||
savedPayload.tutorial = {
|
||||
status: node.payload.tutorial.status
|
||||
}
|
||||
}
|
||||
|
||||
if (includeReferencesInSavedPayload) {
|
||||
/* Next for the ones that have a reference parent, we include it */
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
savedPayload.referenceParent = {
|
||||
type: node.payload.referenceParent.type,
|
||||
name: node.payload.referenceParent.name,
|
||||
id: node.payload.referenceParent.id
|
||||
}
|
||||
} else {
|
||||
/* The referenceParent property can be inherited from the previous saved payload. */
|
||||
if (node.savedPayload !== undefined) {
|
||||
savedPayload.referenceParent = node.savedPayload.referenceParent
|
||||
}
|
||||
}
|
||||
}
|
||||
return savedPayload
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
function newFoundationsFunctionLibraryAttachDetach() {
|
||||
let thisObject = {
|
||||
referenceDetachNode: referenceDetachNode,
|
||||
referenceAttachNode: referenceAttachNode
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function referenceDetachNode(node) {
|
||||
completeDetachment(node)
|
||||
}
|
||||
|
||||
function referenceAttachNode(node, attachToNode) {
|
||||
completeAttachment(node, attachToNode)
|
||||
}
|
||||
|
||||
function completeAttachment(node, attachToNode) {
|
||||
node.payload.referenceParent = attachToNode
|
||||
}
|
||||
|
||||
function completeDetachment(node) {
|
||||
if (node.payload !== undefined) {
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
if (node.payload.referenceParent.payload !== undefined) {
|
||||
if (node.payload.referenceParent.payload.uiObject !== undefined) {
|
||||
node.payload.referenceParent.payload.uiObject.isShowing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
node.payload.referenceParent = undefined
|
||||
if (node.savedPayload !== undefined) {
|
||||
node.savedPayload.referenceParent = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
function newFoundationsFunctionLibraryShortcutKeys() {
|
||||
let thisObject = {
|
||||
getNodeByShortcutKey: getNodeByShortcutKey
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getNodeByShortcutKey(node, searchingKey) {
|
||||
if (node === undefined) { return }
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
/* Check Self first */
|
||||
if (node.payload.uiObject.shortcutKey === searchingKey) {
|
||||
return node
|
||||
}
|
||||
|
||||
/* Check all of its own children nodes. */
|
||||
if (node.payload.floatingObject.isCollapsed !== true) {
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (node[property.name] !== undefined) {
|
||||
let child = getNodeByShortcutKey(node[property.name], searchingKey)
|
||||
if (child !== undefined) {
|
||||
return child
|
||||
}
|
||||
}
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = node[property.name]
|
||||
if (nodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let child = getNodeByShortcutKey(nodePropertyArray[m], searchingKey)
|
||||
if (child !== undefined) {
|
||||
return child
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
function newFoundationsFunctionLibrarySocialBotsFunctions() {
|
||||
let thisObject = {
|
||||
sendTelegramTestMessage: sendTelegramTestMessage,
|
||||
sendDiscordTestMessage: sendDiscordTestMessage,
|
||||
sendSlackTestMessage: sendSlackTestMessage
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function sendTelegramTestMessage(node, callBackFunction) {
|
||||
|
||||
let botToken = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'botToken')
|
||||
let chatId = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'chatId')
|
||||
|
||||
if (botToken === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('botToken parameter not defined.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
if (chatId === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('chatId parameter not defined.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let params = {
|
||||
text: "Test Message from Superalgos",
|
||||
chat_id: chatId
|
||||
}
|
||||
|
||||
httpRequestJSON(JSON.stringify(params),"https://api.telegram.org/bot" + botToken + "/sendMessage", onResponse)
|
||||
|
||||
function onResponse(err) {
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setInfoMessage('Telegram message sent.')
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
} else {
|
||||
node.payload.uiObject.setErrorMessage('Could not send Telegram message. Error Response: ' + err.message)
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function httpRequestJSON(pContentToSend, pPath, callBackFunction) {
|
||||
let xmlHttpRequest = new XMLHttpRequest();
|
||||
xmlHttpRequest.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText);
|
||||
return;
|
||||
} else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) {
|
||||
callBackFunction({
|
||||
result: "Fail",
|
||||
message: JSON.parse(xmlHttpRequest.responseText).description,
|
||||
code: JSON.parse(xmlHttpRequest.responseText).error_code
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (pContentToSend === undefined) {
|
||||
xmlHttpRequest.open("GET", pPath, true);
|
||||
xmlHttpRequest.send();
|
||||
} else {
|
||||
try {
|
||||
let blob = new Blob([pContentToSend], { type: 'application/json' });
|
||||
xmlHttpRequest.open("POST", pPath, true);
|
||||
xmlHttpRequest.send(blob);
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); }
|
||||
callBackFunction({ result: "Fail", message: err.message })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendDiscordTestMessage(node, callBackFunction) {
|
||||
|
||||
let webhookURL = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'webhookURL')
|
||||
|
||||
if (webhookURL === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('webhookURL parameter not defined.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let message = "Test message from Superalgos!"
|
||||
|
||||
httpRequestJSON(JSON.stringify({content: message}), webhookURL, onResponse)
|
||||
|
||||
function onResponse(err) {
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setInfoMessage('Discord message sent.')
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
} else {
|
||||
node.payload.uiObject.setErrorMessage('Could not send Discord message. Error Response: ' + err.message)
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function httpRequestJSON(pContentToSend, pPath, callBackFunction) {
|
||||
let xmlHttpRequest = new XMLHttpRequest();
|
||||
xmlHttpRequest.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText);
|
||||
return;
|
||||
} else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) {
|
||||
callBackFunction({
|
||||
result: "Fail",
|
||||
message: JSON.parse(xmlHttpRequest.responseText).description,
|
||||
code: JSON.parse(xmlHttpRequest.responseText).error_code
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (pContentToSend === undefined) {
|
||||
xmlHttpRequest.open("GET", pPath, true);
|
||||
xmlHttpRequest.send();
|
||||
} else {
|
||||
try {
|
||||
let blob = new Blob([pContentToSend], { type: 'application/json' });
|
||||
xmlHttpRequest.open("POST", pPath, true);
|
||||
xmlHttpRequest.send(blob);
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); }
|
||||
callBackFunction({ result: "Fail", message: err.message })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendSlackTestMessage(node, callBackFunction) {
|
||||
|
||||
let webhookURL = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'webhookURL')
|
||||
|
||||
if (webhookURL === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('webhookURL parameter not defined.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let message = "Test message from Superalgos!"
|
||||
|
||||
httpRequestJSON(JSON.stringify({text: message}), webhookURL, onResponse)
|
||||
|
||||
function onResponse(err) {
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setInfoMessage('Slack message sent.')
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
} else {
|
||||
node.payload.uiObject.setErrorMessage('Could not send Slack message. Error Response: ' + err.message)
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function httpRequestJSON(pContentToSend, pPath, callBackFunction) {
|
||||
let xmlHttpRequest = new XMLHttpRequest();
|
||||
xmlHttpRequest.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText);
|
||||
return;
|
||||
} else if (this.readyState === 4 && (this.status === 404 || this.status === 401 || this.status === 400)) {
|
||||
callBackFunction({
|
||||
result: "Fail",
|
||||
message: xmlHttpRequest.responseText
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (pContentToSend === undefined) {
|
||||
xmlHttpRequest.open("GET", pPath, true);
|
||||
xmlHttpRequest.send();
|
||||
} else {
|
||||
try {
|
||||
let blob = new Blob([pContentToSend]);
|
||||
xmlHttpRequest.open("POST", pPath, true);
|
||||
xmlHttpRequest.send(blob);
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); }
|
||||
callBackFunction({ result: "Fail", message: err.message })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
function newFoundationsFunctionLibrarySuperScriptsFunctions() {
|
||||
let thisObject = {
|
||||
runSuperScript: runSuperScript
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function runSuperScript(node, rootNodes) {
|
||||
try {
|
||||
let clone = UI.projects.foundations.functionLibraries.nodeCloning.getNodeClone
|
||||
let executionResult = true
|
||||
let superAction = node
|
||||
|
||||
function setup(templateClone, target, exchange, exchangeNodeType, arrayPropertyName) {
|
||||
spawnPosition.x = target.payload.position.x
|
||||
spawnPosition.y = target.payload.position.y
|
||||
|
||||
if (exchange === undefined) {
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.createUiObjectFromNode(templateClone, target, target)
|
||||
} else {
|
||||
let definition = getSchemaDocument(target)
|
||||
for (let i = 0; i < definition.childrenNodesProperties.length; i++) {
|
||||
let property = definition.childrenNodesProperties[i]
|
||||
if (property.childType === exchangeNodeType) {
|
||||
let exchanges = target[property.name]
|
||||
if (exchanges === undefined) {
|
||||
exchanges = []
|
||||
}
|
||||
let targetExchange
|
||||
for (let j = 0; j < exchanges.length; j++) {
|
||||
let thisExchange = exchanges[j]
|
||||
if (thisExchange.payload.referenceParent !== undefined) {
|
||||
if (thisExchange.payload.referenceParent.id === exchange.id) {
|
||||
targetExchange = thisExchange
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetExchange === undefined) {
|
||||
targetExchange = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(target, exchangeNodeType)
|
||||
targetExchange.payload.referenceParent = exchange
|
||||
}
|
||||
let nodesArray = targetExchange[arrayPropertyName]
|
||||
nodesArray.push(templateClone)
|
||||
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.createUiObjectFromNode(templateClone, targetExchange, targetExchange)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function deleteNode(node) {
|
||||
UI.projects.foundations.functionLibraries.nodeDeleter.deleteUIObject(node, rootNodes)
|
||||
}
|
||||
|
||||
/* Validations */
|
||||
if (executionResult === true && node.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Super Action node needs a Parent Node.')
|
||||
executionResult = false
|
||||
}
|
||||
if (executionResult === true && node.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Super Action node needs to reference a Master Script Node.')
|
||||
executionResult = false
|
||||
}
|
||||
if (executionResult === true && node.payload.referenceParent.javascriptCode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Master Script Node needs to have a child Javascript Code Node.')
|
||||
executionResult = false
|
||||
}
|
||||
|
||||
let masterScript = node.payload.referenceParent
|
||||
|
||||
eval(masterScript.javascriptCode.code)
|
||||
|
||||
let masterScriptInstance = newNewMasterScriptInstance()
|
||||
|
||||
if (executionResult === true) {
|
||||
executionResult = masterScriptInstance.runValidations(superAction, masterScript)
|
||||
}
|
||||
if (executionResult === true) {
|
||||
executionResult = masterScriptInstance.runScript(superAction, masterScript)
|
||||
}
|
||||
if (executionResult === true) {
|
||||
superAction.payload.uiObject.setValue('Execution Completed Successfully')
|
||||
} else {
|
||||
superAction.payload.uiObject.setValue('Execution Failed')
|
||||
}
|
||||
} catch (err) {
|
||||
superAction.payload.uiObject.setErrorMessage(err.message)
|
||||
superAction.payload.uiObject.setValue('Execution Failed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,953 @@
|
||||
function newFoundationsFunctionLibraryTaskFunctions() {
|
||||
let thisObject = {
|
||||
syncronizeTaskWithBackEnd: syncronizeTaskWithBackEnd,
|
||||
|
||||
runTask: runTask,
|
||||
stopTask: stopTask,
|
||||
runAllTasks: runAllTasks,
|
||||
stopAllTasks: stopAllTasks,
|
||||
runAllTaskManagers: runAllTaskManagers,
|
||||
stopAllTaskManagers: stopAllTaskManagers,
|
||||
|
||||
runAllProjectDataTasks: runAllProjectDataTasks,
|
||||
stopAllProjectDataTasks: stopAllProjectDataTasks,
|
||||
runAllProjectTradingTasks: runAllProjectTradingTasks,
|
||||
stopAllProjectTradingTasks: stopAllProjectTradingTasks,
|
||||
runAllProjectLearningTasks: runAllProjectLearningTasks,
|
||||
stopAllProjectLearningTasks: stopAllProjectLearningTasks,
|
||||
|
||||
runAllExchangeDataTasks: runAllExchangeDataTasks,
|
||||
stopAllExchangeDataTasks: stopAllExchangeDataTasks,
|
||||
runAllExchangeTradingTasks: runAllExchangeTradingTasks,
|
||||
stopAllExchangeTradingTasks: stopAllExchangeTradingTasks,
|
||||
runAllExchangeLearningTasks: runAllExchangeLearningTasks,
|
||||
stopAllExchangeLearningTasks: stopAllExchangeLearningTasks,
|
||||
|
||||
runAllMarketDataTasks: runAllMarketDataTasks,
|
||||
stopAllMarketDataTasks: stopAllMarketDataTasks,
|
||||
runAllMarketTradingTasks: runAllMarketTradingTasks,
|
||||
stopAllMarketTradingTasks: stopAllMarketTradingTasks,
|
||||
runAllMarketLearningTasks: runAllMarketLearningTasks,
|
||||
stopAllMarketLearningTasks: stopAllMarketLearningTasks,
|
||||
|
||||
runAllDataMineTasks: runAllDataMineTasks,
|
||||
stopAllDataMineTasks: stopAllDataMineTasks,
|
||||
runAllTradingMineTasks: runAllTradingMineTasks,
|
||||
stopAllTradingMineTasks: stopAllTradingMineTasks,
|
||||
runAllLearningMineTasks: runAllLearningMineTasks,
|
||||
stopAllLearningMineTasks: stopAllLearningMineTasks,
|
||||
|
||||
addMissingProjectDataTasks: addMissingProjectDataTasks,
|
||||
addMissingExchangeDataTasks: addMissingExchangeDataTasks,
|
||||
addMissingMarketDataTasks: addMissingMarketDataTasks,
|
||||
addMissingDataMineTasks: addMissingDataMineTasks,
|
||||
addMissingProjectTradingTasks: addMissingProjectTradingTasks,
|
||||
addMissingExchangeTradingTasks: addMissingExchangeTradingTasks,
|
||||
addMissingMarketTradingTasks: addMissingMarketTradingTasks,
|
||||
addMissingTradingMineTasks: addMissingTradingMineTasks,
|
||||
addMissingProjectLearningTasks: addMissingProjectLearningTasks,
|
||||
addMissingExchangeLearningTasks: addMissingExchangeLearningTasks,
|
||||
addMissingMarketLearningTasks: addMissingMarketLearningTasks,
|
||||
addMissingLearningMineTasks: addMissingLearningMineTasks,
|
||||
|
||||
addAllTasks: addAllTasks
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function syncronizeTaskWithBackEnd(node) {
|
||||
let networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* Nodes that do not belong to a network can not get ready. */
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
/* First we setup everything so as to listen to the response from the Task Manger */
|
||||
let eventSubscriptionIdOnStatus
|
||||
let key = 'Task Client - ' + node.id
|
||||
eventsServerClient.listenToEvent(key, 'Task Status', undefined, node.id, onResponse, onStatus)
|
||||
|
||||
function onResponse(message) {
|
||||
eventSubscriptionIdOnStatus = message.eventSubscriptionId
|
||||
}
|
||||
|
||||
function onStatus(message) {
|
||||
eventsServerClient.stopListening(key, eventSubscriptionIdOnStatus, node.id)
|
||||
if (message.event.status === 'Task Process Running') {
|
||||
node.payload.uiObject.menu.internalClick('Run Task')
|
||||
}
|
||||
}
|
||||
|
||||
/* Second we ask the Task Manager if this Task has a process Running. */
|
||||
let event = {
|
||||
taskId: node.id
|
||||
}
|
||||
|
||||
eventsServerClient.raiseEvent('Task Manager', 'Task Status', event)
|
||||
}
|
||||
|
||||
function runTask(node, isDebugging, callBackFunction) {
|
||||
|
||||
let networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
for (let i = 0; i < node.bot.processes.length; i++) {
|
||||
let process = node.bot.processes[i]
|
||||
process.payload.uiObject.run(eventsServerClient)
|
||||
if (process.session !== undefined) {
|
||||
process.session.payload.uiObject.reset()
|
||||
}
|
||||
}
|
||||
|
||||
let taskLightingPath = '->Task->' +
|
||||
'Sensor Bot Instance->' +
|
||||
'API Data Fetcher Bot Instance->' +
|
||||
'Indicator Bot Instance->Time Frames Filter->' +
|
||||
'Trading Bot Instance->' +
|
||||
'Learning Bot Instance->' +
|
||||
'Sensor Process Instance->API Data Fetcher Process Instance->Indicator Process Instance->Trading Process Instance->Learning Process Instance->' +
|
||||
'Execution Started Event->' +
|
||||
'Key Reference->Exchange Account Key->' +
|
||||
'Task Manager->' +
|
||||
'Data Mine Tasks->Trading Mine Tasks->Learning Mine Tasks->' +
|
||||
'Market Data Tasks->Market Trading Tasks->Market Learning Tasks->' +
|
||||
'Exchange Data Tasks->Exchange Trading Tasks->Exchange Learning Tasks->' +
|
||||
'Market->Exchange Markets->Crypto Exchange->' +
|
||||
'Market Base Asset->Market Quoted Asset->Asset->' +
|
||||
'Project Data Tasks->Project Trading Tasks->Project Learning Tasks->Project Definition->' +
|
||||
'Backtesting Session->Live Trading Session->Paper Trading Session->Forward Testing Session->' +
|
||||
'Back Learning Session->Live Learning Session->' +
|
||||
'Process Definition->' +
|
||||
'Process Output->' +
|
||||
'Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->' +
|
||||
'Output Dataset->Dataset Definition->Product Definition->API Query Parameters->API Query Parameter->API Path Parameters->API Path Parameter->' +
|
||||
'Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->' +
|
||||
'Process Dependencies->' +
|
||||
'Status Dependency->Status Report->Process Definition->' +
|
||||
'Data Mine Data Dependencies->Bot Data Dependencies->' +
|
||||
'Data Dependency Folder->Data Dependency Folder->Data Dependency Folder->Data Dependency Folder->Data Dependency Folder->' +
|
||||
'Data Dependency->Dataset Definition->Product Definition->' +
|
||||
'Record Definition->Record Property->Record Formula->' +
|
||||
'API Response Field Reference->' +
|
||||
'API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->' +
|
||||
'API Response Schema->API Query Response->API Query Responses->API Endpoint->' +
|
||||
'Data Building Procedure->' +
|
||||
'Procedure Initialization->Procedure Javascript Code->' +
|
||||
'Procedure Loop->Procedure Javascript Code->' +
|
||||
'Calculations Procedure->' +
|
||||
'Procedure Initialization->Procedure Javascript Code->' +
|
||||
'Procedure Loop->Procedure Javascript Code->' +
|
||||
'Status Report->' +
|
||||
'Execution Finished Event->' +
|
||||
'Execution Started Event->Execution Finished Event->Process Definition->' +
|
||||
'Sensor Bot->' +
|
||||
'API Data Fetcher Bot->' +
|
||||
'Indicator Bot->' +
|
||||
'Trading Bot->' +
|
||||
'Learning Bot->' +
|
||||
'Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->' +
|
||||
'Data Mine->Trading Mine->Learning Mine->' +
|
||||
'API Map Reference->' +
|
||||
'API Map->API Version->API Endpoint->API Query Parameters->API Query Parameter->API Path Parameters->API Path Parameter->API Query Responses->API Query Response->API Response Schema->' +
|
||||
'API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->API Response Field->'
|
||||
|
||||
let taskDefinition = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(node, false, true, true, false, false, taskLightingPath)
|
||||
|
||||
let networkLightingPath = '->Network->Network Node->' +
|
||||
'Data Storage->' +
|
||||
'Data Mines Data->Trading Mines Data->Learning Mines Data->' +
|
||||
'Project Data Products->Project Trading Products->Project Learning Products->' +
|
||||
'Exchange Data Products->Exchange Trading Products->Exchange Learning Products->' +
|
||||
'Market Data Products->Market Trading Products->Market Learning Products->' +
|
||||
'Market->Market Base Asset->Market Quoted Asset->Asset->' +
|
||||
'Exchange Markets->Crypto Exchange->' +
|
||||
'Data Mine Products->Bot Products->' +
|
||||
'Data Product Folder->Data Product Folder->Data Product Folder->Data Product Folder->Data Product Folder->' +
|
||||
'Data Product->Product Definition->' +
|
||||
'Data Tasks->Learning Tasks->Testing Trading Tasks->Production Trading Tasks->' +
|
||||
'Project Data Tasks->Project Trading Tasks->Project Learning Tasks->' +
|
||||
'Exchange Data Tasks->Exchange Trading Tasks->Exchange Learning Tasks->Crypto Exchange->' +
|
||||
'Market Data Tasks->Market Trading Tasks->Market Learning Tasks->Market->' +
|
||||
'Data Mine Tasks->Trading Mine Tasks->Learning Mine Tasks->' +
|
||||
'Task Manager->Task->' +
|
||||
'Indicator Bot Instance->Sensor Bot Instance->API Data Fetcher Bot Instance->Trading Bot Instance->Learning Bot Instance->' +
|
||||
'Indicator Process Instance->Sensor Process Instance->API Data Fetcher Process Instance->Trading Process Instance->Learning Process Instance->' +
|
||||
'Paper Trading Session->Forward Testing Session->Backtesting Session->Live Trading Session->Back Learning Session->Live Learning Session->' +
|
||||
'API Map Reference->' +
|
||||
'Market->' +
|
||||
'Process Definition->'
|
||||
|
||||
let networkDefinition = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(networkNode.payload.parentNode, false, true, true, false, false, networkLightingPath)
|
||||
|
||||
/*
|
||||
We will also send all the project schemas we have to the Task Server.
|
||||
*/
|
||||
let projectSchemas = []
|
||||
for (let k = 0; k < PROJECTS_SCHEMA.length; k++) {
|
||||
let projectDefinition = PROJECTS_SCHEMA[k]
|
||||
let project = {
|
||||
name: projectDefinition.name,
|
||||
schema: SCHEMAS_BY_PROJECT.get(projectDefinition.name).array.appSchema
|
||||
}
|
||||
projectSchemas.push(project)
|
||||
}
|
||||
let event = {
|
||||
projectSchemas: JSON.stringify(projectSchemas),
|
||||
taskId: node.id,
|
||||
taskName: node.name,
|
||||
taskDefinition: JSON.stringify(taskDefinition),
|
||||
networkDefinition: JSON.stringify(networkDefinition)
|
||||
}
|
||||
|
||||
if (isDebugging === true) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
eventsServerClient.raiseEvent('Task Server', 'Debug Task Started', event)
|
||||
return
|
||||
}
|
||||
|
||||
node.payload.uiObject.run(eventsServerClient, callBackFunction)
|
||||
eventsServerClient.raiseEvent('Task Manager', 'Run Task', event)
|
||||
}
|
||||
|
||||
function stopTask(node, callBackFunction) {
|
||||
let networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
let event = {
|
||||
taskId: node.id,
|
||||
taskName: node.name
|
||||
}
|
||||
|
||||
node.payload.uiObject.stop(callBackFunction, undefined, true)
|
||||
eventsServerClient.raiseEvent('Task Manager', 'Stop Task', event)
|
||||
|
||||
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.stop(undefined, undefined, true)
|
||||
if (process.session !== undefined) {
|
||||
process.session.payload.uiObject.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validations(node) {
|
||||
if (node.bot === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Task needs to have a Bot Instance.')
|
||||
return
|
||||
}
|
||||
if (node.bot.processes.length === 0) {
|
||||
node.payload.uiObject.setErrorMessage('Task Bot Instance needs to have al least once Process Instance.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Task needs to be inside a Task Manager.')
|
||||
return
|
||||
}
|
||||
|
||||
let taskManager = node.payload.parentNode
|
||||
|
||||
if (taskManager.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Task needs to be inside Mine Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Task needs to be inside Market Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Task needs to be inside Exchange Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Task needs to be inside a Data Tasks, Learning Tasks, Testing or Production Trading Tasks node.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Task needs to be inside a Network Node.')
|
||||
return
|
||||
}
|
||||
|
||||
let networkNode = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(taskManager, 'Network Node', undefined, true, false, true, false)
|
||||
|
||||
if (UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(networkNode.payload, 'host') === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Network Node needs to have a valid Host property at its config.')
|
||||
return
|
||||
}
|
||||
|
||||
if (UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(networkNode.payload, 'webPort') === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Network Node needs to have a valid webPort property at its config.')
|
||||
return
|
||||
}
|
||||
|
||||
if (UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(networkNode.payload, 'webSocketsPort') === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Network Node needs to have a valid webSocketsPort property at its config.')
|
||||
return
|
||||
}
|
||||
|
||||
return networkNode
|
||||
}
|
||||
|
||||
function runAllTasks(taskManager) {
|
||||
for (let i = 0; i < taskManager.tasks.length; i++) {
|
||||
let node = taskManager.tasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run Task')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllTasks(taskManager) {
|
||||
for (let i = 0; i < taskManager.tasks.length; i++) {
|
||||
let node = taskManager.tasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop Task')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllTaskManagers(parent) {
|
||||
for (let i = 0; i < parent.taskManagers.length; i++) {
|
||||
let node = parent.taskManagers[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Tasks')
|
||||
menu.internalClick('Run All Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllTaskManagers(parent) {
|
||||
for (let i = 0; i < parent.taskManagers.length; i++) {
|
||||
let node = parent.taskManagers[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Tasks')
|
||||
menu.internalClick('Stop All Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllProjectDataTasks(parent) {
|
||||
for (let i = 0; i < parent.projectDataTasks.length; i++) {
|
||||
let node = parent.projectDataTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Exchange Data Tasks')
|
||||
menu.internalClick('Run All Exchange Data Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllProjectDataTasks(parent) {
|
||||
for (let i = 0; i < parent.projectDataTasks.length; i++) {
|
||||
let node = parent.projectDataTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Exchange Data Tasks')
|
||||
menu.internalClick('Stop All Exchange Data Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllProjectTradingTasks(parent) {
|
||||
for (let i = 0; i < parent.projectTradingTasks.length; i++) {
|
||||
let node = parent.projectTradingTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Exchange Trading Tasks')
|
||||
menu.internalClick('Run All Exchange Trading Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllProjectTradingTasks(parent) {
|
||||
for (let i = 0; i < parent.projectTradingTasks.length; i++) {
|
||||
let node = parent.projectTradingTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Exchange Trading Tasks')
|
||||
menu.internalClick('Stop All Exchange Trading Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllProjectLearningTasks(parent) {
|
||||
for (let i = 0; i < parent.projectLearningTasks.length; i++) {
|
||||
let node = parent.projectLearningTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Exchange Learning Tasks')
|
||||
menu.internalClick('Run All Exchange Learning Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllProjectLearningTasks(parent) {
|
||||
for (let i = 0; i < parent.projectLearningTasks.length; i++) {
|
||||
let node = parent.projectLearningTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Exchange Learning Tasks')
|
||||
menu.internalClick('Stop All Exchange Learning Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllExchangeDataTasks(parent) {
|
||||
for (let i = 0; i < parent.exchangeDataTasks.length; i++) {
|
||||
let node = parent.exchangeDataTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Market Data Tasks')
|
||||
menu.internalClick('Run All Market Data Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllExchangeDataTasks(parent) {
|
||||
for (let i = 0; i < parent.exchangeDataTasks.length; i++) {
|
||||
let node = parent.exchangeDataTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Market Data Tasks')
|
||||
menu.internalClick('Stop All Market Data Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllExchangeTradingTasks(parent) {
|
||||
for (let i = 0; i < parent.exchangeTradingTasks.length; i++) {
|
||||
let node = parent.exchangeTradingTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Market Trading Tasks')
|
||||
menu.internalClick('Run All Market Trading Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllExchangeTradingTasks(parent) {
|
||||
for (let i = 0; i < parent.exchangeTradingTasks.length; i++) {
|
||||
let node = parent.exchangeTradingTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Market Trading Tasks')
|
||||
menu.internalClick('Stop All Market Trading Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllExchangeLearningTasks(parent) {
|
||||
for (let i = 0; i < parent.exchangeLearningTasks.length; i++) {
|
||||
let node = parent.exchangeLearningTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Market Learning Tasks')
|
||||
menu.internalClick('Run All Market Learning Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllExchangeLearningTasks(parent) {
|
||||
for (let i = 0; i < parent.exchangeLearningTasks.length; i++) {
|
||||
let node = parent.exchangeLearningTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Market Learning Tasks')
|
||||
menu.internalClick('Stop All Market Learning Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllMarketDataTasks(parent) {
|
||||
for (let i = 0; i < parent.marketDataTasks.length; i++) {
|
||||
let node = parent.marketDataTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Data Mine Tasks')
|
||||
menu.internalClick('Run All Data Mine Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllMarketDataTasks(parent) {
|
||||
for (let i = 0; i < parent.marketDataTasks.length; i++) {
|
||||
let node = parent.marketDataTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Data Mine Tasks')
|
||||
menu.internalClick('Stop All Data Mine Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllMarketTradingTasks(parent) {
|
||||
for (let i = 0; i < parent.marketTradingTasks.length; i++) {
|
||||
let node = parent.marketTradingTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Trading Mine Tasks')
|
||||
menu.internalClick('Run All Trading Mine Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllMarketLearningTasks(parent) {
|
||||
for (let i = 0; i < parent.marketLearningTasks.length; i++) {
|
||||
let node = parent.marketLearningTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Learning Mine Tasks')
|
||||
menu.internalClick('Run All Learning Mine Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllMarketTradingTasks(parent) {
|
||||
for (let i = 0; i < parent.marketTradingTasks.length; i++) {
|
||||
let node = parent.marketTradingTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Trading Mine Tasks')
|
||||
menu.internalClick('Stop All Trading Mine Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllMarketLearningTasks(parent) {
|
||||
for (let i = 0; i < parent.marketLearningTasks.length; i++) {
|
||||
let node = parent.marketLearningTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Learning Mine Tasks')
|
||||
menu.internalClick('Stop All Learning Mine Tasks')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllDataMineTasks(parent) {
|
||||
for (let i = 0; i < parent.dataMineTasks.length; i++) {
|
||||
let node = parent.dataMineTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Task Managers')
|
||||
menu.internalClick('Run All Task Managers')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllDataMineTasks(parent) {
|
||||
for (let i = 0; i < parent.dataMineTasks.length; i++) {
|
||||
let node = parent.dataMineTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Task Managers')
|
||||
menu.internalClick('Stop All Task Managers')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllTradingMineTasks(parent) {
|
||||
for (let i = 0; i < parent.tradingMineTasks.length; i++) {
|
||||
let node = parent.tradingMineTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Task Managers')
|
||||
menu.internalClick('Run All Task Managers')
|
||||
}
|
||||
}
|
||||
|
||||
function runAllLearningMineTasks(parent) {
|
||||
for (let i = 0; i < parent.learningMineTasks.length; i++) {
|
||||
let node = parent.learningMineTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Run All Task Managers')
|
||||
menu.internalClick('Run All Task Managers')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllTradingMineTasks(parent) {
|
||||
for (let i = 0; i < parent.tradingMineTasks.length; i++) {
|
||||
let node = parent.tradingMineTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Task Managers')
|
||||
menu.internalClick('Stop All Task Managers')
|
||||
}
|
||||
}
|
||||
|
||||
function stopAllLearningMineTasks(parent) {
|
||||
for (let i = 0; i < parent.learningMineTasks.length; i++) {
|
||||
let node = parent.learningMineTasks[i]
|
||||
let menu = node.payload.uiObject.menu
|
||||
|
||||
menu.internalClick('Stop All Task Managers')
|
||||
menu.internalClick('Stop All Task Managers')
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingProjectDataTasks(node, rootNodes) {
|
||||
addMissingProjectTasks(node, rootNodes, 'Project Data Tasks')
|
||||
}
|
||||
|
||||
function addMissingProjectTradingTasks(node, rootNodes) {
|
||||
addMissingProjectTasks(node, rootNodes, 'Project Trading Tasks')
|
||||
}
|
||||
|
||||
function addMissingProjectLearningTasks(node, rootNodes) {
|
||||
addMissingProjectTasks(node, rootNodes, 'Project Learning Tasks')
|
||||
}
|
||||
|
||||
function addMissingProjectTasks(node, rootNodes, newNodeType) {
|
||||
|
||||
for (let k = 0; k < PROJECTS_SCHEMA.length; k++) {
|
||||
let projectDefinition = PROJECTS_SCHEMA[k]
|
||||
let project = projectDefinition.name
|
||||
|
||||
for (let j = 0; j < rootNodes.length; j++) {
|
||||
let rootNode = rootNodes[j]
|
||||
if (rootNode.type === project + ' Project') {
|
||||
let projectDefinition = rootNode.projectDefinition
|
||||
if (projectDefinition !== undefined) {
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, projectDefinition, true) === true) {
|
||||
let projectTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType, undefined, project)
|
||||
projectTasks.payload.referenceParent = projectDefinition
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingExchangeDataTasks(node, rootNodes) {
|
||||
addMissingExchangeTasks(node, rootNodes, 'Exchange Data Tasks')
|
||||
}
|
||||
|
||||
function addMissingExchangeTradingTasks(node, rootNodes) {
|
||||
addMissingExchangeTasks(node, rootNodes, 'Exchange Trading Tasks')
|
||||
}
|
||||
|
||||
function addMissingExchangeLearningTasks(node, rootNodes) {
|
||||
addMissingExchangeTasks(node, rootNodes, 'Exchange Learning Tasks')
|
||||
}
|
||||
|
||||
function addMissingExchangeTasks(node, rootNodes, newNodeType) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Crypto Ecosystem') {
|
||||
let cryptoEcosystem = rootNode
|
||||
for (let j = 0; j < cryptoEcosystem.cryptoExchanges.length; j++) {
|
||||
let cryptoExchanges = cryptoEcosystem.cryptoExchanges[j]
|
||||
for (let k = 0; k < cryptoExchanges.exchanges.length; k++) {
|
||||
let cryptoExchange = cryptoExchanges.exchanges[k]
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, cryptoExchange, true) === true) {
|
||||
let exchangeTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
|
||||
exchangeTasks.payload.referenceParent = cryptoExchange
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingMarketDataTasks(node) {
|
||||
addMissingMarketTasks(node, 'Market Data Tasks')
|
||||
}
|
||||
|
||||
function addMissingMarketTradingTasks(node) {
|
||||
addMissingMarketTasks(node, 'Market Trading Tasks')
|
||||
}
|
||||
|
||||
function addMissingMarketLearningTasks(node) {
|
||||
addMissingMarketTasks(node, 'Market Learning Tasks')
|
||||
}
|
||||
|
||||
function addMissingMarketTasks(node, newNodeType) {
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.referenceParent === undefined) { return }
|
||||
if (node.payload.referenceParent.exchangeMarkets === undefined) { return }
|
||||
|
||||
let markets = node.payload.referenceParent.exchangeMarkets.markets
|
||||
|
||||
for (let i = 0; i < markets.length; i++) {
|
||||
let market = markets[i]
|
||||
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, market, true) === true) {
|
||||
let marketDataTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
|
||||
marketDataTasks.payload.referenceParent = market
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingDataMineTasks(node, rootNodes) {
|
||||
addMissingMineTasks(node, rootNodes, 'Data Mine', 'Data Mine Tasks')
|
||||
}
|
||||
|
||||
function addMissingTradingMineTasks(node, rootNodes) {
|
||||
addMissingMineTasks(node, rootNodes, 'Trading Mine', 'Trading Mine Tasks')
|
||||
}
|
||||
|
||||
function addMissingLearningMineTasks(node, rootNodes) {
|
||||
addMissingMineTasks(node, rootNodes, 'Learning Mine', 'Learning Mine Tasks')
|
||||
}
|
||||
|
||||
function addMissingMineTasks(node, rootNodes, rootNodeType, newNodeType) {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === rootNodeType) {
|
||||
let mine = rootNode
|
||||
|
||||
if (UI.projects.foundations.utilities.children.isMissingChildren(node, mine, true) === true) {
|
||||
let dataMineTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
|
||||
dataMineTasks.payload.referenceParent = mine
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addAllTasks(node, rootNodes) {
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.referenceParent === undefined) { return }
|
||||
|
||||
let taskManager = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Task Manager')
|
||||
taskManager.name = node.payload.referenceParent.name
|
||||
taskManager.payload.floatingObject.collapseToggle()
|
||||
|
||||
switch (node.type) {
|
||||
case 'Data Mine Tasks': {
|
||||
addDataTasks()
|
||||
break
|
||||
}
|
||||
case 'Learning Mine Tasks': {
|
||||
addLearningTasks()
|
||||
break
|
||||
}
|
||||
case 'Trading Mine Tasks': {
|
||||
addTradingTasks()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function addDataTasks() {
|
||||
addTasks()
|
||||
}
|
||||
|
||||
function addLearningTasks() {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Learning System') {
|
||||
addTasks(rootNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addTradingTasks() {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Trading System') {
|
||||
addTasks(rootNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addTasks(systemNode) {
|
||||
let mine = node.payload.referenceParent
|
||||
|
||||
addTasksForBotArray(mine.sensorBots)
|
||||
addTasksForBotArray(mine.apiDataFetcherBots)
|
||||
addTasksForBotArray(mine.indicatorBots)
|
||||
addTasksForBotArray(mine.tradingBots)
|
||||
addTasksForBotArray(mine.learningBots)
|
||||
|
||||
function addTasksForBotArray(botsArray) {
|
||||
if (botsArray === undefined) { return }
|
||||
|
||||
for (let i = 0; i < botsArray.length; i++) {
|
||||
let bot = botsArray[i]
|
||||
|
||||
let botInstance
|
||||
switch (bot.type) {
|
||||
case 'Sensor Bot': {
|
||||
let task = addTask(taskManager)
|
||||
|
||||
botInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Sensor Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
|
||||
addProcessInstance(task, bot, botInstance)
|
||||
break
|
||||
}
|
||||
case 'API Data Fetcher Bot': {
|
||||
let task = addTask(taskManager)
|
||||
|
||||
botInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'API Data Fetcher Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
|
||||
addProcessInstance(task, bot, botInstance)
|
||||
break
|
||||
}
|
||||
case 'Indicator Bot': {
|
||||
let task = addTask(taskManager)
|
||||
|
||||
botInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Indicator Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
|
||||
addProcessInstance(task, bot, botInstance)
|
||||
break
|
||||
}
|
||||
case 'Trading Bot': {
|
||||
let task = addTask(taskManager)
|
||||
|
||||
botInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Trading Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
|
||||
addProcessInstance(task, bot, botInstance)
|
||||
break
|
||||
}
|
||||
case 'Learning Bot': {
|
||||
let task
|
||||
/*
|
||||
For Learning Bots we will add two Tasks, each one with a different
|
||||
Session Type.
|
||||
*/
|
||||
task = addTask(taskManager)
|
||||
task.name = 'Back ' + task.name
|
||||
|
||||
botInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Learning Bot Instance')
|
||||
botInstance.name = 'Back ' + bot.name
|
||||
|
||||
addProcessInstance(task, bot, botInstance, 'Back Learning Session')
|
||||
|
||||
task = addTask(taskManager)
|
||||
task.name = 'Live ' + task.name
|
||||
|
||||
botInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Learning Bot Instance')
|
||||
botInstance.name = 'Live ' + bot.name
|
||||
|
||||
addProcessInstance(task, bot, botInstance, 'Live Learning Session')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function addTask(taskManager) {
|
||||
let task = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(taskManager, 'Task')
|
||||
|
||||
if (systemNode !== undefined) {
|
||||
task.name = systemNode.name
|
||||
} else {
|
||||
task.name = bot.name
|
||||
}
|
||||
return task
|
||||
}
|
||||
|
||||
function addProcessInstance(task, bot, botInstance, sessionType) {
|
||||
for (let j = 0; j < bot.processes.length; j++) {
|
||||
let process = bot.processes[j]
|
||||
let processInstance
|
||||
switch (bot.type) {
|
||||
case 'Sensor Bot': {
|
||||
processInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'Sensor Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
break
|
||||
}
|
||||
case 'API Data Fetcher Bot': {
|
||||
processInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'API Data Fetcher Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
|
||||
/*
|
||||
We will locate and reference the API MAP that has the same codeName than the data mine.
|
||||
*/
|
||||
let apiMaps = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('API Map')
|
||||
for (let i = 0; i < apiMaps.length; i++) {
|
||||
let apiMap = apiMaps[i]
|
||||
let apiMapCodeName = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(apiMap.payload, 'codeName')
|
||||
let mineCodeName = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(mine.payload, 'codeName')
|
||||
|
||||
if (apiMapCodeName === mineCodeName) {
|
||||
processInstance.apiMapReference.payload.referenceParent = apiMap
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'Indicator Bot': {
|
||||
processInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'Indicator Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
break
|
||||
}
|
||||
case 'Trading Bot': {
|
||||
processInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'Trading Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
|
||||
if (node.payload.parentNode === undefined) { return }
|
||||
if (node.payload.parentNode.payload === undefined) { return }
|
||||
if (node.payload.parentNode.payload.parentNode === undefined) { return }
|
||||
if (node.payload.parentNode.payload.parentNode.payload === undefined) { return }
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { return }
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { return }
|
||||
|
||||
let environment = node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
let session
|
||||
|
||||
switch (environment.type) {
|
||||
case 'Testing Trading Tasks': {
|
||||
addSession('Backtesting Session')
|
||||
break
|
||||
}
|
||||
case 'Production Trading Tasks': {
|
||||
addSession('Live Trading Session')
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
function addSession(sessionType) {
|
||||
session = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(processInstance, sessionType)
|
||||
session.name = task.name
|
||||
let config = JSON.parse(session.config)
|
||||
config.folderName = session.name.split(" ").join("-")
|
||||
session.config = JSON.stringify(config)
|
||||
|
||||
for (let m = 0; m < rootNodes.length; m++) {
|
||||
let rootNode = rootNodes[m]
|
||||
if (rootNode.type === 'Trading Engine' && rootNode.isPlugin === true) {
|
||||
let tradingEngine = rootNode
|
||||
session.tradingEngineReference.payload.referenceParent = tradingEngine
|
||||
session.tradingSystemReference.payload.referenceParent = systemNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'Learning Bot': {
|
||||
processInstance = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'Learning Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
|
||||
let session
|
||||
addSession(sessionType)
|
||||
break
|
||||
|
||||
function addSession(sessionType) {
|
||||
session = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(processInstance, sessionType)
|
||||
session.name = task.name
|
||||
let config = JSON.parse(session.config)
|
||||
config.folderName = session.name.split(" ").join("-")
|
||||
session.config = JSON.stringify(config)
|
||||
|
||||
for (let m = 0; m < rootNodes.length; m++) {
|
||||
let rootNode = rootNodes[m]
|
||||
if (rootNode.type === 'Learning Engine' && rootNode.isPlugin === true) {
|
||||
let learningEngine = rootNode
|
||||
session.learningEngineReference.payload.referenceParent = learningEngine
|
||||
session.learningSystemReference.payload.referenceParent = systemNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
processInstance.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
function newFoundationsFunctionLibraryTradingSessionFunctions() {
|
||||
let thisObject = {
|
||||
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
|
||||
runSession: runSession,
|
||||
stopSession: stopSession
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function syncronizeSessionWithBackEnd(node) {
|
||||
let validationsResult = validations(node)
|
||||
if (validationsResult === undefined) {
|
||||
/* If something fails at validations we just quit. */
|
||||
return
|
||||
}
|
||||
let networkNode = validationsResult.networkNode
|
||||
if (networkNode === undefined) {
|
||||
/* Nodes that do not belong to a network can not get ready. */
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
/* First we setup everything so as to listen to the response from the Task Server */
|
||||
let eventSubscriptionIdOnStatus
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
eventsServerClient.listenToEvent(key, 'Status Response', undefined, node.id, onResponse, onStatus)
|
||||
|
||||
function onResponse(message) {
|
||||
eventSubscriptionIdOnStatus = message.eventSubscriptionId
|
||||
}
|
||||
|
||||
function onStatus(message) {
|
||||
eventsServerClient.stopListening(key, eventSubscriptionIdOnStatus, node.id)
|
||||
if (message.event.status === 'Trading Session Runnning') {
|
||||
node.payload.uiObject.menu.internalClick('Run Trading Session')
|
||||
}
|
||||
}
|
||||
|
||||
/* Second we ask the Task Server if this Session is Running. */
|
||||
eventsServerClient.raiseEvent(key, 'Trading Session Status')
|
||||
}
|
||||
|
||||
function runSession(node, resume, callBackFunction) {
|
||||
let validationsResult = validations(node)
|
||||
if (validationsResult === undefined) {
|
||||
/* If something fails at validations we just quit. */
|
||||
return
|
||||
}
|
||||
let networkNode = validationsResult.networkNode
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
|
||||
/* Setup Listener to check Parent Task Status of the Session */
|
||||
let eventSubscriptionIdOnStatus
|
||||
let eventHandlerKey = "Task Client - " + node.payload.parentNode.payload.parentNode.payload.parentNode.id
|
||||
|
||||
eventsServerClient.listenToEvent(eventHandlerKey, 'Task Status', undefined, node.id, onResponse, onStatus)
|
||||
|
||||
function onResponse(message) {
|
||||
eventSubscriptionIdOnStatus = message.eventSubscriptionId
|
||||
}
|
||||
|
||||
function onStatus(message) {
|
||||
eventsServerClient.stopListening(eventHandlerKey, eventSubscriptionIdOnStatus, node.id)
|
||||
|
||||
/* If Task is Not Running Display Error */
|
||||
if (message.event.status === 'Task Process Not Running') {
|
||||
node.payload.uiObject.setErrorMessage('Parent Task Not Running.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
} else {
|
||||
node.payload.uiObject.run(eventsServerClient, callBackFunction)
|
||||
}
|
||||
}
|
||||
|
||||
/* Raise Event to Check Task Status */
|
||||
let eventKey = {}
|
||||
eventKey.taskId = node.payload.parentNode.payload.parentNode.payload.parentNode.id
|
||||
|
||||
eventsServerClient.raiseEvent("Task Manager", 'Task Status', eventKey)
|
||||
|
||||
let lightingPath = '' +
|
||||
'Trading System->' +
|
||||
'Dynamic Indicators->Indicator Function->Formula->' +
|
||||
'Trading Strategy->' +
|
||||
'Trigger Stage->Trigger On Event->Trigger Off Event->Take Position Event->' +
|
||||
'Open Stage->' +
|
||||
'Manage Stage->' +
|
||||
'Managed Stop Loss->Managed Take Profit->' +
|
||||
'Phase->Formula->Next Phase Event->Move To Phase Event->Phase->' +
|
||||
'Situation->Condition->Javascript Code->' +
|
||||
'Close Stage->' +
|
||||
'Initial Targets->Target Size In Base Asset->Target Size In Quoted Asset->Target Rate->Formula->' +
|
||||
'Open Execution->Close Execution->' +
|
||||
'Execution Algorithm->Market Buy Order->Market Sell Order->Limit Buy Order->Limit Sell Order->' +
|
||||
'Order Rate->Formula->' +
|
||||
'Create Order Event->Cancel Order Event->' +
|
||||
'Close Stage Event->' +
|
||||
'Announcement->Announcement Formula->Announcement Condition->' +
|
||||
'Size In Base Asset->Size In Quoted Asset->Position Rate->Formula->' +
|
||||
'Situation->Condition->Javascript Code->' +
|
||||
'Market Order->Limit Order->' +
|
||||
'Simulated Exchange Events->Simulated Partial Fill->Simulated Actual Rate->Simulated Fees Paid->Formula->' +
|
||||
'User Defined Code->Javascript Code->'
|
||||
|
||||
let tradingSystem = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(node.tradingSystemReference.payload.referenceParent, false, true, true, false, false, lightingPath)
|
||||
|
||||
lightingPath = '' +
|
||||
'Trading Engine->' +
|
||||
'Dynamic Indicators->Indicator Function->' +
|
||||
'Trading Current->Trading Last->Previous->' +
|
||||
'Trading Episode->' +
|
||||
'Episode Base Asset->Episode Quoted Asset->Trading Episode Counters->Trading Episode Statistics->' +
|
||||
'Strategies->Positions->Orders->Hits->Fails->' +
|
||||
'Profit Loss->Hit Ratio->Hit Fail->Days->ROI->Annualized Rate Of Return->User Defined Statistic->' +
|
||||
'Candle->Cycle->' +
|
||||
'Begin->End->Last Begin->Last End->Open->Close->Min->Max->Index->' +
|
||||
'Distance To Trading Event->' +
|
||||
'Head Of The Market->Process Date->' +
|
||||
'Trigger On->Trigger Off->Take Position->Close Position->Next Phase->Move To Phase->Create Order->Cancel Order->Close Order->' +
|
||||
'Strategy->' +
|
||||
'Strategy Counters->' +
|
||||
'Position->' +
|
||||
'Entry Target Rate->Exit Target Rate->' +
|
||||
'Stop Loss->Stop Loss Phase->Stop Loss Position->Begin->End->Initial Value->Final Value->' +
|
||||
'Take Profit->Take Profit Phase->Take Profit Position->Begin->End->Initial Value->Final Value->' +
|
||||
'Position Counters->' +
|
||||
'Position Statistics->Days->User Defined Statistic->' +
|
||||
'Position Base Asset->Position Quoted Asset->Entry Target Size->Exit Target Size->' +
|
||||
'Profit Loss->ROI->Hit Fail->' +
|
||||
'Exchange Orders->Market Buy Orders->Market Sell Orders->Limit Buy Orders->Limit Sell Orders->' +
|
||||
'Market Order->Limit Order->' +
|
||||
'Exchange Id->Rate->Order Name->Algorithm Name->Lock->' +
|
||||
'Order Counters->' +
|
||||
'Order Base Asset->Order Quoted Asset->' +
|
||||
'Actual Size->Size->Size Filled->Amount Received->Fees Paid->Fees To Be Paid->' +
|
||||
'Order Statistics->Percentage Filled->Actual Rate->Days->User Defined Statistic->' +
|
||||
'Strategy Trigger Stage->Strategy Open Stage->Strategy Manage Stage->Strategy Close Stage->' +
|
||||
'Begin->End->Exit Type->Status->Begin Rate->End Rate->Stage Base Asset->Stage Quoted Asset->Size Placed->Target Size->Size Filled->Fees Paid->Stage Defined In->' +
|
||||
'Serial Number->Identifier->Begin->End->Begin Rate->End Rate->Strategy Name->Status->Exit Type->' +
|
||||
'Balance->Begin Balance->End Balance->' +
|
||||
'Index->Situation Name->Formula->Periods->' +
|
||||
'User Defined Variables->User Defined Variable->'
|
||||
|
||||
let tradingEngine = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(node.tradingEngineReference.payload.referenceParent, false, true, true, false, false, lightingPath)
|
||||
|
||||
lightingPath = '' +
|
||||
'Backtesting Session->Paper Trading Session->Forward Testing Session->Live Trading Session->' +
|
||||
'Trading Parameters->' +
|
||||
'Session Base Asset->Session Quoted Asset->Time Range->Time Frame->Slippage->Fee Structure->Snapshots->Heartbeats->User Defined Parameters->' +
|
||||
'Social Bots->Telegram Bot->Discord Bot->Slack Bot->' +
|
||||
'Social Bot Command->Formula->' +
|
||||
'Exchange Account Asset->Asset->'
|
||||
|
||||
let session = UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(node, false, true, true, false, false, lightingPath)
|
||||
|
||||
let defaultExchange = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(validationsResult.exchange.payload, 'codeName')
|
||||
let defaultMarket =
|
||||
UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(validationsResult.market.baseAsset.payload.referenceParent.payload, 'codeName')
|
||||
+ '-' +
|
||||
UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(validationsResult.market.quotedAsset.payload.referenceParent.payload, 'codeName')
|
||||
|
||||
let dependencyFilter = UI.projects.foundations.functionLibraries.dependenciesFilter.createDependencyFilter(
|
||||
defaultExchange,
|
||||
defaultMarket,
|
||||
node.tradingSystemReference.payload.referenceParent
|
||||
)
|
||||
|
||||
/* Raise event to run the session */
|
||||
let event = {
|
||||
session: JSON.stringify(session),
|
||||
tradingSystem: JSON.stringify(tradingSystem),
|
||||
tradingEngine: JSON.stringify(tradingEngine),
|
||||
dependencyFilter: JSON.stringify(dependencyFilter),
|
||||
resume: resume
|
||||
}
|
||||
|
||||
if (resume !== true) {
|
||||
eventsServerClient.raiseEvent(key, 'Run Trading Session', event)
|
||||
} else {
|
||||
eventsServerClient.raiseEvent(key, 'Resume Trading Session', event)
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function stopSession(node, callBackFunction) {
|
||||
let validationsResult = validations(node)
|
||||
if (validationsResult === undefined) {
|
||||
/* If something fails at validations we just quit. */
|
||||
return
|
||||
}
|
||||
let networkNode = validationsResult.networkNode
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
eventsServerClient.raiseEvent(key, 'Stop Trading Session')
|
||||
|
||||
node.payload.uiObject.stop(callBackFunction, undefined, true)
|
||||
}
|
||||
|
||||
function validations(node) {
|
||||
|
||||
let result = {}
|
||||
|
||||
if (node.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs a Process Instance parent to be able to run.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Process Instance node.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Task.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Task Manager.')
|
||||
return
|
||||
}
|
||||
|
||||
result.taskManager = node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
|
||||
if (result.taskManager.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Mine Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Market Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Exchange Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Testing or Production Trading Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Network Node.')
|
||||
return
|
||||
}
|
||||
|
||||
result.networkNode = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(result.taskManager, 'Network Node', undefined, true, false, true, false)
|
||||
|
||||
if (node.tradingSystemReference === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs a child Trading System Reference.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.tradingEngineReference === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs a child Trading Engine Reference.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.tradingSystemReference.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Trading System Reference needs to reference a Trading System.')
|
||||
return
|
||||
}
|
||||
|
||||
if (node.tradingEngineReference.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Trading Engine Reference needs to reference a Trading Engine.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.taskManager.payload.parentNode.payload.parentNode.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to have a Default Market.')
|
||||
return
|
||||
}
|
||||
|
||||
result.market = result.taskManager.payload.parentNode.payload.parentNode.payload.referenceParent
|
||||
|
||||
if (result.market.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Default Market needs to be a child of Exchange Markets.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Exchange Markets neeed to be a child of Crypto Exchange.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.baseAsset === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Default Market needs to have a Base Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.quotedAsset === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Default Market needs to have a Quoted Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.baseAsset.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Market Base Asset needs to reference an Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
if (result.market.quotedAsset.payload.referenceParent === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Market Quoted Asset needs to reference an Asset.')
|
||||
return
|
||||
}
|
||||
|
||||
result.exchange = result.market.payload.parentNode.payload.parentNode
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,742 @@
|
||||
function newFoundationsFunctionLibraryUiObjectsFromNodes() {
|
||||
let thisObject = {
|
||||
syncronizeTasksFoundAtWorkspaceWithBackEnd: syncronizeTasksFoundAtWorkspaceWithBackEnd,
|
||||
syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd: syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd,
|
||||
syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd: syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd,
|
||||
playTutorials: playTutorials,
|
||||
recreateWorkspace: recreateWorkspace,
|
||||
getNodeById: getNodeById,
|
||||
tryToConnectChildrenWithReferenceParents: tryToConnectChildrenWithReferenceParents,
|
||||
createUiObjectFromNode: createUiObjectFromNode,
|
||||
addUIObject: addUIObject,
|
||||
addMissingChildren: addMissingChildren
|
||||
}
|
||||
|
||||
let mapOfReferenceChildren = new Map()
|
||||
let mapOfNodes
|
||||
let tasksFoundAtWorkspace
|
||||
let tradingSessionsFoundAtWorkspace
|
||||
let learningSessionsFoundAtWorkspace
|
||||
let tutorialsToPlay
|
||||
|
||||
return thisObject
|
||||
|
||||
function getNodeById(nodeId) {
|
||||
return mapOfNodes.get(nodeId)
|
||||
}
|
||||
|
||||
function recreateWorkspace(node, callBackFunction) {
|
||||
mapOfNodes = new Map()
|
||||
tasksFoundAtWorkspace = []
|
||||
tradingSessionsFoundAtWorkspace = []
|
||||
learningSessionsFoundAtWorkspace = []
|
||||
tutorialsToPlay = []
|
||||
|
||||
removeNullRootNodes()
|
||||
|
||||
function removeNullRootNodes() {
|
||||
for (let i = 0; i < node.rootNodes.length; i++) {
|
||||
let rootNode = node.rootNodes[i]
|
||||
if (rootNode === null) {
|
||||
node.rootNodes.splice(i, 1)
|
||||
removeNullRootNodes()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addPluginNodes()
|
||||
|
||||
function addPluginNodes(pluginNames) {
|
||||
UI.projects.foundations.utilities.statusBar.changeStatus("Loading Plugins...")
|
||||
|
||||
let blobService = newFileStorage()
|
||||
let totalPlugin = 0
|
||||
let totalRead = 0
|
||||
|
||||
for (let i = 0; i < node.rootNodes.length; i++) {
|
||||
let rootNode = node.rootNodes[i]
|
||||
if (rootNode.type === 'Plugins') {
|
||||
let plugins = rootNode
|
||||
|
||||
if (plugins.pluginProjects === undefined) { continue }
|
||||
for (let j = 0; j < plugins.pluginProjects.length; j++) {
|
||||
let project = plugins.pluginProjects[j]
|
||||
if (project.pluginDataMines !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginDataMines.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginDataMines.pluginFiles, 'Data-Mines')
|
||||
}
|
||||
if (project.pluginTradingMines !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginTradingMines.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginTradingMines.pluginFiles, 'Trading-Mines')
|
||||
}
|
||||
if (project.pluginTradingSystems !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginTradingSystems.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginTradingSystems.pluginFiles, 'Trading-Systems')
|
||||
}
|
||||
if (project.pluginTradingEngines !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginTradingEngines.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginTradingEngines.pluginFiles, 'Trading-Engines')
|
||||
}
|
||||
if (project.pluginLearningMines !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginLearningMines.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginLearningMines.pluginFiles, 'Learning-Mines')
|
||||
}
|
||||
if (project.pluginLearningSystems !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginLearningSystems.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginLearningSystems.pluginFiles, 'Learning-Systems')
|
||||
}
|
||||
if (project.pluginLearningEngines !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginLearningEngines.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginLearningEngines.pluginFiles, 'Learning-Engines')
|
||||
}
|
||||
if (project.pluginTutorials !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginTutorials.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginTutorials.pluginFiles, 'Tutorials')
|
||||
}
|
||||
if (project.pluginApiMaps !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginApiMaps.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginApiMaps.pluginFiles, 'API-Maps')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
If there is no Plugins node at the workspace, we load it anyways here.
|
||||
*/
|
||||
if (totalPlugin === 0) {
|
||||
addUserDefinedNodes()
|
||||
}
|
||||
|
||||
function pluginAllTheseFiles(pluginFiles, pluginType) {
|
||||
for (let i = 0; i < pluginFiles.length; i++) {
|
||||
let pluginFile = pluginFiles[i]
|
||||
let name = pluginFile.name
|
||||
httpRequest(undefined, 'LoadPlugin' + '/' + 'Foundations' + '/' + pluginType + '/' + name + '.json', onFileReceived)
|
||||
|
||||
function onFileReceived(err, text, response) {
|
||||
|
||||
if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
console.log('[WARN] Cannot load plugin ' + pluginType + ' ' + name + '. The Workspace will be loaded with this plugin file missing.')
|
||||
} else {
|
||||
let receivedNode = JSON.parse(text)
|
||||
/*
|
||||
If the workspace already contains a root node with the id of the head of the hirierchy
|
||||
we are loading, we remove it because the plugin file has precedende.
|
||||
*/
|
||||
for (let i = 0; i < node.rootNodes.length; i++) {
|
||||
let rootNode = node.rootNodes[i]
|
||||
if (rootNode.id === receivedNode.id) {
|
||||
node.rootNodes.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
receivedNode.isPlugin = true
|
||||
|
||||
if (pluginFile.pluginFilePosition !== undefined) {
|
||||
let positionOffset = {
|
||||
x: pluginFile.pluginFilePosition.savedPayload.position.x - receivedNode.savedPayload.position.x,
|
||||
y: pluginFile.pluginFilePosition.savedPayload.position.y - receivedNode.savedPayload.position.y
|
||||
}
|
||||
receivedNode.positionOffset = positionOffset
|
||||
}
|
||||
|
||||
node.rootNodes.unshift(receivedNode)
|
||||
}
|
||||
|
||||
totalRead++
|
||||
if (totalPlugin === totalRead) {
|
||||
addUserDefinedNodes()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addUserDefinedNodes() {
|
||||
/* Create the workspace UI OBject and then continue with the root nodes. */
|
||||
createUiObject(false, 'Workspace', node.name, node, undefined, undefined, 'Workspace')
|
||||
if (node.rootNodes !== undefined) {
|
||||
UI.projects.foundations.utilities.statusBar.changeStatus("Setting up Rootnodes...")
|
||||
|
||||
let rootNode
|
||||
let i = -1
|
||||
controlLoop()
|
||||
|
||||
function loopBody() {
|
||||
createUiObjectFromNode(rootNode, undefined, undefined)
|
||||
controlLoop()
|
||||
}
|
||||
|
||||
function controlLoop() {
|
||||
i++
|
||||
if (i < node.rootNodes.length) {
|
||||
rootNode = node.rootNodes[i]
|
||||
UI.projects.foundations.utilities.statusBar.changeStatus("Connecting children nodes from " + rootNode.name + " - " + rootNode.type + "...")
|
||||
setTimeout(loopBody, 100)
|
||||
} else {
|
||||
UI.projects.foundations.utilities.statusBar.changeStatus("Finished connecting all nodes.")
|
||||
setTimeout(endLoop, 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
function endLoop() {
|
||||
tryToConnectChildrenWithReferenceParents()
|
||||
|
||||
if (callBackFunction !== undefined) {
|
||||
callBackFunction() // The recreation of the workspace is complete
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function syncronizeTasksFoundAtWorkspaceWithBackEnd() {
|
||||
for (let i = 0; i < tasksFoundAtWorkspace.length; i++) {
|
||||
let node = tasksFoundAtWorkspace[i]
|
||||
UI.projects.foundations.functionLibraries.taskFunctions.syncronizeTaskWithBackEnd(node)
|
||||
}
|
||||
tasksFoundAtWorkspace = undefined
|
||||
}
|
||||
|
||||
function syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd() {
|
||||
for (let i = 0; i < tradingSessionsFoundAtWorkspace.length; i++) {
|
||||
let node = tradingSessionsFoundAtWorkspace[i]
|
||||
UI.projects.foundations.functionLibraries.tradingSessionFunctions.syncronizeSessionWithBackEnd(node)
|
||||
}
|
||||
tradingSessionsFoundAtWorkspace = undefined
|
||||
}
|
||||
|
||||
function syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd() {
|
||||
for (let i = 0; i < learningSessionsFoundAtWorkspace.length; i++) {
|
||||
let node = learningSessionsFoundAtWorkspace[i]
|
||||
UI.projects.foundations.functionLibraries.tradingSessionFunctions.syncronizeSessionWithBackEnd(node)
|
||||
}
|
||||
learningSessionsFoundAtWorkspace = undefined
|
||||
}
|
||||
|
||||
function playTutorials() {
|
||||
for (let i = 0; i < tutorialsToPlay.length; i++) {
|
||||
let node = tutorialsToPlay[i]
|
||||
node.payload.uiObject.menu.internalClick('Play Tutorial')
|
||||
}
|
||||
tutorialsToPlay = undefined
|
||||
}
|
||||
|
||||
function tryToConnectChildrenWithReferenceParents() {
|
||||
/* We reconstruct here the reference relationships. */
|
||||
for (const [key, node] of mapOfNodes) {
|
||||
if (node.id === "54854f90-d121-4365-8f40-9a26e7af1097") {
|
||||
console.log('ACA')
|
||||
}
|
||||
if (node.payload === undefined) { continue }
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
if (node.payload.referenceParent.cleaned === true) {
|
||||
node.payload.referenceParent = mapOfNodes.get(node.payload.referenceParent.id)
|
||||
if (node.payload.referenceParent === undefined) {
|
||||
//console.log('[WARN]' + node.type + ' ' + node.name + ' reference parent lost during re-binding phase.')
|
||||
}
|
||||
continue // We were referencing a deleted node, so we replace it potentially with a newly created one.
|
||||
} else {
|
||||
continue // In this case the reference is already good.
|
||||
}
|
||||
}
|
||||
if (node.savedPayload !== undefined) {
|
||||
if (node.savedPayload.referenceParent !== undefined) { // these are children recreated
|
||||
node.payload.referenceParent = mapOfNodes.get(node.savedPayload.referenceParent.id)
|
||||
if (node.payload.referenceParent === undefined) {
|
||||
//console.log('[WARN]' + node.type + ' ' + node.name + ' reference parent lost during re-binding phase.')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function migrateCodeToConfig(node, schemaDocument) {
|
||||
/* Code needed to Migrante from Beta 5 to Beta a Workspace */
|
||||
if (schemaDocument.editors !== undefined) {
|
||||
if (schemaDocument.editors.config === true) {
|
||||
if (node.code !== undefined) {
|
||||
node.config = node.code
|
||||
node.code = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createUiObjectFromNode(node, parentNode, chainParent, positionOffset) {
|
||||
|
||||
/* Migration code from beta 10 to beta 11 */
|
||||
if (
|
||||
node.type === 'Tutorial' ||
|
||||
node.type === 'Tutorial Topic' ||
|
||||
node.type === 'Tutorial Step'
|
||||
) {
|
||||
node.project = "Education"
|
||||
}
|
||||
|
||||
if (
|
||||
node.project === undefined ||
|
||||
node.project === 'Superalgos'
|
||||
) {
|
||||
node.project = 'Foundations'
|
||||
}
|
||||
/*
|
||||
This function can be called with a positionOffset to change the node
|
||||
saved position and all of its descendants positions as well with an
|
||||
offset. It can also happen that the positionOffset is defined as a property
|
||||
of the node, in which case it will produce exactly the same effect.
|
||||
*/
|
||||
if (node.positionOffset !== undefined) {
|
||||
positionOffset = node.positionOffset
|
||||
}
|
||||
|
||||
|
||||
/* Get schema document */
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument !== undefined) {
|
||||
migrateCodeToConfig(node, schemaDocument)
|
||||
|
||||
/* Resolve Initial Values */
|
||||
if (schemaDocument.initialValues !== undefined) {
|
||||
if (schemaDocument.initialValues.code !== undefined) {
|
||||
if (node.code === undefined) {
|
||||
node.code = schemaDocument.initialValues.code
|
||||
}
|
||||
}
|
||||
if (schemaDocument.initialValues.config !== undefined) {
|
||||
if (node.config === undefined) {
|
||||
node.config = schemaDocument.initialValues.config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* For the cases where an node is not chained to its parent but to the one at the parent before it at its collection */
|
||||
if (schemaDocument.chainedToSameType === true) {
|
||||
if (parentNode !== undefined) {
|
||||
let parentSchemaDocument = getSchemaDocument(parentNode)
|
||||
if (parentSchemaDocument !== undefined) {
|
||||
if (parentSchemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < parentSchemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = parentSchemaDocument.childrenNodesProperties[i]
|
||||
if (property.childType === node.type) {
|
||||
if (property.type === 'array') {
|
||||
if (parentNode[property.name] !== undefined) {
|
||||
if (parentNode[property.name].length > 1) {
|
||||
let nodeChildren = parentNode[property.name]
|
||||
for (let j = 0; j < nodeChildren.length; j++) {
|
||||
if (node.id === nodeChildren[j].id) {
|
||||
if (j > 0) {
|
||||
chainParent = nodeChildren[j - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Create Self */
|
||||
createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset)
|
||||
|
||||
/* Create Children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
if (node[property.name] !== undefined) {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
createUiObjectFromNode(node[property.name], node, node, positionOffset)
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = node[property.name]
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let arrayItem = nodePropertyArray[m]
|
||||
createUiObjectFromNode(arrayItem, node, node, positionOffset)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if (property.type === 'array') {
|
||||
node[property.name] = []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addUIObject(parentNode, type, rootNodes, project) {
|
||||
if (project === undefined) { project = parentNode.project }
|
||||
|
||||
let object = {
|
||||
name: 'New ' + type,
|
||||
type: type,
|
||||
project: project
|
||||
}
|
||||
|
||||
let parentSchemaDocument
|
||||
/* Resolve Initial Values */
|
||||
let schemaDocument = getSchemaDocument(object, project)
|
||||
|
||||
if (schemaDocument === undefined) {
|
||||
console.log('Cannot addUIOBject of ' + type + ' because that type it is not defined at the APP_SCHEMA.')
|
||||
return
|
||||
}
|
||||
|
||||
if (schemaDocument.initialValues !== undefined) {
|
||||
if (schemaDocument.initialValues.code !== undefined) {
|
||||
object.code = schemaDocument.initialValues.code
|
||||
}
|
||||
}
|
||||
if (schemaDocument.initialValues !== undefined) {
|
||||
if (schemaDocument.initialValues.config !== undefined) {
|
||||
object.config = schemaDocument.initialValues.config
|
||||
}
|
||||
}
|
||||
|
||||
let chainParent = parentNode
|
||||
if (schemaDocument.isHierarchyHead === true || schemaDocument.isProjectHead) {
|
||||
rootNodes.push(object)
|
||||
initializeArrayProperties()
|
||||
applyInitialValues()
|
||||
createUiObject(true, object.type, object.name, object, parentNode, undefined)
|
||||
autoAddChildren()
|
||||
return object
|
||||
|
||||
} else {
|
||||
|
||||
parentSchemaDocument = getSchemaDocument(parentNode, parentNode.project)
|
||||
if (parentSchemaDocument === undefined) {
|
||||
console.log('Cannot addUIOBject from parent of ' + type + ' because that type it is not defined at the APP_SCHEMA.')
|
||||
return
|
||||
}
|
||||
checkChainToSelfTypeCollection()
|
||||
initializeArrayProperties()
|
||||
applyInitialValues()
|
||||
connectToParent()
|
||||
createUiObject(true, object.type, object.name, object, parentNode, chainParent)
|
||||
autoAddChildren()
|
||||
return object
|
||||
}
|
||||
|
||||
function checkChainToSelfTypeCollection() {
|
||||
/* For the cases where a node is not chained to its parent but to the one at the parent before it at its own collection */
|
||||
|
||||
if (schemaDocument.chainedToSameType === true) {
|
||||
if (parentSchemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < parentSchemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = parentSchemaDocument.childrenNodesProperties[i]
|
||||
if (property.childType === type) {
|
||||
if (property.type === 'array') {
|
||||
if (parentNode[property.name] !== undefined) {
|
||||
if (parentNode[property.name].length > 0) {
|
||||
let nodeChildren = parentNode[property.name]
|
||||
chainParent = nodeChildren[nodeChildren.length - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeArrayProperties() {
|
||||
/* Create Empty Arrays for properties of type Array */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
if (property.type === 'array') {
|
||||
object[property.name] = []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function applyInitialValues() {
|
||||
if (schemaDocument.initialValues !== undefined) {
|
||||
if (schemaDocument.initialValues.code !== undefined) {
|
||||
object.code = schemaDocument.initialValues.code
|
||||
}
|
||||
if (schemaDocument.initialValues.config !== undefined) {
|
||||
object.config = schemaDocument.initialValues.config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function connectToParent() {
|
||||
/* Connect to Parent */
|
||||
if (parentSchemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < parentSchemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = parentSchemaDocument.childrenNodesProperties[i]
|
||||
if (property.childType === type) {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
parentNode[property.name] = object
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
if (parentNode[property.name] === undefined) {
|
||||
parentNode[property.name] = []
|
||||
}
|
||||
if (property.maxItems !== undefined) {
|
||||
if (parentNode[property.name].length < property.maxItems) {
|
||||
parentNode[property.name].push(object)
|
||||
} else {
|
||||
return // Object can not be created.
|
||||
}
|
||||
} else {
|
||||
parentNode[property.name].push(object)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function autoAddChildren() {
|
||||
/* Auto Add more Children */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (property.autoAdd === true) {
|
||||
let project = property.project
|
||||
addUIObject(object, property.childType, undefined, project)
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
if (property.autoAdd === true) {
|
||||
if (object[property.name] === undefined) {
|
||||
object[property.name] = []
|
||||
}
|
||||
let project = property.project
|
||||
addUIObject(object, property.childType, undefined, project)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingChildren(node, rootNodes) {
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
|
||||
/* Connect to Parent */
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
if (property.type === 'node') {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (node[property.name] === undefined) {
|
||||
addUIObject(node, property.childType, rootNodes)
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createUiObject(userAddingNew, uiObjectType, name, node, parentNode, chainParent, title, positionOffset) {
|
||||
let payload = {}
|
||||
|
||||
/* Mechanism related to keeping references when cloning */
|
||||
if (node.id === undefined) {
|
||||
node.id = newUniqueId()
|
||||
} else {
|
||||
/*
|
||||
We need to avoid nodes having the same id. If we add nodes to a workspace that already exist with the same Id,
|
||||
the nodes being added will get a new id at this moment.
|
||||
*/
|
||||
let testNode = mapOfNodes.get(node.id)
|
||||
if (testNode !== undefined && testNode.cleaned !== true) {
|
||||
node.id = newUniqueId()
|
||||
console.log(testNode.name + ' already have the id of the node ' + node.name + ' being added. Creating a new id for it: ' + node.id)
|
||||
}
|
||||
}
|
||||
|
||||
/* Default Naming */
|
||||
if (name === '' || name === undefined) { name = 'My ' + uiObjectType }
|
||||
|
||||
/* If we are creating this object as the result of restoring a backup, share or clone, we will bring some of the saved properties to the new running instance. */
|
||||
if (userAddingNew === false && uiObjectType !== 'Workspace') {
|
||||
/* This following info can not be missing. */
|
||||
if (node.savedPayload === undefined) {
|
||||
console.log('Node ' + node.type + ' without savedPayload.', node)
|
||||
return
|
||||
}
|
||||
if (node.savedPayload.position === undefined) {
|
||||
console.log('Node ' + node.type + ' without savedPayload.position.', node)
|
||||
return
|
||||
}
|
||||
if (node.savedPayload.targetPosition === undefined) {
|
||||
console.log('Node ' + node.type + ' without savedPayload.targetPosition.', node)
|
||||
return
|
||||
}
|
||||
|
||||
/* If there is not a position offset, which happens when we are dropping a node into the designer, we create a cero vector then. */
|
||||
if (positionOffset === undefined) {
|
||||
positionOffset = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
}
|
||||
|
||||
/* Adding the offset to the saved positions. */
|
||||
node.savedPayload.targetPosition.x = node.savedPayload.targetPosition.x + positionOffset.x
|
||||
node.savedPayload.targetPosition.y = node.savedPayload.targetPosition.y + positionOffset.y
|
||||
node.savedPayload.position.x = node.savedPayload.position.x + positionOffset.x
|
||||
node.savedPayload.position.y = node.savedPayload.position.y + positionOffset.y
|
||||
|
||||
/* Transferring the saved payload properties into the running instance being created. */
|
||||
payload.targetPosition = {
|
||||
x: node.savedPayload.targetPosition.x,
|
||||
y: node.savedPayload.targetPosition.y
|
||||
}
|
||||
node.savedPayload.targetPosition = undefined
|
||||
|
||||
/* Reference children connection to parents */
|
||||
if (node.savedPayload.referenceParent !== undefined) {
|
||||
payload.referenceParent = mapOfNodes.get(node.savedPayload.referenceParent.id)
|
||||
|
||||
if (payload.referenceParent !== undefined) {
|
||||
mapOfReferenceChildren.set(node.id, node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we are adding a new object, then we set the initial values for position and targetPosition */
|
||||
if (userAddingNew === true || uiObjectType === 'Workspace') {
|
||||
/* Workspace allways to the spawn position */
|
||||
if (uiObjectType === 'Workspace') {
|
||||
payload.position = {
|
||||
x: spawnPosition.x,
|
||||
y: spawnPosition.y
|
||||
}
|
||||
}
|
||||
|
||||
/* Chain parent pointing to the position of the chain parent if defined. */
|
||||
if (chainParent === undefined) {
|
||||
if (parentNode !== undefined) {
|
||||
payload.targetPosition = {
|
||||
x: parentNode.payload.position.x,
|
||||
y: parentNode.payload.position.y
|
||||
}
|
||||
} else {
|
||||
payload.targetPosition = {
|
||||
x: spawnPosition.x,
|
||||
y: spawnPosition.y
|
||||
}
|
||||
}
|
||||
} else {
|
||||
payload.targetPosition = {
|
||||
x: chainParent.payload.position.x,
|
||||
y: chainParent.payload.position.y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
payload.visible = true
|
||||
payload.title = name
|
||||
payload.node = node
|
||||
payload.parentNode = parentNode
|
||||
payload.chainParent = chainParent
|
||||
payload.executeAction = UI.projects.foundations.spaces.designSpace.workspace.executeAction
|
||||
|
||||
node.payload = payload
|
||||
node.type = uiObjectType
|
||||
|
||||
/*
|
||||
Now we copy the possible frame saved to the payload where it can be used. A saved frame stores the position of a a chartingSpace object related to a node.
|
||||
This will prevent that if those charting space objects never get activated, that the frame information is lost when the workspace is saved.
|
||||
*/
|
||||
if (node.savedPayload !== undefined) {
|
||||
if (node.savedPayload.frame !== undefined) {
|
||||
let frame = {
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
}
|
||||
frame.position.x = node.savedPayload.frame.position.x
|
||||
frame.position.y = node.savedPayload.frame.position.y
|
||||
frame.width = node.savedPayload.frame.width
|
||||
frame.height = node.savedPayload.frame.height
|
||||
frame.radius = node.savedPayload.frame.radius
|
||||
UI.projects.foundations.utilities.loadSaveFrame.saveFrame(payload, frame)
|
||||
}
|
||||
if (node.savedPayload.tutorial !== undefined) {
|
||||
let tutorial = {
|
||||
status: node.savedPayload.tutorial.status
|
||||
}
|
||||
UI.projects.foundations.utilities.tutorial.saveTutorial(payload, tutorial)
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we mount the floating object where the UIOBject will be laying on top of */
|
||||
UI.projects.foundations.spaces.floatingSpace.uiObjectConstructor.createUiObject(userAddingNew, payload)
|
||||
|
||||
/* This is the point where we build a map with all nodes present at the workspace */
|
||||
mapOfNodes.set(node.id, node)
|
||||
|
||||
/* We will collect all tasks at the workspace in order to later syncronize them with the client */
|
||||
if (userAddingNew === false && uiObjectType === 'Task' && node.savedPayload !== undefined) {
|
||||
if (tasksFoundAtWorkspace !== undefined) { // it might be undefined when you are spawning a task that was backed up
|
||||
tasksFoundAtWorkspace.push(node)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if there are sessions to run */
|
||||
if (userAddingNew === false && node.savedPayload !== undefined) {
|
||||
if (uiObjectType === 'Live Trading Session' || uiObjectType === 'Forward Testing Session' || uiObjectType === 'Backtesting Session' || uiObjectType === 'Paper Trading Session') {
|
||||
if (tradingSessionsFoundAtWorkspace !== undefined) { // it might be undefined when you are spawning a session that was running while backed up
|
||||
tradingSessionsFoundAtWorkspace.push(node)
|
||||
}
|
||||
}
|
||||
if (uiObjectType === 'Learning Session') {
|
||||
if (learningSessionsFoundAtWorkspace !== undefined) { // it might be undefined when you are spawning a session that was running while backed up
|
||||
learningSessionsFoundAtWorkspace.push(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if there are tutorials to play */
|
||||
if (userAddingNew === false && node.savedPayload !== undefined) {
|
||||
if (uiObjectType === 'Tutorial') {
|
||||
if (node.savedPayload.uiObject.isPlaying === true) {
|
||||
if (tutorialsToPlay !== undefined) { // it might be undefined when you are spawning a tutorial that was playing while backed up
|
||||
tutorialsToPlay.push(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
function newFoundationsFunctionLibraryWebhookFunctions() {
|
||||
let thisObject = {
|
||||
sendTestMessage: sendTestMessage
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function sendTestMessage(node, callBackFunction) {
|
||||
let testMessage = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'testMessage')
|
||||
let letURL = UI.projects.foundations.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'webhookURL')
|
||||
|
||||
httpRequest(testMessage, letURL, onResponse)
|
||||
|
||||
function onResponse(err) {
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setInfoMessage('Test Message sent to the Client.')
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
} else {
|
||||
node.payload.uiObject.resetErrorMessage('Could not send Test Message to the Client.')
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
function newFoundationsFunctionLibraryWorkspaceFunctions() {
|
||||
let thisObject = {
|
||||
addMissingWorkspaceProjects: addMissingWorkspaceProjects
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function addMissingWorkspaceProjects(node, rootNodes) {
|
||||
for (let k = 0; k < PROJECTS_SCHEMA.length; k++) {
|
||||
let projectDefinition = PROJECTS_SCHEMA[k]
|
||||
let project = projectDefinition.name
|
||||
let alreadyExist = false
|
||||
|
||||
for (let j = 0; j < rootNodes.length; j++) {
|
||||
let rootNode = rootNodes[j]
|
||||
if (rootNode.type === project + ' Project') {
|
||||
alreadyExist = true
|
||||
}
|
||||
}
|
||||
|
||||
if (alreadyExist === false) {
|
||||
let child = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, project + ' Project', rootNodes, project)
|
||||
child.project = project
|
||||
child.projectDefinition.name = project
|
||||
child.projectDefinition.config = "{ \n \"codeName\": \"" + project + "\"\n}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user