Definition Added, with Personal Data and Trading System as children
This commit is contained in:
1 parent
474f7fa4f6
commit
deb5327e42
11 files changed
+283
-57
No files matched your search
@@ -8,7 +8,12 @@ function newAttachDetach () {
|
||||
|
||||
function detachNode (node, rootNodes) {
|
||||
switch (node.type) {
|
||||
case 'Definition': {
|
||||
return
|
||||
}
|
||||
case 'Personal Data': {
|
||||
node.payload.parentNode.personalData = undefined
|
||||
completeDetachment(node, rootNodes)
|
||||
return
|
||||
}
|
||||
case 'Exchange Account': {
|
||||
@@ -45,6 +50,8 @@ function newAttachDetach () {
|
||||
return
|
||||
}
|
||||
case 'Trading System': {
|
||||
node.payload.parentNode.tradingSystem = undefined
|
||||
completeDetachment(node, rootNodes)
|
||||
return
|
||||
}
|
||||
case 'Base Asset': {
|
||||
@@ -196,6 +203,13 @@ function newAttachDetach () {
|
||||
|
||||
function attachNode (node, attachToNode, rootNodes) {
|
||||
switch (node.type) {
|
||||
case 'Personal Data': {
|
||||
node.payload.parentNode = attachToNode
|
||||
node.payload.chainParent = attachToNode
|
||||
node.payload.parentNode.personalData = node
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Exchange Account': {
|
||||
node.payload.parentNode = attachToNode
|
||||
node.payload.chainParent = attachToNode
|
||||
@@ -231,6 +245,13 @@ function newAttachDetach () {
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Trading System': {
|
||||
node.payload.parentNode = attachToNode
|
||||
node.payload.chainParent = attachToNode
|
||||
node.payload.parentNode.tradingSystem = node
|
||||
completeAttachment(node, rootNodes)
|
||||
}
|
||||
break
|
||||
case 'Strategy': {
|
||||
node.payload.parentNode = attachToNode
|
||||
node.payload.chainParent = attachToNode
|
||||
|
||||
@@ -8,6 +8,9 @@ function newNodeChildren () {
|
||||
function childrenCount (parentNode, childNode) {
|
||||
switch (parentNode.type) {
|
||||
|
||||
case 'Definition': {
|
||||
return countChildrenDefinition(parentNode, childNode)
|
||||
}
|
||||
case 'Personal Data': {
|
||||
return countChildrenPersonalData(parentNode, childNode)
|
||||
}
|
||||
@@ -98,6 +101,26 @@ function newNodeChildren () {
|
||||
}
|
||||
}
|
||||
|
||||
function countChildrenDefinition (parentNode, childNode) {
|
||||
let response = {
|
||||
childrenCount: 0,
|
||||
childIndex: undefined
|
||||
}
|
||||
if (parentNode.tradingSystem !== undefined) {
|
||||
response.childrenCount++
|
||||
if (parentNode.tradingSystem.id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
}
|
||||
}
|
||||
if (parentNode.personalData !== undefined) {
|
||||
response.childrenCount++
|
||||
if (parentNode.personalData.id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
function countChildrenPersonalData (parentNode, childNode) {
|
||||
let response = {
|
||||
childrenCount: 0,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
function newNodeDeleter () {
|
||||
thisObject = {
|
||||
deleteDefinition: deleteDefinition,
|
||||
deletePersonalData: deletePersonalData,
|
||||
deleteExchangeAccount: deleteExchangeAccount,
|
||||
deleteExchangeAccountAsset: deleteExchangeAccountAsset,
|
||||
@@ -38,24 +39,28 @@ function newNodeDeleter () {
|
||||
let rootNode = node.rootNodes[0]
|
||||
switch (rootNode.type) {
|
||||
|
||||
case 'Definition': {
|
||||
deleteDefinition(rootNode, rootNodes, true)
|
||||
break
|
||||
}
|
||||
case 'Personal Data': {
|
||||
deletePersonalData(rootNode, rootNodes, true)
|
||||
deletePersonalData(rootNode, rootNodes)
|
||||
break
|
||||
}
|
||||
case 'Exchange Account': {
|
||||
deleteExchangeAccount(rootNode, rootNodes, true)
|
||||
deleteExchangeAccount(rootNode, rootNodes)
|
||||
break
|
||||
}
|
||||
case 'Exchange Account Asset': {
|
||||
deleteExchangeAccountAsset(rootNode, rootNodes, true)
|
||||
deleteExchangeAccountAsset(rootNode, rootNodes)
|
||||
break
|
||||
}
|
||||
case 'Exchange Account Key': {
|
||||
deleteExchangeAccountKey(rootNode, rootNodes, true)
|
||||
deleteExchangeAccountKey(rootNode, rootNodes)
|
||||
break
|
||||
}
|
||||
case 'Trading System': {
|
||||
deleteTradingSystem(rootNode, rootNodes, true)
|
||||
deleteTradingSystem(rootNode, rootNodes)
|
||||
break
|
||||
}
|
||||
case 'Parameters': {
|
||||
@@ -146,9 +151,45 @@ function newNodeDeleter () {
|
||||
cleanNode(node)
|
||||
}
|
||||
|
||||
function deleteDefinition (node, rootNodes, forced) {
|
||||
let payload = node.payload
|
||||
|
||||
if (forced !== true) {
|
||||
/* Can not delete if it is the last one */
|
||||
let counter = 0
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === node.type) {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
if (counter <= 1) { return }
|
||||
}
|
||||
|
||||
if (node.payload.uiObject.isRunning === true) {
|
||||
node.payload.uiObject.setNotRunningStatus()
|
||||
}
|
||||
|
||||
if (node.tradingSystem !== undefined) {
|
||||
deleteTradingSystem(node.tradingSystem, rootNodes)
|
||||
}
|
||||
if (node.personalData !== undefined) {
|
||||
deletePersonalData(node.personalData, rootNodes)
|
||||
}
|
||||
completeDeletion(node, rootNodes)
|
||||
destroyPart(node)
|
||||
cleanNode(node)
|
||||
}
|
||||
|
||||
function deletePersonalData (node, rootNodes) {
|
||||
let payload = node.payload
|
||||
|
||||
if (payload.parentNode !== undefined) {
|
||||
payload.parentNode.personalData = undefined
|
||||
}
|
||||
|
||||
while (node.exchangeAccounts.length > 0) {
|
||||
deleteStrategy(node.exchangeAccounts[0], rootNodes)
|
||||
deleteExchangeAccount(node.exchangeAccounts[0], rootNodes)
|
||||
}
|
||||
|
||||
completeDeletion(node, rootNodes)
|
||||
@@ -209,21 +250,11 @@ function newNodeDeleter () {
|
||||
cleanNode(node)
|
||||
}
|
||||
|
||||
function deleteTradingSystem (node, rootNodes, forced) {
|
||||
if (forced !== true) {
|
||||
/* Can not delete if it is the last one */
|
||||
let counter = 0
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
let rootNode = rootNodes[i]
|
||||
if (rootNode.type === node.type) {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
if (counter <= 1) { return }
|
||||
}
|
||||
function deleteTradingSystem (node, rootNodes) {
|
||||
let payload = node.payload
|
||||
|
||||
if (node.payload.uiObject.isRunning === true) {
|
||||
node.payload.uiObject.setNotRunningStatus()
|
||||
if (payload.parentNode !== undefined) {
|
||||
payload.parentNode.tradingSystem = undefined
|
||||
}
|
||||
|
||||
while (node.strategies.length > 0) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
function newPartsFromNodes () {
|
||||
thisObject = {
|
||||
createPartFromNode: createPartFromNode,
|
||||
addTradingSystem: addTradingSystem,
|
||||
addPersonalData: addPersonalData,
|
||||
addExchangeAccount: addExchangeAccount,
|
||||
addExchangeAccountAsset: addExchangeAccountAsset,
|
||||
addExchangeAccountKey: addExchangeAccountKey,
|
||||
@@ -299,6 +301,34 @@ function newPartsFromNodes () {
|
||||
createPart('Exchange Account Key', node.name, node, parentNode, chainParent, 'Exchange Account Key')
|
||||
return
|
||||
}
|
||||
case 'Definition': {
|
||||
createPart('Definition', node.name, node, parentNode, chainParent, 'Definition')
|
||||
if (node.tradingSystem !== undefined) {
|
||||
createPartFromNode(node.tradingSystem, node, node)
|
||||
}
|
||||
if (node.personalData !== undefined) {
|
||||
createPartFromNode(node.personalData, node, node)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addTradingSystem (node) {
|
||||
if (node.tradingSystem === undefined) {
|
||||
node.tradingSystem = {
|
||||
strategies: []
|
||||
}
|
||||
createPart('Trading System', '', node.tradingSystem, node, node)
|
||||
}
|
||||
}
|
||||
|
||||
function addPersonalData (node) {
|
||||
if (node.personalData === undefined) {
|
||||
node.personalData = {
|
||||
exchangeAccounts: []
|
||||
}
|
||||
createPart('Personal Data', '', node.personalData, node, node)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -325,6 +325,16 @@ function newProtocolNode () {
|
||||
}
|
||||
return key
|
||||
}
|
||||
case 'Definition': {
|
||||
let object = {
|
||||
type: node.type,
|
||||
subType: node.subType,
|
||||
name: node.name,
|
||||
tradingSystem: getProtocolNode(node.tradingSystem),
|
||||
personalData: getProtocolNode(node.personalData)
|
||||
}
|
||||
return object
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,6 +384,18 @@ function newStringifyNode () {
|
||||
}
|
||||
return key
|
||||
}
|
||||
case 'Definition': {
|
||||
let object = {
|
||||
id: node.id,
|
||||
type: node.type,
|
||||
subType: node.subType,
|
||||
name: node.name,
|
||||
tradingSystem: prepareForStringify(node.tradingSystem),
|
||||
personalData: prepareForStringify(node.personalData),
|
||||
savedPayload: getSavedPayload(node)
|
||||
}
|
||||
return object
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user