Current Folder
No files matched your search
@@ -0,0 +1,53 @@
|
||||
function newEthereumFunctionLibraryAccounts() {
|
||||
thisObject = {
|
||||
createWalletAccount: createWalletAccount
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function createWalletAccount(node) {
|
||||
|
||||
let walletAccountNode = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Wallet Account')
|
||||
|
||||
let params = {
|
||||
method: 'createWalletAccount',
|
||||
entropy: walletAccountNode.id
|
||||
}
|
||||
|
||||
let url = 'WEB3' // we don't need to ask this to any specific superalgos node.
|
||||
|
||||
httpRequest(JSON.stringify(params), url, onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
/* Lets check the result of the call through the http interface */
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
|
||||
walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object')
|
||||
walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object')
|
||||
return
|
||||
}
|
||||
|
||||
let response = JSON.parse(data)
|
||||
|
||||
/* Lets check the result of the method call */
|
||||
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
|
||||
walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object')
|
||||
walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object')
|
||||
return
|
||||
}
|
||||
|
||||
let config = {
|
||||
address: response.address,
|
||||
privateKey: response.privateKey
|
||||
}
|
||||
|
||||
walletAccountNode.config = JSON.stringify(config, null, 4)
|
||||
walletAccountNode.name =
|
||||
response.address[response.address.length - 4] +
|
||||
response.address[response.address.length - 3] +
|
||||
response.address[response.address.length - 2] +
|
||||
response.address[response.address.length - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
function newEthereumActionSwitch() {
|
||||
|
||||
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 'Create Wallet Account': {
|
||||
UI.projects.ethereum.functionLibraries.accounts.createWalletAccount(action.node)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
function newEthereumGlobalsChainIds() {
|
||||
thisObject = {
|
||||
chainNameById: chainNameById
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function chainNameById(chainId) {
|
||||
switch(chainId) {
|
||||
case 1: return 'Ethereum Mainnet'
|
||||
case 3: return 'Ethereum Ropsten'
|
||||
case 4: return 'Ethereum Rinkeby'
|
||||
case 42: return 'Ethereum Kovan'
|
||||
case 61: return 'Ethereum Classic Mainnet'
|
||||
case 62: return 'Ethereum Classic Morden'
|
||||
default: return 'Unknown Network'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1 @@
|
||||
{"type":"Workspace","name":"Ethereum Integration Demo","rootNodes":[{"type":"Network","name":"My Network","project":"Superalgos","networkNodes":[{"type":"Network Node","name":"My Computer","config":"{ \n\"host\": \"localhost\", \n\"webPort\": \"34248\", \n\"webSocketsPort\": \"18041\"\n}","project":"Superalgos","dataMining":{"type":"Data Mining","name":"New Data Mining","project":"Superalgos","exchangeDataTasks":[{"type":"Exchange Data Tasks","name":"Binance","project":"Superalgos","marketDataTasks":[{"type":"Market Data Tasks","name":"Binance BTC/USDT","project":"Superalgos","dataMineTasks":[{"type":"Data Mine Tasks","name":"Masters","project":"Superalgos","taskManagers":[{"type":"Task Manager","name":"Masters","project":"Superalgos","tasks":[{"type":"Task","name":"Exchange Raw Data","project":"Superalgos","bot":{"type":"Sensor Bot Instance","name":"Exchange Raw Data","config":"{ \n\"startDate\": \"2017-01-01\"\n}","project":"Superalgos","processes":[{"type":"Sensor Process Instance","name":"Exchange Raw Data Historic-OHLCVs","project":"Superalgos","id":"da7e6d2a-76d5-431c-ba48-aa98ebd2a907","savedPayload":{"position":{"x":23623.030015561097,"y":29888.16403283887},"targetPosition":{"x":23918.47234146476,"y":29836.06957953879},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":3,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false},"referenceParent":{"type":"Process Definition","name":"Historic-OHLCVs","id":"5eb11d6a-022e-4f60-97c4-d6cf90b249dc"}}}],"id":"f9daa393-935e-4a9d-bdc5-706d97ac5530","savedPayload":{"position":{"x":23918.47234146476,"y":29836.06957953879},"targetPosition":{"x":24213.914667368423,"y":29783.97512623871},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"id":"5827edbc-89f8-495a-953a-a568f2fca44e","savedPayload":{"position":{"x":24213.914667368423,"y":29783.97512623871},"targetPosition":{"x":24509.356993272086,"y":29731.88067293863},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},{"type":"Task","name":"Candles Volumes","project":"Superalgos","bot":{"type":"Indicator Bot Instance","name":"Candles Volumes","config":"{}","project":"Superalgos","processes":[{"type":"Indicator Process Instance","name":"Candles Volumes Multi-Period-Market","project":"Superalgos","id":"243ecbf4-cb69-42e2-9acb-b03c7c481b79","savedPayload":{"position":{"x":23619.613932037235,"y":29653.83848916277},"targetPosition":{"x":23918.47234146476,"y":29627.69176633847},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":3,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false},"referenceParent":{"type":"Process Definition","name":"Multi-Period-Market","id":"9f683143-a33f-42c1-9fa8-c601f01ee4e1"}}},{"type":"Indicator Process Instance","name":"Candles Volumes Multi-Period-Daily","project":"Superalgos","id":"c90cb0e5-3e49-40ba-b919-38b0e5f7fcee","savedPayload":{"position":{"x":23646.580005353764,"y":29500.906287816262},"targetPosition":{"x":23918.47234146476,"y":29627.69176633847},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":3,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false},"referenceParent":{"type":"Process Definition","name":"Multi-Period-Daily","id":"980ceb1d-7be6-454f-90d9-01ba1fd4a65d"}}}],"id":"ac31f04b-4d79-4e18-9262-1a9a933b6156","savedPayload":{"position":{"x":23918.47234146476,"y":29627.69176633847},"targetPosition":{"x":24213.914667368423,"y":29679.78621963855},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"id":"46c3f665-a9e2-46dc-b569-2a928d2067af","savedPayload":{"position":{"x":24213.914667368423,"y":29679.78621963855},"targetPosition":{"x":24509.356993272086,"y":29731.88067293863},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},{"type":"Task","name":"Bollinger Bands","project":"Superalgos","bot":{"type":"Indicator Bot Instance","name":"Bollinger Bands","config":"{}","project":"Superalgos","processes":[{"type":"Indicator Process Instance","name":"Bollinger Bands Multi-Period-Market","project":"Superalgos","id":"12498614-646b-411c-9c82-747bacb8d7a6","savedPayload":{"position":{"x":23699.9640031147,"y":29354.234959407873},"targetPosition":{"x":23989.74175100142,"y":29431.88067293863},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":3,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false},"referenceParent":{"type":"Process Definition","name":"Multi-Period-Market","id":"941a0543-0cc0-4a5d-a782-728d2835c100"}}},{"typeLine truncated
|
||||
@@ -0,0 +1,690 @@
|
||||
[
|
||||
{
|
||||
"type": "Ethereum Project",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Blockchain",
|
||||
"relatedUiObject": "Ethereum Blockchain",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Decentralized Application",
|
||||
"relatedUiObject": "Ethereum Decentralized Application",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Token Definitions",
|
||||
"relatedUiObject": "Ethereum Token Definitions",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Wallet",
|
||||
"relatedUiObject": "Ethereum Wallet",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"actionFunction": "payload.executeAction",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete"
|
||||
}
|
||||
],
|
||||
"isProjectHead": true,
|
||||
"isTitleAllwaysVisible": false,
|
||||
"addLeftIcons": true,
|
||||
"isPinned": true,
|
||||
"positionLocked": true,
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Ethereum Wallet",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Client Reference",
|
||||
"disableIfPropertyIsDefined": true,
|
||||
"propertyToCheckFor": "networkClientReference",
|
||||
"relatedUiObject": "Network Client Reference",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Create Wallet Account",
|
||||
"actionProject": "Ethereum",
|
||||
"label": "Add Wallet Account",
|
||||
"relatedUiObject": "Wallet Account",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"isHierarchyHead": true,
|
||||
"addLeftIcons": true,
|
||||
"level": 0,
|
||||
"properties": [
|
||||
{
|
||||
"name": "networkClientReference",
|
||||
"type": "node",
|
||||
"childType": "Network Client Reference",
|
||||
"autoAdd": true
|
||||
},
|
||||
{
|
||||
"name": "walletAccounts",
|
||||
"type": "array",
|
||||
"childType": "Wallet Account"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Network Client Reference",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"title": [
|
||||
"Use Reference Parent Parent",
|
||||
"Use Reference Parent"
|
||||
],
|
||||
"referenceAttachesTo": {
|
||||
"compatibleTypes": "->Network Client->"
|
||||
},
|
||||
"addLeftIcons": true,
|
||||
"level": 3,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Wallet->"
|
||||
},
|
||||
"propertyNameAtParent": "networkClientReference",
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Wallet Account",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Configure",
|
||||
"label": "Configure",
|
||||
"iconPathOn": "configuration",
|
||||
"iconPathOff": "configuration",
|
||||
"dontShowAtFullscreen": true,
|
||||
"actionFunction": "uiObject.configEditor.activate"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add ETH Balance",
|
||||
"disableIfPropertyIsDefined": true,
|
||||
"propertyToCheckFor": "ethBalance",
|
||||
"relatedUiObject": "ETH Balance",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Token Balance",
|
||||
"relatedUiObject": "Token Balance",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"editors": {
|
||||
"config": true
|
||||
},
|
||||
"initialValues": {
|
||||
"config": "{ \n\"address\": \"\", \n\"privateKey\": \"\"\n}"
|
||||
},
|
||||
"addLeftIcons": true,
|
||||
"level": 0,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Wallet->"
|
||||
},
|
||||
"propertyNameAtParent": "walletAccounts",
|
||||
"properties": [
|
||||
{
|
||||
"name": "ethBalance",
|
||||
"type": "node",
|
||||
"childType": "ETH Balance"
|
||||
},
|
||||
{
|
||||
"name": "tokenBalances",
|
||||
"type": "array",
|
||||
"childType": "Token Balance"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum",
|
||||
"isPersonalData": true
|
||||
},
|
||||
{
|
||||
"type": "ETH Balance",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"addLeftIcons": true,
|
||||
"level": 4,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Wallet Account->"
|
||||
},
|
||||
"propertyNameAtParent": "ethBalance",
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Token Balance",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"title": [
|
||||
"Use Reference Parent"
|
||||
],
|
||||
"addLeftIcons": true,
|
||||
"level": 4,
|
||||
"referenceAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Token->"
|
||||
},
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Wallet Account->"
|
||||
},
|
||||
"propertyNameAtParent": "tokenBalances",
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Ethereum Token Definitions",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add Missing Children",
|
||||
"label": "Add Missing Children",
|
||||
"relatedUiObject": "Ethereum Token Definitions",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"isHierarchyHead": true,
|
||||
"addLeftIcons": true,
|
||||
"level": 0,
|
||||
"properties": [
|
||||
{
|
||||
"name": "erc-20TokenType",
|
||||
"type": "node",
|
||||
"childType": "ERC-20 Token Type"
|
||||
},
|
||||
{
|
||||
"name": "erc-223TokenType",
|
||||
"type": "node",
|
||||
"childType": "ERC-223 Token Type"
|
||||
},
|
||||
{
|
||||
"name": "erc-721TokenType",
|
||||
"type": "node",
|
||||
"childType": "ERC-721 Token Type"
|
||||
},
|
||||
{
|
||||
"name": "erc-777TokenType",
|
||||
"type": "node",
|
||||
"childType": "ERC-777 Token Type"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "ERC-20 Token Type",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Ethereum Token",
|
||||
"relatedUiObject": "Ethereum Token",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Token Definitions->"
|
||||
},
|
||||
"propertyNameAtParent": "erc-20TokenType",
|
||||
"properties": [
|
||||
{
|
||||
"name": "ethereumTokens",
|
||||
"type": "array",
|
||||
"childType": "Ethereum Token"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "ERC-223 Token Type",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Ethereum Token",
|
||||
"relatedUiObject": "Ethereum Token",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Token Definitions->"
|
||||
},
|
||||
"propertyNameAtParent": "erc-223TokenType",
|
||||
"properties": [
|
||||
{
|
||||
"name": "ethereumTokens",
|
||||
"type": "array",
|
||||
"childType": "Ethereum Token"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "ERC-721 Token Type",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Ethereum Token",
|
||||
"relatedUiObject": "Ethereum Token",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Token Definitions->"
|
||||
},
|
||||
"propertyNameAtParent": "erc-721TokenType",
|
||||
"properties": [
|
||||
{
|
||||
"name": "ethereumTokens",
|
||||
"type": "array",
|
||||
"childType": "Ethereum Token"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "ERC-777 Token Type",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Ethereum Token",
|
||||
"relatedUiObject": "Ethereum Token",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Token Definitions->"
|
||||
},
|
||||
"propertyNameAtParent": "erc-777TokenType",
|
||||
"properties": [
|
||||
{
|
||||
"name": "ethereumTokens",
|
||||
"type": "array",
|
||||
"childType": "Ethereum Token"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Ethereum Token",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Configure",
|
||||
"label": "Configure",
|
||||
"iconPathOn": "configuration",
|
||||
"iconPathOff": "configuration",
|
||||
"dontShowAtFullscreen": true,
|
||||
"actionFunction": "uiObject.configEditor.activate"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Smart Contract",
|
||||
"disableIfPropertyIsDefined": true,
|
||||
"propertyToCheckFor": "smartContract",
|
||||
"relatedUiObject": "Smart Contract",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"editors": {
|
||||
"config": true
|
||||
},
|
||||
"initialValues": {
|
||||
"config": "{ \n\"codeName\": \"\"\n}"
|
||||
},
|
||||
"addLeftIcons": true,
|
||||
"level": 2,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->ERC-20 Token Type->ERC-223 Token Type->ERC-721 Token Type->ERC-777 Token Type->"
|
||||
},
|
||||
"propertyNameAtParent": "ethereumTokens",
|
||||
"properties": [
|
||||
{
|
||||
"name": "smartContracts",
|
||||
"type": "node",
|
||||
"childType": "Smart Contract"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum",
|
||||
"alternativeIcons": [
|
||||
{
|
||||
"codeName": "USDT",
|
||||
"iconName": "tether"
|
||||
},
|
||||
{
|
||||
"codeName": "BNB",
|
||||
"iconName": "binance-coin"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Ethereum Blockchain",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Blockchain Network",
|
||||
"relatedUiObject": "Blockchain Network",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"isHierarchyHead": true,
|
||||
"addLeftIcons": true,
|
||||
"level": 0,
|
||||
"properties": [
|
||||
{
|
||||
"name": "blockchainNetworks",
|
||||
"type": "array",
|
||||
"childType": "Blockchain Network"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Blockchain Network",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Network Client",
|
||||
"relatedUiObject": "Network Client",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Ethereum Blockchain->"
|
||||
},
|
||||
"propertyNameAtParent": "blockchainNetworks",
|
||||
"properties": [
|
||||
{
|
||||
"name": "networkClients",
|
||||
"type": "array",
|
||||
"childType": "Network Client"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Network Client",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Configure",
|
||||
"label": "Configure",
|
||||
"iconPathOn": "configuration",
|
||||
"iconPathOff": "configuration",
|
||||
"dontShowAtFullscreen": true,
|
||||
"actionFunction": "uiObject.configEditor.activate"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"referenceAttachesTo": {
|
||||
"compatibleTypes": "->Network Node->"
|
||||
},
|
||||
"editors": {
|
||||
"config": true
|
||||
},
|
||||
"initialValues": {
|
||||
"config": "{ \n\"host\": \"localhost\", \n\"httpPort\": \"8545\"\n}"
|
||||
},
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Blockchain Network->"
|
||||
},
|
||||
"propertyNameAtParent": "networkClients",
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Ethereum Decentralized Application",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"label": "Add Smart Contract",
|
||||
"relatedUiObject": "Smart Contract",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"isHierarchyHead": true,
|
||||
"addLeftIcons": true,
|
||||
"level": 0,
|
||||
"properties": [
|
||||
{
|
||||
"name": "smartContracts",
|
||||
"type": "array",
|
||||
"childType": "Smart Contract"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Smart Contract",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Configure",
|
||||
"label": "Configure",
|
||||
"iconPathOn": "configuration",
|
||||
"iconPathOff": "configuration",
|
||||
"dontShowAtFullscreen": true,
|
||||
"actionFunction": "uiObject.configEditor.activate"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"disableIfPropertyIsDefined": true,
|
||||
"propertyToCheckFor": "solidityCode",
|
||||
"label": "Add Solidity Code",
|
||||
"relatedUiObject": "Solidity Code",
|
||||
"actionFunction": "payload.executeAction"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"editors": {
|
||||
"config": true
|
||||
},
|
||||
"initialValues": {
|
||||
"config": "{ \n\"address\": \"\"\n}"
|
||||
},
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Token Definition->Ethereum Decentralized Application->"
|
||||
},
|
||||
"propertyNameAtParent": "smartContracts",
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"properties": [
|
||||
{
|
||||
"name": "solidityCode",
|
||||
"type": "node",
|
||||
"childType": "Solidity Code"
|
||||
}
|
||||
],
|
||||
"icon": "ethereum"
|
||||
},
|
||||
{
|
||||
"type": "Solidity Code",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Edit",
|
||||
"actionFunction": "uiObject.codeEditor.activate",
|
||||
"label": "Edit",
|
||||
"iconPathOn": "ethereum",
|
||||
"iconPathOff": "ethereum"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete",
|
||||
"iconPathOff": "delete",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"editors": {
|
||||
"code": true
|
||||
},
|
||||
"initialValues": {
|
||||
"code": "// Type your smart contract code here."
|
||||
},
|
||||
"chainAttachesTo": {
|
||||
"compatibleTypes": "->Smart Contract->"
|
||||
},
|
||||
"propertyNameAtParent": "solidityCode",
|
||||
"addLeftIcons": true,
|
||||
"level": 2,
|
||||
"icon": "ethereum"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,2 @@
|
||||
[
|
||||
]
|
||||
@@ -0,0 +1,2 @@
|
||||
[
|
||||
]
|
||||
@@ -0,0 +1,180 @@
|
||||
function newEthereumBlockchainSpace() {
|
||||
const MODULE_NAME = 'Blockchain Space'
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
physics: physics,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
finalize: finalize,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
|
||||
let lastTryToReconnectDatetime
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
clientMap = undefined
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
|
||||
}
|
||||
|
||||
function physics() {
|
||||
networkClientStatusPhysics()
|
||||
}
|
||||
|
||||
async function networkClientStatusPhysics() {
|
||||
|
||||
/* We will query the node only every 3 seconds */
|
||||
if (lastTryToReconnectDatetime === undefined) {
|
||||
checkStatus()
|
||||
lastTryToReconnectDatetime = (new Date()).valueOf()
|
||||
} else {
|
||||
let now = (new Date()).valueOf()
|
||||
if (now - lastTryToReconnectDatetime > 3000) {
|
||||
checkStatus()
|
||||
lastTryToReconnectDatetime = now
|
||||
}
|
||||
}
|
||||
|
||||
async function checkStatus() {
|
||||
try {
|
||||
if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return }
|
||||
|
||||
let blockchain = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByType('Ethereum Blockchain')
|
||||
if (blockchain === undefined) { return }
|
||||
for (let i = 0; i < blockchain.blockchainNetworks.length; i++) {
|
||||
let blockchainNetwork = blockchain.blockchainNetworks[i]
|
||||
for (let j = 0; j < blockchainNetwork.networkClients.length; j++) {
|
||||
let networkClient = blockchainNetwork.networkClients[j]
|
||||
|
||||
let route = UI.projects.ethereum.utilities.routeToClient.buildRouteToClient(networkClient)
|
||||
|
||||
if (route === undefined) { continue } // something went wrong building the route.
|
||||
|
||||
route.params.method = 'getNetworkClientStatus'
|
||||
|
||||
httpRequest(JSON.stringify(route.params), route.url, onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
/* Lets check the result of the call through the http interface */
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
|
||||
return
|
||||
}
|
||||
|
||||
let status = JSON.parse(data)
|
||||
|
||||
/* Lets check the result of the method call */
|
||||
if (status.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + status.error)
|
||||
return
|
||||
}
|
||||
|
||||
showStatus(status)
|
||||
}
|
||||
|
||||
async function showStatus(status) {
|
||||
const ANNIMATION_CYCLES_TO_LAST = 300
|
||||
|
||||
networkClient.payload.uiObject.resetErrorMessage()
|
||||
|
||||
if (status.isSyncing === false && status.chainId === 0) {
|
||||
networkClient.payload.uiObject.setStatus('Client is looking for peers...', ANNIMATION_CYCLES_TO_LAST)
|
||||
return
|
||||
}
|
||||
|
||||
if (status.chainId > 0) {
|
||||
let networkName = UI.projects.ethereum.globals.chainIds.chainNameById(status.chainId)
|
||||
networkClient.payload.uiObject.setStatus('Connected to ' + networkName + ' via the ' + route.params.interface + ' interface, through ' + networkClient.payload.referenceParent.name + ' Network Node.', ANNIMATION_CYCLES_TO_LAST)
|
||||
|
||||
networkClient.payload.uiObject.valueAtAngle = false
|
||||
networkClient.payload.uiObject.setValue(
|
||||
'Current Block Number ' + splitLargeNumber(status.currentBlockNumber)
|
||||
, 200)
|
||||
networkClient.payload.uiObject.setPercentage('100.00', ANNIMATION_CYCLES_TO_LAST)
|
||||
return
|
||||
}
|
||||
|
||||
/* If it is not syncing, then we have the current block and the highets block too */
|
||||
let percentage = (status.isSyncing.currentBlock * 100 / status.isSyncing.highestBlock).toFixed(4)
|
||||
let extraStatus = ''
|
||||
if (status.isSyncing.highestBlock - status.isSyncing.currentBlock < 300) {
|
||||
extraStatus = 'Block Download Phase Finished. Downloading Trie Data Structure.'
|
||||
} else {
|
||||
extraStatus = 'Block Download Phase.'
|
||||
networkClient.payload.uiObject.setPercentage(percentage, ANNIMATION_CYCLES_TO_LAST)
|
||||
}
|
||||
|
||||
networkClient.payload.uiObject.valueAtAngle = false
|
||||
networkClient.payload.uiObject.setValue(
|
||||
'Block ' + splitLargeNumber(status.isSyncing.currentBlock) +
|
||||
' from ' + splitLargeNumber(status.isSyncing.highestBlock) +
|
||||
'. State ' + splitLargeNumber(status.isSyncing.pulledStates) +
|
||||
' from ' + splitLargeNumber(status.isSyncing.knownStates)
|
||||
, 200)
|
||||
|
||||
if (status.isSyncing.currentBlock !== status.isSyncing.highestBlock) {
|
||||
networkClient.payload.uiObject.setStatus('Connected via http. Client is Syncing... ' + extraStatus, ANNIMATION_CYCLES_TO_LAST)
|
||||
}
|
||||
|
||||
function splitLargeNumber(number) {
|
||||
let label = number.toString()
|
||||
let result = label
|
||||
switch (label.length) {
|
||||
case 4: {
|
||||
return label[0] + ',' + label[1] + label[2] + label[3]
|
||||
}
|
||||
case 5: {
|
||||
return label[0] + label[1] + ',' + label[2] + label[3] + label[4]
|
||||
}
|
||||
case 6: {
|
||||
return label[0] + label[1] + label[2] + ',' + label[3] + label[4] + label[5]
|
||||
}
|
||||
case 7: {
|
||||
return label[0] + ',' + label[1] + label[2] + label[3] + ',' + label[4] + label[5] + label[6]
|
||||
}
|
||||
case 8: {
|
||||
return label[0] + label[1] + ',' + label[2] + label[3] + label[4] + ',' + label[5] + label[6] + label[7]
|
||||
}
|
||||
case 9: {
|
||||
return label[0] + label[1] + label[2] + ',' + label[3] + label[4] + label[5] + ',' + label[6] + label[7] + label[8]
|
||||
}
|
||||
case 10: {
|
||||
return label[0] + ',' + label[1] + label[2] + label[3] + ',' + label[4] + label[5] + label[6] + ',' + label[7] + label[8] + label[9]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[ERROR] checkStatus -> err = ' + err.stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
thisObject.container.space = MODULE_NAME
|
||||
return thisObject.container
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
function newEthereumWalletSpace() {
|
||||
const MODULE_NAME = 'Wallet Space'
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
physics: physics,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
finalize: finalize,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
|
||||
let lastTryToReconnectDatetime
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
|
||||
}
|
||||
|
||||
function physics() {
|
||||
walletBalancesPhysics()
|
||||
}
|
||||
|
||||
async function walletBalancesPhysics() {
|
||||
|
||||
/* We will query the node only every 3 seconds */
|
||||
if (lastTryToReconnectDatetime === undefined) {
|
||||
checkBalances()
|
||||
lastTryToReconnectDatetime = (new Date()).valueOf()
|
||||
} else {
|
||||
let now = (new Date()).valueOf()
|
||||
if (now - lastTryToReconnectDatetime > 3000) {
|
||||
checkBalances()
|
||||
lastTryToReconnectDatetime = now
|
||||
}
|
||||
}
|
||||
|
||||
async function checkBalances() {
|
||||
try {
|
||||
if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return }
|
||||
|
||||
let wallets = []
|
||||
let hierarchyHeads = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeads()
|
||||
for (let i = 0; i < hierarchyHeads.length; i++) {
|
||||
let hierarchyHead = hierarchyHeads[i]
|
||||
if (hierarchyHead.type === 'Ethereum Wallet') {
|
||||
wallets.push(hierarchyHead)
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < wallets.length; i++) {
|
||||
let wallet = wallets[i]
|
||||
|
||||
if (wallet.networkClientReference === undefined) {
|
||||
wallet.payload.uiObject.setWarningMessage('A Network Client Reference is needed in order to fetch Account Balances from a Network Client.')
|
||||
continue
|
||||
}
|
||||
|
||||
if (wallet.networkClientReference.payload === undefined) {
|
||||
// node exists without payload, probably has been deleted.
|
||||
continue
|
||||
}
|
||||
|
||||
if (wallet.networkClientReference.payload.referenceParent === undefined) {
|
||||
wallet.networkClientReference.payload.uiObject.setWarningMessage('A reference to a Network Client is needed in order to fetch Account Balances from a Network Client.')
|
||||
continue
|
||||
}
|
||||
|
||||
let networkClient = wallet.networkClientReference.payload.referenceParent
|
||||
|
||||
let route = UI.projects.ethereum.utilities.routeToClient.buildRouteToClient(networkClient)
|
||||
|
||||
if (route === undefined) { continue } // something went wrong building the route.
|
||||
|
||||
route.params.method = 'getWalletBalances'
|
||||
|
||||
let lightingPath = '' +
|
||||
'Ethereum Wallet->' +
|
||||
'Wallet Account->' +
|
||||
'ETH Balance->' +
|
||||
'Token Balance->' +
|
||||
'Ethereum Token->Smart Contract->' +
|
||||
'ERC-20 Token Type->ERC-223 Token Type->ERC-721 Token Type->ERC-777 Token Type->'
|
||||
|
||||
route.params.walletDefinition = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(wallet, false, true, true, false, false, lightingPath)
|
||||
|
||||
httpRequest(JSON.stringify(route.params), route.url, onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
/* Lets check the result of the call through the http interface */
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
|
||||
return
|
||||
}
|
||||
|
||||
let response = JSON.parse(data)
|
||||
|
||||
/* Lets check the result of the method call */
|
||||
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
|
||||
return
|
||||
}
|
||||
|
||||
showBalances(response.walletDefinition)
|
||||
}
|
||||
|
||||
function showBalances(walletDefinition) {
|
||||
for (let i = 0; i < walletDefinition.walletAccounts.length; i++) {
|
||||
let walletAccount = walletDefinition.walletAccounts[i]
|
||||
|
||||
if (walletAccount.ethBalance !== undefined) {
|
||||
|
||||
let uiObject = wallet.walletAccounts[i].ethBalance.payload.uiObject
|
||||
|
||||
if (walletAccount.error !== undefined) {
|
||||
uiObject.setErrorMessage(walletAccount.error)
|
||||
} else {
|
||||
let value = walletAccount.ethBalance.value / 1000000000000000000
|
||||
uiObject.valueAtAngle = false
|
||||
uiObject.setValue(value + ' ETH')
|
||||
}
|
||||
}
|
||||
|
||||
for (let j = 0; j < walletAccount.tokenBalances.length; j++) {
|
||||
let tokenBalance = walletAccount.tokenBalances[j]
|
||||
let uiObject = wallet.walletAccounts[i].tokenBalances[j].payload.uiObject
|
||||
let value = tokenBalance.value / 1000000000000000000
|
||||
uiObject.valueAtAngle = false
|
||||
uiObject.setValue(value + ' ' + tokenBalance.referenceParent.config.codeName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[ERROR] checkBalances -> err = ' + err.stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
thisObject.container.space = MODULE_NAME
|
||||
return thisObject.container
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
function newEthereumUtilitiesRouteToClient() {
|
||||
thisObject = {
|
||||
buildRouteToClient: buildRouteToClient
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function buildRouteToClient(networkClient) {
|
||||
let config = JSON.parse(networkClient.config)
|
||||
if (config.host === undefined) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Property host not defined at node config.')
|
||||
return
|
||||
}
|
||||
if (config.httpPort === undefined && config.webSocketsPort === undefined) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Property httpPort or webSocketsPort must be defined at node config.')
|
||||
return
|
||||
}
|
||||
|
||||
/* Web Sockets would be the default protocol */
|
||||
let clientPort
|
||||
let clientInterface
|
||||
if (config.webSocketsPort !== undefined) {
|
||||
clientInterface = 'ws'
|
||||
clientPort = config.webSocketsPort
|
||||
} else {
|
||||
clientInterface = 'http'
|
||||
clientPort = config.httpPort
|
||||
}
|
||||
|
||||
let params = {
|
||||
host: config.host,
|
||||
port: clientPort,
|
||||
interface: clientInterface
|
||||
}
|
||||
|
||||
/*
|
||||
Next, we will check which Superalgos Network Node we need as a gateway
|
||||
to the Ethereum Client. We will use the current node reference parent for that.
|
||||
*/
|
||||
if (networkClient.payload.referenceParent === undefined) {
|
||||
networkClient.payload.uiObject.setErrorMessage('You need to reference a Superalgos Network Node so that it acts as a gateway to the Ethereum Client.')
|
||||
return
|
||||
}
|
||||
|
||||
let networkNodeConfig = JSON.parse(networkClient.payload.referenceParent.config)
|
||||
let url = 'http://' + networkNodeConfig.host + ':' + networkNodeConfig.webPort + '/' + 'WEB3'
|
||||
|
||||
return {
|
||||
params: params,
|
||||
url: url
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
[
|
||||
{
|
||||
"name": "Superalgos",
|
||||
"propertyName": "superalgos",
|
||||
"globals": [
|
||||
{
|
||||
"name": "Docs",
|
||||
"propertyName": "docs",
|
||||
"functionName": "newSuperalgosGlobalsDocs"
|
||||
},
|
||||
{
|
||||
"name": "Zoom",
|
||||
"propertyName": "zoom",
|
||||
"functionName": "newSuperalgosGlobalsZoom"
|
||||
}
|
||||
],
|
||||
"functionLibraries": [
|
||||
{
|
||||
"name": "Attach Detach",
|
||||
"propertyName": "attachDetach",
|
||||
"functionName": "newSuperalgosFunctionLibraryAttachDetach"
|
||||
},
|
||||
{
|
||||
"name": "Chain Attach Detach",
|
||||
"propertyName": "chainAttachDetach",
|
||||
"functionName": "newSuperalgosFunctionLibraryChainAttachDetach"
|
||||
},
|
||||
{
|
||||
"name": "Node Deleter",
|
||||
"propertyName": "nodeDeleter",
|
||||
"functionName": "newSuperalgosFunctionLibraryNodeDeleter"
|
||||
},
|
||||
{
|
||||
"name": "Ui Objects From Nodes",
|
||||
"propertyName": "uiObjectsFromNodes",
|
||||
"functionName": "newSuperalgosFunctionLibraryUiObjectsFromNodes"
|
||||
},
|
||||
{
|
||||
"name": "Protocol Node",
|
||||
"propertyName": "protocolNode",
|
||||
"functionName": "newSuperalgosFunctionLibraryProtocolNode"
|
||||
},
|
||||
{
|
||||
"name": "Node Cloning",
|
||||
"propertyName": "nodeCloning",
|
||||
"functionName": "newSuperalgosFunctionLibraryNodeCloning"
|
||||
},
|
||||
{
|
||||
"name": "Shortcut Keys",
|
||||
"propertyName": "shortcutKeys",
|
||||
"functionName": "newSuperalgosFunctionLibraryShortcutKeys"
|
||||
},
|
||||
{
|
||||
"name": "On Focus",
|
||||
"propertyName": "onFocus",
|
||||
"functionName": "newSuperalgosFunctionLibraryOnFocus"
|
||||
},
|
||||
{
|
||||
"name": "Super Scripts Functions",
|
||||
"propertyName": "superScriptsFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibrarySuperScriptsFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Webhook Functions",
|
||||
"propertyName": "webhookFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryWebhookFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Dependencies Filter",
|
||||
"propertyName": "dependenciesFilter",
|
||||
"functionName": "newSuperalgosFunctionLibraryDependenciesFilter"
|
||||
},
|
||||
{
|
||||
"name": "Node Path",
|
||||
"propertyName": "nodePath",
|
||||
"functionName": "newSuperalgosFunctionLibraryNodePath"
|
||||
},
|
||||
{
|
||||
"name": "Task Functions",
|
||||
"propertyName": "taskFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryTaskFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Trading Session Functions",
|
||||
"propertyName": "tradingSessionFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryTradingSessionFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Learning Session Functions",
|
||||
"propertyName": "learningSessionFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryLearningSessionFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Crypto Ecosystem Functions",
|
||||
"propertyName": "cryptoEcosystemFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryCryptoEcosystemFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Mine Functions",
|
||||
"propertyName": "mineFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryMineFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Data Storage Functions",
|
||||
"propertyName": "dataStorageFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryDataStorageFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Charting Space Functions",
|
||||
"propertyName": "chartingSpaceFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryChartingSpaceFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Plugins Functions",
|
||||
"propertyName": "pluginsFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryPluginsFunctions"
|
||||
},
|
||||
{
|
||||
"name": "Workspace Functions",
|
||||
"propertyName": "workspaceFunctions",
|
||||
"functionName": "newSuperalgosFunctionLibraryWorkspaceFunctions"
|
||||
}
|
||||
],
|
||||
"utilities": [
|
||||
{
|
||||
"name": "Branches",
|
||||
"propertyName": "branches",
|
||||
"functionName": "newSuperalgosUtilitiesBranches"
|
||||
},
|
||||
{
|
||||
"name": "Clipboard",
|
||||
"propertyName": "clipboard",
|
||||
"functionName": "newSuperalgosUtilitiesClipboard"
|
||||
},
|
||||
{
|
||||
"name": "Coordinate Transformations",
|
||||
"propertyName": "coordinateTransformations",
|
||||
"functionName": "newSuperalgosUtilitiesCoordinateTransformations"
|
||||
},
|
||||
{
|
||||
"name": "Date Rate Transformations",
|
||||
"propertyName": "dateRateTransformations",
|
||||
"functionName": "newSuperalgosUtilitiesDateRateTransformations"
|
||||
},
|
||||
{
|
||||
"name": "Dates",
|
||||
"propertyName": "dates",
|
||||
"functionName": "newSuperalgosUtilitiesDates"
|
||||
},
|
||||
{
|
||||
"name": "Download",
|
||||
"propertyName": "download",
|
||||
"functionName": "newSuperalgosUtilitiesDownload"
|
||||
},
|
||||
{
|
||||
"name": "Draw Print",
|
||||
"propertyName": "drawPrint",
|
||||
"functionName": "newSuperalgosUtilitiesDrawPrint"
|
||||
},
|
||||
{
|
||||
"name": "Hierarchy",
|
||||
"propertyName": "hierarchy",
|
||||
"functionName": "newSuperalgosUtilitiesHierarchy"
|
||||
},
|
||||
{
|
||||
"name": "Load Save Frame",
|
||||
"propertyName": "loadSaveFrame",
|
||||
"functionName": "newSuperalgosUtilitiesLoadSaveFrame"
|
||||
},
|
||||
{
|
||||
"name": "Tutorial",
|
||||
"propertyName": "tutorial",
|
||||
"functionName": "newSuperalgosUtilitiesTutorial"
|
||||
},
|
||||
{
|
||||
"name": "Menu",
|
||||
"propertyName": "menu",
|
||||
"functionName": "newSuperalgosUtilitiesMenu"
|
||||
},
|
||||
{
|
||||
"name": "Meshes",
|
||||
"propertyName": "meshes",
|
||||
"functionName": "newSuperalgosUtilitiesMeshes"
|
||||
},
|
||||
{
|
||||
"name": "Children",
|
||||
"propertyName": "children",
|
||||
"functionName": "newSuperalgosUtilitiesNodeChildren"
|
||||
},
|
||||
{
|
||||
"name": "Node Config",
|
||||
"propertyName": "nodeConfig",
|
||||
"functionName": "newSuperalgosUtilitiesNodeConfig"
|
||||
},
|
||||
{
|
||||
"name": "Folders",
|
||||
"propertyName": "folders",
|
||||
"functionName": "newSuperalgosUtilitiesFolders"
|
||||
}
|
||||
],
|
||||
"spaces": [
|
||||
{
|
||||
"name": "Floating Space",
|
||||
"folderName": "Floating-Space",
|
||||
"propertyName": "floatingSpace",
|
||||
"functionName": "newSuperalgosFloatingSpace",
|
||||
"initializationIndex": 0,
|
||||
"animationPhysicsIndex": 1,
|
||||
"animationDrawIndex": 0,
|
||||
"onMouseWheelIndex": 6,
|
||||
"onMouseOverIndex": 8,
|
||||
"onMouseClickIndex": 8,
|
||||
"onMouseDownIndex": 8
|
||||
},
|
||||
{
|
||||
"name": "Top Space",
|
||||
"folderName": "Top-Space",
|
||||
"propertyName": "topSpace",
|
||||
"functionName": "newSuperalgosTopSpace",
|
||||
"initializationIndex": 1,
|
||||
"animationPhysicsIndex": 7,
|
||||
"animationDrawIndex": 6,
|
||||
"onMouseOverIndex": 4,
|
||||
"onMouseClickIndex": 4,
|
||||
"onMouseDownIndex": 4
|
||||
},
|
||||
{
|
||||
"name": "Cockpit Space",
|
||||
"folderName": "Cocksit-Space",
|
||||
"propertyName": "cockpitSpace",
|
||||
"functionName": "newSuperalgosCockpitSpace",
|
||||
"initializationIndex": 2,
|
||||
"animationPhysicsIndex": 0,
|
||||
"animationDrawIndex": 7,
|
||||
"onMouseWheelIndex": 4,
|
||||
"onMouseOverIndex": 5,
|
||||
"onMouseClickIndex": 5,
|
||||
"onMouseDownIndex": 5
|
||||
},
|
||||
{
|
||||
"name": "Design Space",
|
||||
"folderName": "Design-Space",
|
||||
"propertyName": "designSpace",
|
||||
"functionName": "newSuperalgosDesignSpace",
|
||||
"initializationIndex": 3,
|
||||
"animationPhysicsIndex": 3,
|
||||
"animationDrawIndex": 2,
|
||||
"onMouseWheelIndex": 0,
|
||||
"onMouseOverIndex": 3,
|
||||
"onMouseClickIndex": 3,
|
||||
"onMouseDownIndex": 3
|
||||
},
|
||||
{
|
||||
"name": "Panel Space",
|
||||
"folderName": "Panel-Space",
|
||||
"propertyName": "panelSpace",
|
||||
"functionName": "newSuperalgosPanelSpace",
|
||||
"initializationIndex": 4,
|
||||
"animationPhysicsIndex": 4,
|
||||
"animationDrawIndex": 3,
|
||||
"onMouseWheelIndex": 3,
|
||||
"onMouseOverIndex": 6,
|
||||
"onMouseClickIndex": 6,
|
||||
"onMouseDownIndex": 6
|
||||
},
|
||||
{
|
||||
"name": "Charting Space",
|
||||
"folderName": "Charting-Space",
|
||||
"propertyName": "chartingSpace",
|
||||
"functionName": "newSuperalgosChartingSpace",
|
||||
"initializationIndex": 5,
|
||||
"animationPhysicsIndex": 2,
|
||||
"animationDrawIndex": 1,
|
||||
"onMouseWheelIndex": 5,
|
||||
"onMouseOverIndex": 7,
|
||||
"onMouseClickIndex": 7,
|
||||
"onMouseDownIndex": 7
|
||||
},
|
||||
{
|
||||
"name": "Side Space",
|
||||
"folderName": "Floating-Space",
|
||||
"propertyName": "sideSpace",
|
||||
"functionName": "newSuperalgosSideSpace",
|
||||
"initializationIndex": 6,
|
||||
"animationPhysicsIndex": 8,
|
||||
"animationDrawIndex": 8,
|
||||
"onMouseWheelIndex": 2,
|
||||
"onMouseOverIndex": 2,
|
||||
"onMouseClickIndex": 2,
|
||||
"onMouseDownIndex": 2
|
||||
},
|
||||
{
|
||||
"name": "Doc Space",
|
||||
"folderName": "Doc-Space",
|
||||
"propertyName": "docSpace",
|
||||
"functionName": "newSuperalgosDocSpace",
|
||||
"initializationIndex": 7,
|
||||
"animationPhysicsIndex": 5,
|
||||
"animationDrawIndex": 4,
|
||||
"onMouseWheelIndex": 1,
|
||||
"onMouseOverIndex": 1,
|
||||
"onMouseClickIndex": 1,
|
||||
"onMouseDownIndex": 1
|
||||
},
|
||||
{
|
||||
"name": "Chat Space",
|
||||
"folderName": "Chat-Space",
|
||||
"propertyName": "chatSpace",
|
||||
"functionName": "newSuperalgosChatSpace"
|
||||
},
|
||||
{
|
||||
"name": "Tutorial Space",
|
||||
"folderName": "Tutorial-Space",
|
||||
"propertyName": "tutorialSpace",
|
||||
"functionName": "newSuperalgosTutorialSpace",
|
||||
"initializationIndex": 8,
|
||||
"animationPhysicsIndex": 6,
|
||||
"animationDrawIndex": 5,
|
||||
"onMouseWheelIndex": 0,
|
||||
"onMouseOverIndex": 0,
|
||||
"onMouseClickIndex": 0,
|
||||
"onMouseDownIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Ethereum",
|
||||
"propertyName": "ethereum",
|
||||
"globals": [
|
||||
{
|
||||
"name": "ChainIds",
|
||||
"propertyName": "chainIds",
|
||||
"functionName": "newEthereumGlobalsChainIds"
|
||||
}
|
||||
],
|
||||
"functionLibraries": [
|
||||
{
|
||||
"name": "Accounts",
|
||||
"propertyName": "accounts",
|
||||
"functionName": "newEthereumFunctionLibraryAccounts"
|
||||
}
|
||||
],
|
||||
"utilities": [
|
||||
{
|
||||
"name": "Route To Client",
|
||||
"propertyName": "routeToClient",
|
||||
"functionName": "newEthereumUtilitiesRouteToClient"
|
||||
}
|
||||
],
|
||||
"spaces": [
|
||||
{
|
||||
"name": "Blockchain Space",
|
||||
"folderName": "Blockchain-Space",
|
||||
"propertyName": "blockchainSpace",
|
||||
"functionName": "newEthereumBlockchainSpace",
|
||||
"initializationIndex": 0,
|
||||
"animationPhysicsIndex": 0,
|
||||
"animationDrawIndex": 0,
|
||||
"onMouseWheelIndex": 0,
|
||||
"onMouseOverIndex": 0,
|
||||
"onMouseClickIndex": 0,
|
||||
"onMouseDownIndex": 0
|
||||
},
|
||||
{
|
||||
"name": "Wallet Space",
|
||||
"folderName": "Wallet-Space",
|
||||
"propertyName": "walletSpace",
|
||||
"functionName": "newEthereumWalletSpace",
|
||||
"initializationIndex": 1,
|
||||
"animationPhysicsIndex": 1,
|
||||
"animationDrawIndex": 1,
|
||||
"onMouseWheelIndex": 1,
|
||||
"onMouseOverIndex": 1,
|
||||
"onMouseClickIndex": 1,
|
||||
"onMouseDownIndex": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,619 @@
|
||||
function newSuperalgosActionSwitch() {
|
||||
|
||||
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.superalgos.functionLibraries.onFocus.getNodeThatIsOnFocus(action.node)
|
||||
}
|
||||
|
||||
case 'Get Node By Shortcut Key': {
|
||||
return UI.projects.superalgos.functionLibraries.shortcutKeys.getNodeByShortcutKey(action.node, action.extraParameter)
|
||||
}
|
||||
|
||||
case 'Get Node Data Structure': {
|
||||
return UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(action.node, action.extraParameter, false, true, true, true)
|
||||
}
|
||||
|
||||
case 'Create UI Object': {
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.createUiObjectFromNode(action.node, undefined, undefined, action.extraParameter)
|
||||
}
|
||||
break
|
||||
case 'Connect Children to Reference Parents': {
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.tryToConnectChildrenWithReferenceParents()
|
||||
}
|
||||
break
|
||||
case 'Get Node By Id': {
|
||||
return UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.getNodeById(action.relatedNodeId)
|
||||
}
|
||||
|
||||
case 'Syncronize Tasks': {
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.syncronizeTasksFoundAtWorkspaceWithBackEnd()
|
||||
}
|
||||
break
|
||||
case 'Syncronize Trading Sessions': {
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd()
|
||||
}
|
||||
break
|
||||
case 'Syncronize Learning Sessions': {
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd()
|
||||
}
|
||||
break
|
||||
case 'Play Tutorials': {
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.playTutorials()
|
||||
}
|
||||
break
|
||||
case 'Recreate Workspace': {
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.recreateWorkspace(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Delete Workspace': {
|
||||
return UI.projects.superalgos.functionLibraries.nodeDeleter.deleteWorkspace(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Copy Node Path':
|
||||
{
|
||||
let nodePath = UI.projects.superalgos.functionLibraries.nodePath.getNodePath(action.node)
|
||||
|
||||
UI.projects.superalgos.utilities.clipboard.copyTextToClipboard(nodePath)
|
||||
|
||||
UI.projects.superalgos.spaces.cockpitSpace.setStatus(
|
||||
nodePath + ' copied to the Clipboard.'
|
||||
, 50, UI.projects.superalgos.spaces.cockpitSpace.statusTypes.ALL_GOOD)
|
||||
}
|
||||
break
|
||||
case 'Copy Node Value':
|
||||
{
|
||||
let value = action.node.payload.uiObject.getValue()
|
||||
|
||||
UI.projects.superalgos.utilities.clipboard.copyTextToClipboard(value)
|
||||
|
||||
UI.projects.superalgos.spaces.cockpitSpace.setStatus(
|
||||
value + ' copied to the Clipboard.'
|
||||
, 50, UI.projects.superalgos.spaces.cockpitSpace.statusTypes.ALL_GOOD)
|
||||
}
|
||||
break
|
||||
case 'Copy Node Type':
|
||||
{
|
||||
let value = action.node.type
|
||||
|
||||
UI.projects.superalgos.utilities.clipboard.copyTextToClipboard(value)
|
||||
|
||||
UI.projects.superalgos.spaces.cockpitSpace.setStatus(
|
||||
value + ' copied to the Clipboard.'
|
||||
, 50, UI.projects.superalgos.spaces.cockpitSpace.statusTypes.ALL_GOOD)
|
||||
}
|
||||
break
|
||||
case 'Add UI Object':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(action.node, action.relatedNodeType, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Children':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addMissingChildren(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Delete UI Object':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.nodeDeleter.deleteUIObject(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Edit Code':
|
||||
|
||||
break
|
||||
case 'Share':
|
||||
{
|
||||
let text = JSON.stringify(UI.projects.superalgos.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.superalgos.utilities.download.downloadText(fileName, text)
|
||||
}
|
||||
|
||||
break
|
||||
case 'Backup':
|
||||
{
|
||||
let text = JSON.stringify(UI.projects.superalgos.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.superalgos.utilities.download.downloadText(fileName, text)
|
||||
}
|
||||
|
||||
break
|
||||
case 'Clone':
|
||||
{
|
||||
let text = JSON.stringify(UI.projects.superalgos.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.superalgos.utilities.download.downloadText(fileName, text)
|
||||
}
|
||||
|
||||
break
|
||||
case 'Debug Task':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runTask(action.node, true, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Task':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runTask(action.node, false, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Stop Task':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopTask(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run All Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Task Managers':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllTaskManagers(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Task Managers':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllTaskManagers(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Exchange Data Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllExchangeDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Exchange Data Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllExchangeDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Exchange Trading Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllExchangeTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Exchange Trading Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllExchangeTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Exchange Learning Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllExchangeLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Exchange Learning Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllExchangeLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Market Data Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllMarketDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Market Data Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllMarketDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Market Trading Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllMarketTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Market Trading Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllMarketTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Market Learning Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllMarketLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Market Learning Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllMarketLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Data Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllDataMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Data Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllDataMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Trading Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllTradingMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Trading Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllTradingMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Run All Learning Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.runAllLearningMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Stop All Learning Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.stopAllLearningMineTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Data Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingExchangeDataTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Data Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingMarketDataTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Data Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingDataMineTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Trading Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingExchangeTradingTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Trading Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingMarketTradingTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Trading Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingTradingMineTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Learning Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingExchangeLearningTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Learning Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingMarketLearningTasks(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Learning Mine Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addMissingLearningMineTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Tasks':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.taskFunctions.addAllTasks(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Crypto Exchanges':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.cryptoEcosystemFunctions.addMissingExchanges(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Assets':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.cryptoEcosystemFunctions.addMissingAssets(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Markets':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.cryptoEcosystemFunctions.addMissingMarkets(action.node)
|
||||
}
|
||||
break
|
||||
case 'Install Market':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.cryptoEcosystemFunctions.installMarket(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Uninstall Market':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.cryptoEcosystemFunctions.uninstallMarket(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Output Datasets':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.mineFunctions.addAllOutputDatasets(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addAllDataProducts(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Mine Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addAllDataMineProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Learning Mine Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addAllLearningMineProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Trading Mine Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addAllTradingMineProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Trading Session References':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addMissingTradingSessionReferences(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Learning Session References':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addMissingLearningSessionReferences(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Data Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addMissingMarketDataProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Market Trading Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addMissingMarketTradingProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Trading Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addMissingExchangeTradingProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Exchange Data Products':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.dataStorageFunctions.addMissingExchangeDataProducts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Dependencies':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.mineFunctions.addAllDataDependencies(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Data Mine Dependencies':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.mineFunctions.addAllDataMineDataDependencies(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add All Layer Panels':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.chartingSpaceFunctions.addAllLayerPanels(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Layer Polygons':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.chartingSpaceFunctions.addAllLayerPolygons(action.node)
|
||||
}
|
||||
break
|
||||
case 'Add All Mine Layers':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.chartingSpaceFunctions.addAllMineLayers(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Time Machines':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.chartingSpaceFunctions.addMissingTimeMachines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Dashboards':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.chartingSpaceFunctions.addMissingDashboards(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Play Tutorial':
|
||||
{
|
||||
UI.projects.superalgos.spaces.tutorialSpace.playTutorial(action.node)
|
||||
}
|
||||
break
|
||||
case 'Play Tutorial Topic':
|
||||
{
|
||||
UI.projects.superalgos.spaces.tutorialSpace.playTutorialTopic(action.node)
|
||||
}
|
||||
break
|
||||
case 'Play Tutorial Step':
|
||||
{
|
||||
UI.projects.superalgos.spaces.tutorialSpace.playTutorialStep(action.node)
|
||||
}
|
||||
break
|
||||
case 'Resume Tutorial':
|
||||
{
|
||||
UI.projects.superalgos.spaces.tutorialSpace.resumeTutorial(action.node)
|
||||
}
|
||||
break
|
||||
case 'Resume Tutorial Topic':
|
||||
{
|
||||
UI.projects.superalgos.spaces.tutorialSpace.resumeTutorialTopic(action.node)
|
||||
}
|
||||
break
|
||||
case 'Resume Tutorial Step':
|
||||
{
|
||||
UI.projects.superalgos.spaces.tutorialSpace.resumeTutorialStep(action.node)
|
||||
}
|
||||
break
|
||||
case 'Reset Tutorial Progress':
|
||||
{
|
||||
UI.projects.superalgos.spaces.tutorialSpace.resetTutorialProgress(action.node)
|
||||
}
|
||||
break
|
||||
case 'Send Webhook Test Message':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.webhookFunctions.sendTestMessage(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Trading Session':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.tradingSessionFunctions.runSession(action.node, false, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Resume Trading Session':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.tradingSessionFunctions.runSession(action.node, true, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Stop Trading Session':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.tradingSessionFunctions.stopSession(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Learning Session':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.learningSessionFunctions.runSession(action.node, false, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Resume Learning Session':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.learningSessionFunctions.runSession(action.node, true, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Stop Learning Session':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.learningSessionFunctions.stopSession(action.node, action.callBackFunction)
|
||||
}
|
||||
break
|
||||
case 'Run Super Action':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.superScriptsFunctions.runSuperScript(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Parent Attach': {
|
||||
UI.projects.superalgos.functionLibraries.chainAttachDetach.chainAttachNode(action.node, action.relatedNode, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Reference Attach': {
|
||||
UI.projects.superalgos.functionLibraries.attachDetach.referenceAttachNode(action.node, action.relatedNode, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Parent Detach':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.chainAttachDetach.chainDetachNode(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Reference Detach':
|
||||
{
|
||||
UI.projects.superalgos.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 = getNodeDefinition(action.node)
|
||||
if (definition !== undefined) {
|
||||
if (definition.docURL !== undefined) {
|
||||
UI.projects.superalgos.spaces.docSpace.navigateTo(definition.docURL)
|
||||
} else {
|
||||
let headName = UI.projects.superalgos.utilities.hierarchy.getHiriarchyHead(action.node).type
|
||||
headName = headName.toLowerCase()
|
||||
headName = headName.split(" ").join("-")
|
||||
let nodeName = action.node.type
|
||||
nodeName = nodeName.toLowerCase()
|
||||
nodeName = nodeName.split(" ").join("-")
|
||||
url = UI.projects.superalgos.globals.docs.DOCUMENTATION_URL_PREFIX + "suite-hierarchy-" + headName + ".html#" + nodeName
|
||||
UI.projects.superalgos.spaces.docSpace.navigateTo(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Projects':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.pluginsFunctions.pluginMissingProjects(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Data Mines':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.pluginsFunctions.pluginMissingDataMines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Trading Mines':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.pluginsFunctions.pluginMissingTradingMines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Trading Systems':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.pluginsFunctions.pluginMissingTradingSystems(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Trading Engines':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.pluginsFunctions.pluginMissingTradingEngines(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Super Scripts':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.pluginsFunctions.pluginMissingSuperScripts(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Plugin Tutorials':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.pluginsFunctions.pluginMissingTutorials(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Add Missing Workspace Projects':
|
||||
{
|
||||
UI.projects.superalgos.functionLibraries.workspaceFunctions.addMissingWorkspaceProjects(action.node, action.rootNodes)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
function newSuperalgosFunctionLibraryChainAttachDetach() {
|
||||
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 nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
/* Detach from parent */
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
let parentNodeDefinition = getNodeDefinition(node.payload.parentNode)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[i]
|
||||
if (nodeDefinition.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
node.payload.parentNode = attachToNode
|
||||
node.payload.chainParent = attachToNode
|
||||
/* Attach to new parent */
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
let parentNodeDefinition = getNodeDefinition(node.payload.parentNode)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[i]
|
||||
if (nodeDefinition.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,379 @@
|
||||
function newSuperalgosFunctionLibraryChartingSpaceFunctions() {
|
||||
thisObject = {
|
||||
addAllLayerPanels: addAllLayerPanels,
|
||||
addAllLayerPolygons: addAllLayerPolygons,
|
||||
addAllMineLayers: addAllMineLayers,
|
||||
addMissingDashboards: addMissingDashboards,
|
||||
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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Bot Layers')
|
||||
botLayers.name = bot.name
|
||||
|
||||
UI.projects.superalgos.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.superalgos.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.superalgos.utilities.meshes.findNodeInNodeMesh(layer, 'Plotter Module', undefined, true, false, false, true)
|
||||
if (plotterModule === undefined) {
|
||||
UI.projects.superalgos.functionLibraries.nodeDeleter.deleteUIObject(layer, rootNodes)
|
||||
}
|
||||
}
|
||||
/*
|
||||
For each of the layers we will not create the Layer Panels and Layer Polygons.
|
||||
*/
|
||||
allLayers = UI.projects.superalgos.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.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Backtesting Session')
|
||||
let fordwardTestingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Forward Testing Session')
|
||||
let paperTradingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Paper Trading Session')
|
||||
let liveTradingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Live Trading Session')
|
||||
let learningSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Learning Session')
|
||||
|
||||
scanSessionArray(backtestingSessionsArray)
|
||||
scanSessionArray(fordwardTestingSessionsArray)
|
||||
scanSessionArray(paperTradingSessionsArray)
|
||||
scanSessionArray(liveTradingSessionsArray)
|
||||
scanSessionArray(learningSessionsArray)
|
||||
|
||||
function scanSessionArray(sessionsArray) {
|
||||
for (let i = 0; i < sessionsArray.length; i++) {
|
||||
let session = sessionsArray[i]
|
||||
let environment = UI.projects.superalgos.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.superalgos.utilities.meshes.findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false)
|
||||
if (market.payload.referenceParent === undefined) { continue }
|
||||
if (UI.projects.superalgos.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.superalgos.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.superalgos.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 filer 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.superalgos.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.superalgos.utilities.meshes.findNodeInNodeMesh(timelineChart.layerManager, undefined, nodeName, true, true, false, false)
|
||||
if (nodeToDelete === undefined) { return }
|
||||
UI.projects.superalgos.functionLibraries.nodeDeleter.deleteUIObject(nodeToDelete, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
We need to create a Timeline Chart for each Data Mine Products.
|
||||
*/
|
||||
mineProducts = UI.projects.superalgos.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.superalgos.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')
|
||||
}
|
||||
/*
|
||||
We need to create a Timeline Chart for each Learning Mine Products.
|
||||
*/
|
||||
mineProducts = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Learning 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.parentNode.payload.referenceParent === undefined) { continue }
|
||||
if (mineProduct.payload.parentNode.payload.parentNode.payload.referenceParent.id !== market.id) { continue }
|
||||
|
||||
let timelineChart = UI.projects.superalgos.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 + ' Learning'
|
||||
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 testingEnvironment = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, 'Testing Environment', node, true)
|
||||
let productionEnvironment = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, 'Production Environment', node, true)
|
||||
|
||||
if (UI.projects.superalgos.utilities.children.isMissingChildren(node, testingEnvironment, true) === true) {
|
||||
let dashboard = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Dashboard')
|
||||
dashboard.payload.referenceParent = testingEnvironment
|
||||
dashboard.name = testingEnvironment.type + ' ' + networkNode.name
|
||||
}
|
||||
|
||||
if (UI.projects.superalgos.utilities.children.isMissingChildren(node, productionEnvironment, true) === true) {
|
||||
let dashboard = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Dashboard')
|
||||
dashboard.payload.referenceParent = productionEnvironment
|
||||
dashboard.name = productionEnvironment.type + ' ' + networkNode.name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.superalgos.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.superalgos.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,572 @@
|
||||
function newSuperalgosFunctionLibraryCryptoEcosystemFunctions() {
|
||||
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.superalgos.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.superalgos.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.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(asset.payload, 'codeName')
|
||||
currentAssets.set(codeName, asset)
|
||||
}
|
||||
|
||||
let exchangeId = UI.projects.superalgos.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.superalgos.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.superalgos.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.superalgos.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.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(asset.payload, 'codeName')
|
||||
currentMarkets.set(codeName, asset)
|
||||
}
|
||||
|
||||
let exchangeId = UI.projects.superalgos.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.superalgos.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.superalgos.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 = []
|
||||
|
||||
installDataMiningTasks()
|
||||
installLearningMiningTasks()
|
||||
isntallTradingMiningTasks()
|
||||
|
||||
installDataMinesData()
|
||||
installLearningMinesData()
|
||||
installTradingMineData()
|
||||
|
||||
function installDataMiningTasks() {
|
||||
/*
|
||||
Here we complete the missing stuff at Data Mining
|
||||
*/
|
||||
let dataMining = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, 'Data Mining', node, true)
|
||||
if (dataMining === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Data Mining node not found at Network Node ' + networkNode.name)
|
||||
return
|
||||
}
|
||||
|
||||
let exchangeDataTasks = UI.projects.superalgos.utilities.children.findOrCreateChildWithReference(dataMining, 'Exchange Data Tasks', cryptoExchange)
|
||||
exchangeDataTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketDataTask = UI.projects.superalgos.utilities.children.findAndRecreateChildWithReference(exchangeDataTasks, 'Market Data Tasks', market, rootNodes)
|
||||
|
||||
UI.projects.superalgos.utilities.menu.menuClick(marketDataTask, 'Add Missing Data Mine Tasks', true)
|
||||
UI.projects.superalgos.utilities.menu.menuClickOfNodeArray(marketDataTask.dataMineTasks, 'Add All Tasks', true)
|
||||
}
|
||||
|
||||
function installLearningMiningTasks() {
|
||||
/*
|
||||
Here we complete the missing stuff at Learning Mining
|
||||
*/
|
||||
let learningMining = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, 'Learning Mining', node, true)
|
||||
if (learningMining === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Learning Mining node not found at Network Node ' + networkNode.name)
|
||||
return
|
||||
}
|
||||
|
||||
let exchangeLearningTasks = UI.projects.superalgos.utilities.children.findOrCreateChildWithReference(learningMining, 'Exchange Learning Tasks', cryptoExchange)
|
||||
exchangeLearningTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketLearningTask = UI.projects.superalgos.utilities.children.findAndRecreateChildWithReference(exchangeLearningTasks, 'Market Learning Tasks', market, rootNodes)
|
||||
|
||||
UI.projects.superalgos.utilities.menu.menuClick(marketLearningTask, 'Add Missing Learning Mine Tasks', true)
|
||||
UI.projects.superalgos.utilities.menu.menuClickOfNodeArray(marketLearningTask.learningMineTasks, 'Add All Tasks', true)
|
||||
|
||||
/* This will be needed at the charting space, for creating Dashboards */
|
||||
let learningSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(marketLearningTask, 'Learning Session')
|
||||
learningSessionsCreatedArray = learningSessionsCreatedArray.concat(learningSessionsArray)
|
||||
}
|
||||
|
||||
function isntallTradingMiningTasks() {
|
||||
/*
|
||||
Next we complete the missing stuff at Testing Environment
|
||||
*/
|
||||
installEnvironment('Testing Environment')
|
||||
/*
|
||||
Next we complete the missing stuff at Production Environment
|
||||
*/
|
||||
installEnvironment('Production Environment')
|
||||
|
||||
function installEnvironment(environment) {
|
||||
/*
|
||||
Now we install the environmnet at the current Network Node
|
||||
*/
|
||||
let environmentFound = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, environment, node, true)
|
||||
if (environmentFound === undefined) {
|
||||
node.payload.uiObject.setErrorMessage(environment + ' node not found at Network Node ' + networkNode.name)
|
||||
return
|
||||
}
|
||||
|
||||
let exchangeTradingTasks = UI.projects.superalgos.utilities.children.findOrCreateChildWithReference(environmentFound, 'Exchange Trading Tasks', cryptoExchange)
|
||||
exchangeTradingTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketTradingTask = UI.projects.superalgos.utilities.children.findAndRecreateChildWithReference(exchangeTradingTasks, 'Market Trading Tasks', market, rootNodes)
|
||||
|
||||
UI.projects.superalgos.utilities.menu.menuClick(marketTradingTask, 'Add Missing Trading Mine Tasks', true)
|
||||
UI.projects.superalgos.utilities.menu.menuClickOfNodeArray(marketTradingTask.tradingMineTasks, 'Add All Tasks', true)
|
||||
|
||||
/* This will be needed at the charting space, for creating Dashboards */
|
||||
let backtestingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(marketTradingTask, 'Backtesting Session')
|
||||
let liveTradingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(marketTradingTask, 'Live Trading Session')
|
||||
let paperTradingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(marketTradingTask, 'Paper Trading Session')
|
||||
let forwardSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(marketTradingTask, 'Forward Testing Session')
|
||||
let allSessionsArray = backtestingSessionsArray
|
||||
.concat(liveTradingSessionsArray)
|
||||
.concat(paperTradingSessionsArray)
|
||||
.concat(forwardSessionsArray)
|
||||
tradingSessionsCreatedArray = tradingSessionsCreatedArray.concat(allSessionsArray)
|
||||
|
||||
dashboardsArray.push({ environmentNode: environmentFound, networkNode: networkNode, sessionsArray: allSessionsArray })
|
||||
}
|
||||
}
|
||||
|
||||
function installDataMinesData() {
|
||||
/*
|
||||
Here we complete the missing stuff at Data Mines Data
|
||||
*/
|
||||
let dataMinesData = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, 'Data Mines Data', node, true)
|
||||
if (dataMinesData === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Data Mines Data node not found at Network Node ' + networkNode.name)
|
||||
return
|
||||
}
|
||||
|
||||
let exchangeDataProducts = UI.projects.superalgos.utilities.children.findOrCreateChildWithReference(dataMinesData, 'Exchange Data Products', cryptoExchange)
|
||||
exchangeDataProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketDataProducts = UI.projects.superalgos.utilities.children.findAndRecreateChildWithReference(exchangeDataProducts, 'Market Data Products', market, rootNodes)
|
||||
marketDataProducts.payload.floatingObject.collapseToggle()
|
||||
|
||||
UI.projects.superalgos.utilities.menu.menuClick(marketDataProducts, 'Add All Data Mine Products', true)
|
||||
UI.projects.superalgos.utilities.menu.menuClickOfNodeArray(marketDataProducts.dataMineProducts, 'Add All Data Products', true)
|
||||
}
|
||||
|
||||
function installLearningMinesData() {
|
||||
/*
|
||||
Here we complete the missing stuff at Learning Mines Data
|
||||
*/
|
||||
let learningMinesData = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, 'Learning Mines Data', node, true)
|
||||
if (learningMinesData === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Learning Mines Data node not found at Network Node ' + networkNode.name)
|
||||
return
|
||||
}
|
||||
|
||||
let exchangeLearningProducts = UI.projects.superalgos.utilities.children.findOrCreateChildWithReference(learningMinesData, 'Exchange Learning Products', cryptoExchange)
|
||||
exchangeLearningProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketLearningProducts = UI.projects.superalgos.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.superalgos.utilities.children.isMissingChildren(marketLearningProducts, session, true) === true) {
|
||||
UI.projects.superalgos.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.superalgos.utilities.menu.menuClick(sessionReference, 'Add All Learning Mine Products', true)
|
||||
UI.projects.superalgos.utilities.menu.menuClickOfNodeArray(sessionReference.learningMineProducts, 'Add All Data Products', true)
|
||||
sessionReference.payload.floatingObject.collapseToggle()
|
||||
}
|
||||
}
|
||||
|
||||
function installTradingMineData() {
|
||||
/*
|
||||
Finally we complete the missing stuff at Trading Mines Data
|
||||
*/
|
||||
let tradingMinesData = UI.projects.superalgos.utilities.branches.findInBranch(networkNode, 'Trading Mines Data', node, true)
|
||||
if (tradingMinesData === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Trading Mines Data node not found at Network Node ' + networkNode.name)
|
||||
return
|
||||
}
|
||||
|
||||
let exchangeTradingProducts = UI.projects.superalgos.utilities.children.findOrCreateChildWithReference(tradingMinesData, 'Exchange Trading Products', cryptoExchange)
|
||||
exchangeTradingProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
let marketTradingProducts = UI.projects.superalgos.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.superalgos.utilities.children.isMissingChildren(marketTradingProducts, session, true) === true) {
|
||||
UI.projects.superalgos.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.superalgos.utilities.menu.menuClick(sessionReference, 'Add All Trading Mine Products', true)
|
||||
UI.projects.superalgos.utilities.menu.menuClickOfNodeArray(sessionReference.tradingMineProducts, 'Add All Data Products', true)
|
||||
sessionReference.payload.floatingObject.collapseToggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function installInChartingSpace(chartingSpace) {
|
||||
|
||||
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.superalgos.utilities.children.findOrCreateChildWithReference(chartingSpace, '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.superalgos.functionLibraries.nodeDeleter.deleteUIObject(timeMachine, rootNodes)
|
||||
continue
|
||||
}
|
||||
let marketTradingTasks = UI.projects.superalgos.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.superalgos.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.superalgos.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.superalgos.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.superalgos.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.superalgos.functionLibraries.nodeDeleter.deleteUIObject(timeMachine, rootNodes)
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete all Dashboards that does not have time machines inside. */
|
||||
let dashboardArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(chartingSpace, 'Dashboard')
|
||||
for (let i = 0; i < dashboardArray.length; i++) {
|
||||
let dashboard = dashboardArray[i]
|
||||
if (dashboard.timeMachines.length === 0) {
|
||||
UI.projects.superalgos.functionLibraries.nodeDeleter.deleteUIObject(dashboard, 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.superalgos.utilities.branches.nodeBranchToArray(network, 'Market Data Tasks')
|
||||
let marketTradingTasksArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(network, 'Market Trading Tasks')
|
||||
let marketLearningTasksArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(network, 'Market Learning Tasks')
|
||||
let marketDataProductsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(network, 'Market Data Products')
|
||||
let marketTradingProductsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(network, 'Market Trading Products')
|
||||
let marketLearningProductsArray = UI.projects.superalgos.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) {
|
||||
UI.projects.superalgos.functionLibraries.nodeDeleter.deleteUIObject(marketReference, rootNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
function newSuperalgosFunctionLibraryDataStorageFunctions() {
|
||||
thisObject = {
|
||||
addAllDataProducts: addAllDataProducts,
|
||||
addAllDataMineProducts: addAllDataMineProducts,
|
||||
addAllTradingMineProducts: addAllTradingMineProducts,
|
||||
addAllLearningMineProducts: addAllLearningMineProducts,
|
||||
addMissingTradingSessionReferences: addMissingTradingSessionReferences,
|
||||
addMissingLearningSessionReferences: addMissingLearningSessionReferences,
|
||||
addMissingMarketDataProducts: addMissingMarketDataProducts,
|
||||
addMissingMarketTradingProducts: addMissingMarketTradingProducts,
|
||||
addMissingExchangeTradingProducts: addMissingExchangeTradingProducts,
|
||||
addMissingExchangeDataProducts: addMissingExchangeDataProducts,
|
||||
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.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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Bot Products')
|
||||
botProducts.name = bot.name
|
||||
botProducts.payload.floatingObject.collapseToggle()
|
||||
|
||||
UI.projects.superalgos.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.superalgos.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.superalgos.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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Learning Mine Products')
|
||||
learningMineProducts.payload.referenceParent = rootNode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingTradingSessionReferences(node, rootNodes) {
|
||||
let networkNode = UI.projects.superalgos.utilities.meshes.findNodeInNodeMesh(node, 'Network Node', undefined, true, false, true, false)
|
||||
if (networkNode === undefined) { return }
|
||||
|
||||
let backtestingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Backtesting Session')
|
||||
let fordwardTestingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Forward Testing Session')
|
||||
let paperTradingSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Paper Trading Session')
|
||||
let liveTradingSessionsArray = UI.projects.superalgos.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.superalgos.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.superalgos.utilities.children.isMissingChildren(node, session, true) === true) {
|
||||
createSessionReference(node, session, 'Trading Session Reference')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingLearningSessionReferences(node, rootNodes) {
|
||||
let networkNode = UI.projects.superalgos.utilities.meshes.findNodeInNodeMesh(node, 'Network Node', undefined, true, false, true, false)
|
||||
if (networkNode === undefined) { return }
|
||||
|
||||
let learningSessionsArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(networkNode, 'Learning Session')
|
||||
|
||||
addMissingSession(learningSessionsArray)
|
||||
|
||||
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.superalgos.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.superalgos.utilities.children.isMissingChildren(node, session, true) === true) {
|
||||
createSessionReference(node, session, 'Learning Session Reference')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createSessionReference(node, session, nodeType) {
|
||||
let sessionReference = UI.projects.superalgos.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 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.superalgos.utilities.children.isMissingChildren(node, market, true) === true) {
|
||||
let marketDataProducts = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
|
||||
marketDataProducts.payload.referenceParent = market
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMissingExchangeTradingProducts(node, rootNodes) {
|
||||
addMissingExchange(node, rootNodes, 'Exchange Trading Products')
|
||||
}
|
||||
|
||||
function addMissingExchangeDataProducts(node, rootNodes) {
|
||||
addMissingExchange(node, rootNodes, 'Exchange Data 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.superalgos.utilities.children.isMissingChildren(node, cryptoExchange, true) === true) {
|
||||
let exchange = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
|
||||
exchange.payload.referenceParent = cryptoExchange
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
function newSuperalgosFunctionLibraryDependenciesFilter() {
|
||||
thisObject = {
|
||||
createFilter: createFilter
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function createFilter(node) {
|
||||
let filters = new Map()
|
||||
recursiveFilter(node)
|
||||
|
||||
return Array.from(filters.keys())
|
||||
|
||||
function recursiveFilter(node) {
|
||||
filter(node.code)
|
||||
|
||||
let nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
if (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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 }
|
||||
|
||||
let instructionsArray = code.split(' ')
|
||||
for (let i = 0; i < instructionsArray.length; i++) {
|
||||
let instruction = instructionsArray[i]
|
||||
if (instruction.indexOf('chart') >= 0) {
|
||||
let parts = instruction.split('.')
|
||||
let timeFrame = parts[1]
|
||||
let product = parts[2]
|
||||
let productParts = product.split(',')
|
||||
product = productParts[0]
|
||||
productParts = product.split(')')
|
||||
product = productParts[0]
|
||||
|
||||
// Example: chart.at01hs.popularSMA.sma200 - chart.at01hs.popularSMA.sma100 < 10
|
||||
if (timeFrame !== 'atAnyTimeFrame') {
|
||||
timeFrame = timeFrame.substring(2, 4) + '-' + timeFrame.substring(4, 7)
|
||||
}
|
||||
filters.set(timeFrame + '-' + product, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
function newSuperalgosFunctionLibraryLearningSessionFunctions() {
|
||||
thisObject = {
|
||||
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
|
||||
runSession: runSession,
|
||||
stopSession: stopSession
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function syncronizeSessionWithBackEnd(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.superalgos.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 networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.superalgos.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
node.payload.uiObject.run(eventsServerClient, callBackFunction)
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
|
||||
let lightingPath = '' +
|
||||
'Trading System->' +
|
||||
'Dynamic Indicators->Indicator Function->Formula->' +
|
||||
'Trading Strategy->' +
|
||||
'Trigger Stage->Trigger On Event->Trigger Off Event->Take Position Event->' +
|
||||
'Announcement->Announcement Formula->' +
|
||||
'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->' +
|
||||
'Announcement->Announcement 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->' +
|
||||
'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->'
|
||||
|
||||
let tradingSystem = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(node.tradingSystemReference.payload.referenceParent, false, true, true, false, false, lightingPath)
|
||||
|
||||
lightingPath = '' +
|
||||
'Trading Engine->' +
|
||||
'Dynamic Indicators->Indicator Function->' +
|
||||
'Current->Last->Previous->' +
|
||||
'Episode->' +
|
||||
'Episode Base Asset->Episode Quoted Asset->Episode Counters->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 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->'
|
||||
|
||||
let tradingEngine = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(node.tradingEngineReference.payload.referenceParent, false, true, true, false, false, lightingPath)
|
||||
|
||||
lightingPath = '' +
|
||||
'Learning Session->' +
|
||||
'Learning Parameters->' +
|
||||
'Session Base Asset->Session Quoted Asset->Time Range->Time Frame->Slippage->Fee Structure->Snapshots->Heartbeats->User Defined Parameters->' +
|
||||
'Exchange Account Asset->Asset->' +
|
||||
'Social Bots->Telegram Bot->'
|
||||
|
||||
let session = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(node, false, true, true, false, false, lightingPath)
|
||||
|
||||
let dependencyFilter = UI.projects.superalgos.functionLibraries.dependenciesFilter.createFilter(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 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 networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.superalgos.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) {
|
||||
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
|
||||
}
|
||||
|
||||
let taskManager = node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
|
||||
if (taskManager.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Mine Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Market Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Exchange Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Testing or Production Environment.')
|
||||
return
|
||||
}
|
||||
|
||||
if (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
|
||||
}
|
||||
|
||||
let networkNode = taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
|
||||
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
|
||||
}
|
||||
return networkNode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
function newSuperalgosFunctionLibraryMineFunctions() {
|
||||
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.superalgos.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.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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Bot Data Dependencies')
|
||||
botProducts.name = bot.name
|
||||
|
||||
UI.projects.superalgos.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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Data Mine Data Dependencies')
|
||||
dataMineDataDependencies.payload.referenceParent = rootNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
function newNodeChildren() {
|
||||
thisObject = {
|
||||
childrenCount: childrenCount
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function childrenCount(parentNode, childNode) {
|
||||
return countChildrenUiObject(parentNode, childNode)
|
||||
}
|
||||
|
||||
function countChildrenUiObject(parentNode, childNode) {
|
||||
let response = {
|
||||
childrenCount: 0,
|
||||
childIndex: undefined
|
||||
}
|
||||
let parentNodeDefinition = getNodeDefinition(parentNode)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
if (parentNodeDefinition.properties !== 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 < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[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 nodeDefinition = getNodeDefinition(childNode)
|
||||
if (nodeDefinition !== undefined) {
|
||||
let nodePropertyArray = parentNode[property.name]
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let child = nodePropertyArray[j]
|
||||
if (nodeDefinition.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 newSuperalgosFunctionLibraryNodeCloning() {
|
||||
const MODULE_NAME = 'Node Cloning'
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
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 nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
let object = {
|
||||
type: node.type,
|
||||
name: node.name,
|
||||
code: node.code,
|
||||
config: node.config,
|
||||
project: node.project
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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 nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
let object = {
|
||||
type: node.type,
|
||||
name: node.name,
|
||||
code: node.code,
|
||||
config: node.config,
|
||||
project: node.project
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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,149 @@
|
||||
function newSuperalgosFunctionLibraryNodeDeleter() {
|
||||
thisObject = {
|
||||
deleteWorkspace: deleteWorkspace,
|
||||
deleteUIObject: deleteUIObject
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function destroyUiObject(node) {
|
||||
UI.projects.superalgos.spaces.floatingSpace.uiObjectConstructor.destroyUiObject(node.payload)
|
||||
}
|
||||
|
||||
function deleteWorkspace(node, rootNodes) {
|
||||
if (node.rootNodes !== undefined) {
|
||||
while (node.rootNodes.length > 0) {
|
||||
let rootNode = node.rootNodes[0]
|
||||
let result = deleteUIObject(rootNode, rootNodes)
|
||||
if (result === false) { return false}
|
||||
}
|
||||
}
|
||||
|
||||
completeDeletion(node, rootNodes)
|
||||
destroyUiObject(node)
|
||||
cleanNode(node)
|
||||
}
|
||||
|
||||
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 nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
/* Remove all of its own children nodes. */
|
||||
if (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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 */
|
||||
let removedFromParent = false
|
||||
if (node.payload !== undefined) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
let parentNodeDefinition = getNodeDefinition(node.payload.parentNode)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[i]
|
||||
if (nodeDefinition.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 (nodeDefinition.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 (' + nodeDefinition.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.subTitle = 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 newSuperalgosFunctionLibraryNodePath() {
|
||||
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 nodeDefinition = getNodeDefinition(node.payload.parentNode)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
if (nodeDefinition.properties === undefined) { return }
|
||||
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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 newSuperalgosFunctionLibraryOnFocus() {
|
||||
thisObject = {
|
||||
getNodeThatIsOnFocus: getNodeThatIsOnFocus
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getNodeThatIsOnFocus(node) {
|
||||
if (node === undefined || node === null) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
let nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== 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 (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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,171 @@
|
||||
function newSuperalgosFunctionLibraryPluginsFunctions() {
|
||||
thisObject = {
|
||||
pluginMissingProjects: pluginMissingProjects,
|
||||
pluginMissingDataMines: pluginMissingDataMines,
|
||||
pluginMissingTradingMines: pluginMissingTradingMines,
|
||||
pluginMissingTradingSystems: pluginMissingTradingSystems,
|
||||
pluginMissingTradingEngines: pluginMissingTradingEngines,
|
||||
pluginMissingSuperScripts: pluginMissingSuperScripts,
|
||||
pluginMissingTutorials: pluginMissingTutorials
|
||||
}
|
||||
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 Backend')
|
||||
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.superalgos.utilities.children.isMissingChildrenByName(node, fileName) === true) {
|
||||
let child = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Plugin File')
|
||||
child.name = fileName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pluginMissingProjects(node, rootNodes) {
|
||||
let url = 'ProjectNames'
|
||||
httpRequest(undefined, url, onResponse)
|
||||
|
||||
function onResponse(err, pProjects) {
|
||||
let projects = JSON.parse(pProjects)
|
||||
for (let i = 0; i < projects.length; i++) {
|
||||
let project = projects[i]
|
||||
if (UI.projects.superalgos.utilities.children.isMissingChildrenByName(node, project) === true) {
|
||||
let child = UI.projects.superalgos.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 pluginMissingSuperScripts(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, 'Super-Scripts', 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
function newSuperalgosFunctionLibraryProtocolNode() {
|
||||
const MODULE_NAME = 'Protocol Node'
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
thisObject = {
|
||||
getProtocolNode: getProtocolNode
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getProtocolNode(node, removePersonalData, parseConfig, includeIds, includePayload, includeReferencesInSavedPayload, lightingPath) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
|
||||
let nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
if (removePersonalData === true && nodeDefinition.isPersonalData === true) { return }
|
||||
let object = {
|
||||
type: node.type,
|
||||
name: node.name,
|
||||
code: node.code,
|
||||
config: node.config,
|
||||
project: node.project
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
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)
|
||||
} 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 && nodeDefinition.editors !== undefined) {
|
||||
if (nodeDefinition.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.
|
||||
*/
|
||||
if (currentNodeType === nextNodeType) {
|
||||
let tempLightingPath = lightingPath.substring(currentNodePosition + currentNodeType.length, lightingPath.length + 1)
|
||||
nextNodePosition = tempLightingPath.indexOf('->' + nextNodeType + '->')
|
||||
}
|
||||
|
||||
let newLightingPath = lightingPath.substring(nextNodePosition, lightingPath.length + 1)
|
||||
|
||||
if (nextNodePosition > currentNodePosition) {
|
||||
return newLightingPath
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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 newSuperalgosFunctionLibraryAttachDetach() {
|
||||
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 newSuperalgosFunctionLibraryShortcutKeys() {
|
||||
thisObject = {
|
||||
getNodeByShortcutKey: getNodeByShortcutKey
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getNodeByShortcutKey(node, searchingKey) {
|
||||
if (node === undefined) { return }
|
||||
let nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== 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 (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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,90 @@
|
||||
function newSuperalgosFunctionLibrarySuperScriptsFunctions() {
|
||||
thisObject = {
|
||||
runSuperScript: runSuperScript
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function runSuperScript(node, rootNodes) {
|
||||
try {
|
||||
let clone = UI.projects.superalgos.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.superalgos.functionLibraries.uiObjectsFromNodes.createUiObjectFromNode(templateClone, target, target)
|
||||
} else {
|
||||
let definition = getNodeDefinition(target)
|
||||
for (let i = 0; i < definition.properties.length; i++) {
|
||||
let property = definition.properties[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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(target, exchangeNodeType)
|
||||
targetExchange.payload.referenceParent = exchange
|
||||
}
|
||||
let nodesArray = targetExchange[arrayPropertyName]
|
||||
nodesArray.push(templateClone)
|
||||
UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.createUiObjectFromNode(templateClone, targetExchange, targetExchange)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function deleteNode(node) {
|
||||
UI.projects.superalgos.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,750 @@
|
||||
function newSuperalgosFunctionLibraryTaskFunctions() {
|
||||
thisObject = {
|
||||
syncronizeTaskWithBackEnd: syncronizeTaskWithBackEnd,
|
||||
|
||||
runTask: runTask,
|
||||
stopTask: stopTask,
|
||||
runAllTasks: runAllTasks,
|
||||
stopAllTasks: stopAllTasks,
|
||||
runAllTaskManagers: runAllTaskManagers,
|
||||
stopAllTaskManagers: stopAllTaskManagers,
|
||||
|
||||
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,
|
||||
|
||||
addMissingExchangeDataTasks: addMissingExchangeDataTasks,
|
||||
addMissingMarketDataTasks: addMissingMarketDataTasks,
|
||||
addMissingDataMineTasks: addMissingDataMineTasks,
|
||||
addMissingExchangeTradingTasks: addMissingExchangeTradingTasks,
|
||||
addMissingMarketTradingTasks: addMissingMarketTradingTasks,
|
||||
addMissingTradingMineTasks: addMissingTradingMineTasks,
|
||||
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.superalgos.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.superalgos.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->' +
|
||||
'Indicator Bot Instance->Time Frames Filter->' +
|
||||
'Trading Bot Instance->' +
|
||||
'Learning Bot Instance->' +
|
||||
'Sensor 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->' +
|
||||
'Backtesting Session->Live Trading Session->Paper Trading Session->Forward Testing Session->' +
|
||||
'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->' +
|
||||
'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->Formula->' +
|
||||
'Data Building Procedure->' +
|
||||
'Procedure Initialization->Javascript Code->' +
|
||||
'Procedure Loop->Javascript Code->' +
|
||||
'Calculations Procedure->' +
|
||||
'Procedure Initialization->Javascript Code->' +
|
||||
'Procedure Loop->Javascript Code->' +
|
||||
'Status Report->' +
|
||||
'Execution Finished Event->' +
|
||||
'Execution Started Event->Execution Finished Event->Process Definition->' +
|
||||
'Sensor Bot->' +
|
||||
'Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->' +
|
||||
'Indicator Bot->' +
|
||||
'Trading Bot->' +
|
||||
'Learning Bot->' +
|
||||
'Data Mine->Trading Mine->Learning Mine->'
|
||||
|
||||
let taskDefinition = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(node, false, true, true, false, false, taskLightingPath)
|
||||
|
||||
let networkLightingPath = '->Network->Network Node->' +
|
||||
'Data Storage->Data Mines Data->Exchange Data Products->' +
|
||||
'Market Data Products->' +
|
||||
'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 Mining->Learning Mining->Testing Environment->Production Environment->' +
|
||||
'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->Trading Bot Instance->Learning Bot Instance->' +
|
||||
'Indicator Process Instance->Sensor Process Instance->Trading Process Instance->Learning Process Instance->' +
|
||||
'Paper Trading Session->Forward Testing Session->Backtesting Session->Live Trading Session->Learning Session->' +
|
||||
'Market->' +
|
||||
'Process Definition->'
|
||||
|
||||
let networkDefinition = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(networkNode.payload.parentNode, false, true, true, false, false, networkLightingPath)
|
||||
|
||||
let event = {
|
||||
appSchema: JSON.stringify(SCHEMAS_BY_PROJECT.get('Superalgos').array.appSchema),
|
||||
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.superalgos.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 Mining, Learning Mining, Testing or Production Environment 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 = taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
if (UI.projects.superalgos.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.superalgos.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.superalgos.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 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 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.superalgos.utilities.children.isMissingChildren(node, cryptoExchange, true) === true) {
|
||||
let exchangeTasks = UI.projects.superalgos.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.superalgos.utilities.children.isMissingChildren(node, market, true) === true) {
|
||||
let marketDataTasks = UI.projects.superalgos.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.superalgos.utilities.children.isMissingChildren(node, mine, true) === true) {
|
||||
let dataMineTasks = UI.projects.superalgos.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.superalgos.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() {
|
||||
addTaskForTradinSystem()
|
||||
}
|
||||
|
||||
function addLearningTasks() {
|
||||
addTaskForTradinSystem()
|
||||
}
|
||||
|
||||
function addTradingTasks() {
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === 'Trading System') {
|
||||
addTaskForTradinSystem(rootNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addTaskForTradinSystem(tradingSystem) {
|
||||
let mine = node.payload.referenceParent
|
||||
|
||||
addTasksForBotArray(mine.sensorBots)
|
||||
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 task = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(taskManager, 'Task')
|
||||
|
||||
if (tradingSystem !== undefined) {
|
||||
task.name = tradingSystem.name
|
||||
} else {
|
||||
task.name = bot.name
|
||||
}
|
||||
|
||||
let botInstance
|
||||
switch (bot.type) {
|
||||
case 'Sensor Bot': {
|
||||
botInstance = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Sensor Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
break
|
||||
}
|
||||
case 'Indicator Bot': {
|
||||
botInstance = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Indicator Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
break
|
||||
}
|
||||
case 'Trading Bot': {
|
||||
botInstance = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Trading Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
break
|
||||
}
|
||||
case 'Learning Bot': {
|
||||
botInstance = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(task, 'Learning Bot Instance')
|
||||
botInstance.name = bot.name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'Sensor Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
break
|
||||
}
|
||||
case 'Indicator Bot': {
|
||||
processInstance = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'Indicator Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
break
|
||||
}
|
||||
case 'Trading Bot': {
|
||||
processInstance = UI.projects.superalgos.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 }
|
||||
|
||||
let environment = node.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
let session
|
||||
|
||||
switch (environment.type) {
|
||||
case 'Testing Environment': {
|
||||
addSession('Backtesting Session')
|
||||
break
|
||||
}
|
||||
case 'Production Environment': {
|
||||
addSession('Live Trading Session')
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
function addSession(sessionType) {
|
||||
session = UI.projects.superalgos.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 = tradingSystem
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'Learning Bot': {
|
||||
processInstance = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(botInstance, 'Learning Process Instance')
|
||||
processInstance.payload.referenceParent = process
|
||||
|
||||
let session
|
||||
|
||||
addSession('Learning Session')
|
||||
break
|
||||
|
||||
function addSession(sessionType) {
|
||||
session = UI.projects.superalgos.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 = tradingSystem
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
processInstance.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
function newSuperalgosFunctionLibraryTradingSessionFunctions() {
|
||||
thisObject = {
|
||||
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
|
||||
runSession: runSession,
|
||||
stopSession: stopSession
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function syncronizeSessionWithBackEnd(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.superalgos.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 networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.superalgos.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id)
|
||||
|
||||
node.payload.uiObject.run(eventsServerClient, callBackFunction)
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
|
||||
let lightingPath = '' +
|
||||
'Trading System->' +
|
||||
'Dynamic Indicators->Indicator Function->Formula->' +
|
||||
'Trading Strategy->' +
|
||||
'Trigger Stage->Trigger On Event->Trigger Off Event->Take Position Event->' +
|
||||
'Announcement->Announcement Formula->' +
|
||||
'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->' +
|
||||
'Announcement->Announcement 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->' +
|
||||
'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->'
|
||||
|
||||
let tradingSystem = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(node.tradingSystemReference.payload.referenceParent, false, true, true, false, false, lightingPath)
|
||||
|
||||
lightingPath = '' +
|
||||
'Trading Engine->' +
|
||||
'Dynamic Indicators->Indicator Function->' +
|
||||
'Current->Last->Previous->' +
|
||||
'Episode->' +
|
||||
'Episode Base Asset->Episode Quoted Asset->Episode Counters->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 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->'
|
||||
|
||||
let tradingEngine = UI.projects.superalgos.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->' +
|
||||
'Exchange Account Asset->Asset->' +
|
||||
'Social Bots->Telegram Bot->'
|
||||
|
||||
let session = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(node, false, true, true, false, false, lightingPath)
|
||||
|
||||
let dependencyFilter = UI.projects.superalgos.functionLibraries.dependenciesFilter.createFilter(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 networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* This means that the validations failed. */
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
let eventsServerClient = UI.projects.superalgos.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) {
|
||||
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
|
||||
}
|
||||
|
||||
let taskManager = node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
|
||||
if (taskManager.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Mine Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Market Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside Exchange Tasks.')
|
||||
return
|
||||
}
|
||||
|
||||
if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
|
||||
node.payload.uiObject.setErrorMessage('Session needs to be inside a Testing or Production Environment.')
|
||||
return
|
||||
}
|
||||
|
||||
if (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
|
||||
}
|
||||
|
||||
let networkNode = taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
|
||||
|
||||
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
|
||||
}
|
||||
return networkNode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,681 @@
|
||||
function newSuperalgosFunctionLibraryUiObjectsFromNodes() {
|
||||
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) {
|
||||
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.pluginSuperScripts !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginSuperScripts.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginSuperScripts.pluginFiles, 'Super-Scripts')
|
||||
}
|
||||
if (project.pluginTutorials !== undefined) {
|
||||
totalPlugin = totalPlugin + project.pluginTutorials.pluginFiles.length
|
||||
pluginAllTheseFiles(project.pluginTutorials.pluginFiles, 'Tutorials')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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' + '/' + 'Superalgos' + '/' + 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) {
|
||||
for (let i = 0; i < node.rootNodes.length; i++) {
|
||||
let rootNode = node.rootNodes[i]
|
||||
createUiObjectFromNode(rootNode, undefined, undefined)
|
||||
}
|
||||
}
|
||||
|
||||
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.superalgos.functionLibraries.taskFunctions.syncronizeTaskWithBackEnd(node)
|
||||
}
|
||||
tasksFoundAtWorkspace = undefined
|
||||
}
|
||||
|
||||
function syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd() {
|
||||
for (let i = 0; i < tradingSessionsFoundAtWorkspace.length; i++) {
|
||||
let node = tradingSessionsFoundAtWorkspace[i]
|
||||
UI.projects.superalgos.functionLibraries.tradingSessionFunctions.syncronizeSessionWithBackEnd(node)
|
||||
}
|
||||
tradingSessionsFoundAtWorkspace = undefined
|
||||
}
|
||||
|
||||
function syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd() {
|
||||
for (let i = 0; i < learningSessionsFoundAtWorkspace.length; i++) {
|
||||
let node = learningSessionsFoundAtWorkspace[i]
|
||||
UI.projects.superalgos.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, nodeDefinition) {
|
||||
/* Code needed to Migrante from Beta 5 to Beta a Workspace */
|
||||
if (nodeDefinition.editors !== undefined) {
|
||||
if (nodeDefinition.editors.config === true) {
|
||||
if (node.code !== undefined) {
|
||||
node.config = node.code
|
||||
node.code = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createUiObjectFromNode(node, parentNode, chainParent, positionOffset) {
|
||||
/* Migration code from beta 6 to beta 7 */
|
||||
if (node.project === undefined) {
|
||||
node.project = 'Superalgos'
|
||||
}
|
||||
|
||||
/*
|
||||
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 node definition */
|
||||
let nodeDefinition = getNodeDefinition(node)
|
||||
if (nodeDefinition !== undefined) {
|
||||
migrateCodeToConfig(node, nodeDefinition)
|
||||
|
||||
/* Resolve Initial Values */
|
||||
if (nodeDefinition.initialValues !== undefined) {
|
||||
if (nodeDefinition.initialValues.code !== undefined) {
|
||||
if (node.code === undefined) {
|
||||
node.code = nodeDefinition.initialValues.code
|
||||
}
|
||||
}
|
||||
if (nodeDefinition.initialValues.config !== undefined) {
|
||||
if (node.config === undefined) {
|
||||
node.config = nodeDefinition.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 (nodeDefinition.chainedToSameType === true) {
|
||||
if (parentNode !== undefined) {
|
||||
let parentNodeDefinition = getNodeDefinition(parentNode)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[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 (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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 parentNodeDefinition = getNodeDefinition(parentNode, project)
|
||||
if (parentNodeDefinition === undefined) {
|
||||
console.log('Cannot addUIOBject from parent of ' + type + ' because that type it is not defined at the APP_SCHEMA.')
|
||||
}
|
||||
/* Resolve Initial Values */
|
||||
let nodeDefinition = getNodeDefinition(object, project)
|
||||
|
||||
if (nodeDefinition === undefined) {
|
||||
console.log('Cannot addUIOBject of ' + type + ' because that type it is not defined at the APP_SCHEMA.')
|
||||
return
|
||||
}
|
||||
|
||||
if (nodeDefinition.initialValues !== undefined) {
|
||||
if (nodeDefinition.initialValues.code !== undefined) {
|
||||
object.code = nodeDefinition.initialValues.code
|
||||
}
|
||||
}
|
||||
if (nodeDefinition.initialValues !== undefined) {
|
||||
if (nodeDefinition.initialValues.config !== undefined) {
|
||||
object.config = nodeDefinition.initialValues.config
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeDefinition.isHierarchyHead === true || nodeDefinition.isProjectHead) {
|
||||
rootNodes.push(object)
|
||||
createUiObject(true, object.type, object.name, object, parentNode, undefined)
|
||||
return object
|
||||
}
|
||||
|
||||
/* For the cases where an node is not chained to its parent but to the one at the parent before it at its collection */
|
||||
let chainParent = parentNode
|
||||
if (nodeDefinition.chainedToSameType === true) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[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]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Create Empty Arrays for properties of type Array */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
if (property.type === 'array') {
|
||||
object[property.name] = []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeDefinition.initialValues !== undefined) {
|
||||
if (nodeDefinition.initialValues.code !== undefined) {
|
||||
object.code = nodeDefinition.initialValues.code
|
||||
}
|
||||
if (nodeDefinition.initialValues.config !== undefined) {
|
||||
object.config = nodeDefinition.initialValues.config
|
||||
}
|
||||
}
|
||||
|
||||
/* Connect to Parent */
|
||||
if (parentNodeDefinition.properties !== 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 < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createUiObject(true, object.type, object.name, object, parentNode, chainParent)
|
||||
|
||||
/* Auto Add more Children */
|
||||
if (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
if (property.autoAdd === true) {
|
||||
addUIObject(object, property.childType)
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
if (property.autoAdd === true) {
|
||||
if (object[property.name] === undefined) {
|
||||
object[property.name] = []
|
||||
}
|
||||
addUIObject(object, property.childType)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return object
|
||||
}
|
||||
|
||||
function addMissingChildren(node, rootNodes) {
|
||||
let nodeDefinition = getNodeDefinition(node)
|
||||
|
||||
/* Connect to Parent */
|
||||
if (nodeDefinition.properties !== 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 < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Setting the title */
|
||||
if (title !== undefined) {
|
||||
payload.subTitle = title
|
||||
} else {
|
||||
payload.subTitle = uiObjectType
|
||||
}
|
||||
|
||||
payload.visible = true
|
||||
payload.title = name
|
||||
payload.node = node
|
||||
payload.parentNode = parentNode
|
||||
payload.chainParent = chainParent
|
||||
payload.executeAction = UI.projects.superalgos.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.superalgos.utilities.loadSaveFrame.saveFrame(payload, frame)
|
||||
}
|
||||
if (node.savedPayload.tutorial !== undefined) {
|
||||
let tutorial = {
|
||||
status: node.savedPayload.tutorial.status
|
||||
}
|
||||
UI.projects.superalgos.utilities.tutorial.saveTutorial(payload, tutorial)
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we mount the floating object where the UIOBject will be laying on top of */
|
||||
UI.projects.superalgos.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 backend */
|
||||
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,22 @@
|
||||
function newSuperalgosFunctionLibraryWebhookFunctions() {
|
||||
thisObject = {
|
||||
sendTestMessage: sendTestMessage
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function sendTestMessage(node, callBackFunction) {
|
||||
let testMessage = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'testMessage')
|
||||
let letURL = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'webhookURL')
|
||||
|
||||
httpRequest(testMessage, letURL, onResponse)
|
||||
|
||||
function onResponse(err) {
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
} else {
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
function newSuperalgosFunctionLibraryWorkspaceFunctions() {
|
||||
thisObject = {
|
||||
addMissingWorkspaceProjects: addMissingWorkspaceProjects
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function addMissingWorkspaceProjects(node, rootNodes) {
|
||||
let url = 'ProjectNames'
|
||||
httpRequest(undefined, url, onResponse)
|
||||
|
||||
function onResponse(err, pProjects) {
|
||||
let projects = JSON.parse(pProjects)
|
||||
for (let i = 0; i < projects.length; i++) {
|
||||
let project = projects[i]
|
||||
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.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, project + ' Project', rootNodes, project)
|
||||
child.project = project
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
function newSuperalgosGlobalsDocs() {
|
||||
thisObject = {
|
||||
DOCUMENTATION_URL_PREFIX: 'https://docs.superalgos.org/',
|
||||
DOCUMENTATION_URL_DEFAULT: 'https://docs.superalgos.org/suite-about-this-documentation.html'
|
||||
}
|
||||
return thisObject
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
function newSuperalgosGlobalsZoom() {
|
||||
thisObject = {
|
||||
DOUBLE_CLICK_ZOOM_OUT_LEVEL: 0,
|
||||
DOUBLE_CLICK_ZOOM_IN_LEVEL: 6,
|
||||
DOUBLE_CLICK_ZOOM_IN_IN_LEVEL: 7,
|
||||
ZOOM_OUT_THRESHOLD_FOR_NOT_HIDDING_PANELS: 12,
|
||||
ZOOM_OUT_THRESHOLD_FOR_HIDDING_PANELS: 7,
|
||||
ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME: 3,
|
||||
ZOOM_OUT_THRESHOLD_FOR_PACKING_OBJECTS_AT_THE_BOTTOM_OR_TOP_OF_VIEWPORT: 2,
|
||||
ZOOM_OUT_THRESHOLD_FOR_PLOTTING_IN_LOW_RESOLUTION: 3,
|
||||
ZOOM_OUT_THRESHOLD_FOR_DISPLAYING_TIME_MACHINES_ICONIZED: 5,
|
||||
ZOOM_OUT_THRESHOLD_FOR_DISPLAYING_SCALES: 3
|
||||
}
|
||||
return thisObject
|
||||
}
|
||||
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 8.7 KiB |