Bug Fixes and Default Definition Concept Completely erradicated
This commit is contained in:
1 parent
835cb1c4e1
commit
90cc2a0690
5 files changed
+157
-102
No files matched your search
@@ -8,8 +8,7 @@ function newStrategizerGateway () {
|
||||
idAtStrategizer: undefined,
|
||||
strategizerData: undefined,
|
||||
container: undefined,
|
||||
loadFromStrategyzer: loadFromStrategyzer,
|
||||
saveToStrategyzer: saveToStrategyzer
|
||||
loadFromStrategyzer: loadFromStrategyzer
|
||||
}
|
||||
|
||||
let colletionItems = []
|
||||
@@ -92,77 +91,5 @@ function newStrategizerGateway () {
|
||||
} catch (err) {
|
||||
logger.write('[ERROR] loadFromStrategyzer -> err = ' + err.stack)
|
||||
}
|
||||
}
|
||||
|
||||
async function saveToStrategyzer (uiCurrentValues) {
|
||||
try {
|
||||
const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY)
|
||||
if (accessToken === null) {
|
||||
logger.write('[ERROR] saveToStrategyzer -> Can not save because the accessToken is missing.')
|
||||
return
|
||||
}
|
||||
|
||||
let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY)
|
||||
if (user === null) {
|
||||
logger.write('[ERROR] saveToStrategyzer -> Can not save because user is not logged in. ')
|
||||
return
|
||||
}
|
||||
|
||||
let tradingSystem = canvas.strategySpace.workspace.getProtocolDefinitionNode()
|
||||
if (tradingSystem === undefined || tradingSystem === null) {
|
||||
logger.write('[ERROR] saveToStrategyzer -> Can not save when tradingSystem is null or undefined.')
|
||||
return
|
||||
}
|
||||
|
||||
if (window.canvasApp.executingAt === 'Local') {
|
||||
tradingSystem.uiCurrentValues = uiCurrentValues
|
||||
callServer(JSON.stringify(tradingSystem), 'SaveDefinition', onSaved)
|
||||
function onSaved (err) {
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
return true
|
||||
} else {
|
||||
logger.write('[ERROR] saveToStrategyzer -> Can not save definition to local server. err = ' + err.messsage)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true // TODO: Here we will always show that the saving works even if it does not. We need to fix this at some point in time.
|
||||
} else {
|
||||
user = JSON.parse(user)
|
||||
|
||||
graphQLServer = await axios({
|
||||
url: window.canvasApp.graphQL.masterAppApiUrl,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
mutation strategizer_EditTradingSystem
|
||||
(
|
||||
$id: ID!, $data: strategizer_JSON!
|
||||
)
|
||||
{
|
||||
strategizer_EditTradingSystem(id: $id, tradingSystem: { data: $data })
|
||||
{
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: idAtStrategizer,
|
||||
data: tradingSystem
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
authorization: 'Bearer ' + accessToken
|
||||
}
|
||||
})
|
||||
|
||||
if (graphQLServer.data.errors) {
|
||||
logger.write('[ERROR] saveToStrategyzer -> GraphsQL Error -> graphQLServer.data.errors = ' + JSON.stringify(graphQLServer.data.errors))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
} catch (err) {
|
||||
logger.write('[ERROR] saveToStrategyzer -> err = ' + err.stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
code.id = node.id
|
||||
}
|
||||
return code
|
||||
}
|
||||
case 'Condition':
|
||||
@@ -25,6 +28,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: getProtocolNode(node.code, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
condition.id = node.id
|
||||
}
|
||||
return condition
|
||||
}
|
||||
case 'Situation': {
|
||||
@@ -39,6 +45,9 @@ function newProtocolNode () {
|
||||
let condition = getProtocolNode(node.conditions[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
situation.conditions.push(condition)
|
||||
}
|
||||
if (includeIds) {
|
||||
situation.id = node.id
|
||||
}
|
||||
return situation
|
||||
}
|
||||
case 'Formula':
|
||||
@@ -49,6 +58,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
formula.id = node.id
|
||||
}
|
||||
return formula
|
||||
}
|
||||
case 'Next Phase Event':
|
||||
@@ -63,6 +75,9 @@ function newProtocolNode () {
|
||||
let situation = getProtocolNode(node.situations[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
event.situations.push(situation)
|
||||
}
|
||||
if (includeIds) {
|
||||
event.id = node.id
|
||||
}
|
||||
return event
|
||||
}
|
||||
case 'Phase': {
|
||||
@@ -73,6 +88,9 @@ function newProtocolNode () {
|
||||
formula: getProtocolNode(node.formula, removePersonalData, parseJSONStrings, includeIds),
|
||||
nextPhaseEvent: getProtocolNode(node.nextPhaseEvent, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
phase.id = node.id
|
||||
}
|
||||
return phase
|
||||
}
|
||||
case 'Stop': {
|
||||
@@ -87,6 +105,9 @@ function newProtocolNode () {
|
||||
let phase = getProtocolNode(node.phases[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
stop.phases.push(phase)
|
||||
}
|
||||
if (includeIds) {
|
||||
stop.id = node.id
|
||||
}
|
||||
return stop
|
||||
}
|
||||
case 'Take Profit': {
|
||||
@@ -101,6 +122,9 @@ function newProtocolNode () {
|
||||
let phase = getProtocolNode(node.phases[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
takeProfit.phases.push(phase)
|
||||
}
|
||||
if (includeIds) {
|
||||
takeProfit.id = node.id
|
||||
}
|
||||
return takeProfit
|
||||
}
|
||||
case 'Take Position Event': {
|
||||
@@ -115,6 +139,9 @@ function newProtocolNode () {
|
||||
let situation = getProtocolNode(node.situations[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
event.situations.push(situation)
|
||||
}
|
||||
if (includeIds) {
|
||||
event.id = node.id
|
||||
}
|
||||
return event
|
||||
}
|
||||
case 'Trigger On Event': {
|
||||
@@ -129,6 +156,9 @@ function newProtocolNode () {
|
||||
let situation = getProtocolNode(node.situations[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
event.situations.push(situation)
|
||||
}
|
||||
if (includeIds) {
|
||||
event.id = node.id
|
||||
}
|
||||
return event
|
||||
}
|
||||
case 'Trigger Off Event': {
|
||||
@@ -143,6 +173,9 @@ function newProtocolNode () {
|
||||
let situation = getProtocolNode(node.situations[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
event.situations.push(situation)
|
||||
}
|
||||
if (includeIds) {
|
||||
event.id = node.id
|
||||
}
|
||||
return event
|
||||
}
|
||||
case 'Initial Definition': {
|
||||
@@ -155,6 +188,9 @@ function newProtocolNode () {
|
||||
positionSize: getProtocolNode(node.positionSize, removePersonalData, parseJSONStrings, includeIds),
|
||||
positionRate: getProtocolNode(node.positionRate, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Open Execution': {
|
||||
@@ -163,6 +199,9 @@ function newProtocolNode () {
|
||||
subType: node.subType,
|
||||
name: node.name
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Close Execution': {
|
||||
@@ -171,6 +210,9 @@ function newProtocolNode () {
|
||||
subType: node.subType,
|
||||
name: node.name
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Position Size': {
|
||||
@@ -180,6 +222,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
formula: getProtocolNode(node.formula, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Position Rate': {
|
||||
@@ -189,6 +234,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
formula: getProtocolNode(node.formula, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Trigger Stage': {
|
||||
@@ -200,6 +248,9 @@ function newProtocolNode () {
|
||||
triggerOff: getProtocolNode(node.triggerOff, removePersonalData, parseJSONStrings, includeIds),
|
||||
takePosition: getProtocolNode(node.takePosition, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
stage.id = node.id
|
||||
}
|
||||
return stage
|
||||
}
|
||||
case 'Open Stage': {
|
||||
@@ -210,6 +261,9 @@ function newProtocolNode () {
|
||||
initialDefinition: getProtocolNode(node.initialDefinition, removePersonalData, parseJSONStrings, includeIds),
|
||||
openExecution: getProtocolNode(node.openExecution, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
stage.id = node.id
|
||||
}
|
||||
return stage
|
||||
}
|
||||
case 'Manage Stage': {
|
||||
@@ -220,6 +274,9 @@ function newProtocolNode () {
|
||||
stopLoss: getProtocolNode(node.stopLoss, removePersonalData, parseJSONStrings, includeIds),
|
||||
takeProfit: getProtocolNode(node.takeProfit, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
stage.id = node.id
|
||||
}
|
||||
return stage
|
||||
}
|
||||
case 'Close Stage': {
|
||||
@@ -229,6 +286,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
closeExecution: getProtocolNode(node.closeExecution, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
stage.id = node.id
|
||||
}
|
||||
return stage
|
||||
}
|
||||
case 'Strategy': {
|
||||
@@ -241,6 +301,9 @@ function newProtocolNode () {
|
||||
manageStage: getProtocolNode(node.manageStage, removePersonalData, parseJSONStrings, includeIds),
|
||||
closeStage: getProtocolNode(node.closeStage, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
strategy.id = node.id
|
||||
}
|
||||
return strategy
|
||||
}
|
||||
case 'Base Asset': {
|
||||
@@ -250,6 +313,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Time Range': {
|
||||
@@ -259,6 +325,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Time Period': {
|
||||
@@ -268,6 +337,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Slippage': {
|
||||
@@ -277,6 +349,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Fee Structure': {
|
||||
@@ -286,6 +361,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Parameters': {
|
||||
@@ -299,6 +377,9 @@ function newProtocolNode () {
|
||||
slippage: getProtocolNode(node.slippage, removePersonalData, parseJSONStrings, includeIds),
|
||||
feeStructure: getProtocolNode(node.feeStructure, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Trading System': {
|
||||
@@ -314,6 +395,9 @@ function newProtocolNode () {
|
||||
let strategy = getProtocolNode(node.strategies[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
tradingSystem.strategies.push(strategy)
|
||||
}
|
||||
if (includeIds) {
|
||||
tradingSystem.id = node.id
|
||||
}
|
||||
return tradingSystem
|
||||
}
|
||||
case 'Personal Data': {
|
||||
@@ -329,6 +413,9 @@ function newProtocolNode () {
|
||||
let exchangeAccount = getProtocolNode(node.exchangeAccounts[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
personalData.exchangeAccounts.push(exchangeAccount)
|
||||
}
|
||||
if (includeIds) {
|
||||
personalData.id = node.id
|
||||
}
|
||||
return personalData
|
||||
}
|
||||
case 'Exchange Account': {
|
||||
@@ -349,6 +436,9 @@ function newProtocolNode () {
|
||||
let key = getProtocolNode(node.keys[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
exchangeAccount.keys.push(key)
|
||||
}
|
||||
if (includeIds) {
|
||||
exchangeAccount.id = node.id
|
||||
}
|
||||
return exchangeAccount
|
||||
}
|
||||
case 'Exchange Account Asset': {
|
||||
@@ -358,6 +448,9 @@ function newProtocolNode () {
|
||||
subType: node.subType,
|
||||
name: node.name
|
||||
}
|
||||
if (includeIds) {
|
||||
asset.id = node.id
|
||||
}
|
||||
return asset
|
||||
}
|
||||
case 'Exchange Account Key': {
|
||||
@@ -368,6 +461,9 @@ function newProtocolNode () {
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
if (includeIds) {
|
||||
key.id = node.id
|
||||
}
|
||||
return key
|
||||
}
|
||||
case 'Task Manager': {
|
||||
@@ -382,6 +478,9 @@ function newProtocolNode () {
|
||||
let task = getProtocolNode(node.tasks[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
taskManager.tasks.push(task)
|
||||
}
|
||||
if (includeIds) {
|
||||
taskManager.id = node.id
|
||||
}
|
||||
return taskManager
|
||||
}
|
||||
case 'Task': {
|
||||
@@ -394,6 +493,9 @@ function newProtocolNode () {
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Sensor': {
|
||||
@@ -408,6 +510,9 @@ function newProtocolNode () {
|
||||
let process = getProtocolNode(node.processes[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
bot.processes.push(process)
|
||||
}
|
||||
if (includeIds) {
|
||||
bot.id = node.id
|
||||
}
|
||||
return bot
|
||||
}
|
||||
case 'Indicator': {
|
||||
@@ -422,6 +527,9 @@ function newProtocolNode () {
|
||||
let process = getProtocolNode(node.processes[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
bot.processes.push(process)
|
||||
}
|
||||
if (includeIds) {
|
||||
bot.id = node.id
|
||||
}
|
||||
return bot
|
||||
}
|
||||
case 'Trading Engine': {
|
||||
@@ -436,6 +544,9 @@ function newProtocolNode () {
|
||||
let process = getProtocolNode(node.processes[m], removePersonalData, parseJSONStrings, includeIds)
|
||||
bot.processes.push(process)
|
||||
}
|
||||
if (includeIds) {
|
||||
bot.id = node.id
|
||||
}
|
||||
return bot
|
||||
}
|
||||
case 'Process': {
|
||||
@@ -504,6 +615,9 @@ function newProtocolNode () {
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
|
||||
@@ -520,6 +634,9 @@ function newProtocolNode () {
|
||||
object.taskManagers.push(taskManager)
|
||||
}
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Network': {
|
||||
@@ -535,6 +652,9 @@ function newProtocolNode () {
|
||||
object.networkNodes.push(networkNode)
|
||||
}
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
case 'Definition': {
|
||||
@@ -546,6 +666,9 @@ function newProtocolNode () {
|
||||
personalData: getProtocolNode(node.personalData, removePersonalData, parseJSONStrings, includeIds),
|
||||
network: getProtocolNode(node.network, removePersonalData, parseJSONStrings, includeIds)
|
||||
}
|
||||
if (includeIds) {
|
||||
object.id = node.id
|
||||
}
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,18 +22,45 @@ function newSessionFunctions () {
|
||||
|
||||
let key = node.name + '-' + node.type + '-' + node.id
|
||||
|
||||
let thisNodeDefinition = getDefinition(node)
|
||||
if (thisNodeDefinition === undefined) { return }
|
||||
|
||||
/* Raise event to run the session */
|
||||
let event = {
|
||||
session: JSON.stringify(functionLibraryProtocolNode.getProtocolNode(node, false, false, true)),
|
||||
definition: getDefinition()
|
||||
definition: JSON.stringify(functionLibraryProtocolNode.getProtocolNode(thisNodeDefinition, false, true, true)),
|
||||
uiCurrentValues: getUICurrentValues()
|
||||
}
|
||||
|
||||
systemEventHandler.raiseEvent(key, 'Run Session', event)
|
||||
|
||||
function getDefinition () {
|
||||
let definitionNode = canvas.strategySpace.workspace.getProtocolDefinitionNode()
|
||||
definitionNode.uiCurrentValues = getUICurrentValues()
|
||||
return JSON.stringify(definitionNode)
|
||||
function getDefinition (node) {
|
||||
if (node.type === 'Definition') {
|
||||
return node
|
||||
}
|
||||
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
return getDefinition(node.payload.parentNode)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function getUICurrentValues () {
|
||||
let dateAtScreenCorner = new Date(window.localStorage.getItem('Date @ Screen Corner'))
|
||||
let currentTimePeriod = JSON.parse(window.localStorage.getItem('Current Time Period'))
|
||||
|
||||
let timePeriodsMasterArray = [marketFilesPeriods, dailyFilePeriods]
|
||||
let timePeriodArray = timePeriodsMasterArray[currentTimePeriod.filePeriodIndex]
|
||||
let timePeriod = timePeriodArray[currentTimePeriod.timePeriodIndex][1]
|
||||
|
||||
let uiCurrentValues = {
|
||||
initialDatetime: dateAtScreenCorner,
|
||||
timePeriod: timePeriod,
|
||||
timestamp: (new Date()).valueOf()
|
||||
}
|
||||
|
||||
return uiCurrentValues
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ function newWorkspace () {
|
||||
nodeChildren: undefined,
|
||||
stopAllRunningTasks: stopAllRunningTasks,
|
||||
onMenuItemClick: onMenuItemClick,
|
||||
getProtocolDefinitionNode: getProtocolDefinitionNode,
|
||||
physics: physics,
|
||||
spawn: spawn,
|
||||
detachNode: detachNode,
|
||||
@@ -102,10 +101,6 @@ function newWorkspace () {
|
||||
}
|
||||
}
|
||||
|
||||
function getProtocolDefinitionNode () {
|
||||
return functionLibraryProtocolNode.getProtocolNode(thisObject.definition, false, true, true) // <- We need to do this workaround in order no to send unescaped charactars through a system event.
|
||||
}
|
||||
|
||||
function detachNode (node) {
|
||||
functionLibraryAttachDetach.detachNode(node, thisObject.workspaceNode.rootNodes)
|
||||
}
|
||||
|
||||
@@ -1,21 +1,4 @@
|
||||
|
||||
function getUICurrentValues () {
|
||||
let dateAtScreenCorner = new Date(window.localStorage.getItem('Date @ Screen Corner'))
|
||||
let currentTimePeriod = JSON.parse(window.localStorage.getItem('Current Time Period'))
|
||||
|
||||
let timePeriodsMasterArray = [marketFilesPeriods, dailyFilePeriods]
|
||||
let timePeriodArray = timePeriodsMasterArray[currentTimePeriod.filePeriodIndex]
|
||||
let timePeriod = timePeriodArray[currentTimePeriod.timePeriodIndex][1]
|
||||
|
||||
let uiCurrentValues = {
|
||||
initialDatetime: dateAtScreenCorner,
|
||||
timePeriod: timePeriod,
|
||||
timestamp: (new Date()).valueOf()
|
||||
}
|
||||
|
||||
return uiCurrentValues
|
||||
}
|
||||
|
||||
function transformThisPoint (point, container) {
|
||||
/* We make the point relative to the current frame */
|
||||
|
||||
|
||||
Reference in new issue
Block a user