ADD|MODIFY Many Functionalities to portfolio-management to get us to step 4

This commit is contained in:
Philip Love committed 2021-11-28 23:29:48 -05:00
1 parent 67fccaae2d
commit 66f422bf68
33 files changed
+30600 -6909

No files matched your search

@@ -0,0 +1,45 @@
/* PMCommunicationModule - Trading Bot's Version.
* Fascilitates communications between the Portfolio Manager and its managed sessions.
* Session Key naming convention: name + type + id
*/
exports.newPMCommunicationModule_Trading = function (callerId) {
const MODULE_NAME = 'PM Communication Module - Trading';
moduleObj = {
beginListening: beginListening,
getQuoteAssetBalance: getQuoteAssetBalance
}
const SESSION_ID = callerId;
return moduleObj;
/* Listeners Section: */
function beginListening() {
TS.projects.foundations.globals.taskConstants.EVENT_SERVER_CLIENT_MODULE_OBJECT.listenToEvent(
SESSION_ID,
'Quote Asset Balance Reply',
undefined,
SESSION_ID,
undefined,
gotQuoteAssetBalance)
}
/* eventsCallBack Section: */
function getQuoteAssetBalance() {
TS.projects.foundations.globals.taskConstants.EVENT_SERVER_CLIENT_MODULE_OBJECT.raiseEvent(
SESSION_ID,
'Quote Asset Balance',
undefined
)
}
function gotQuoteAssetBalance() {
let ret = arguments[0].event;
console.log("Quote Asset Balance=>" + ret);
}
}
@@ -47,6 +47,9 @@
TS.projects.foundations.globals.taskVariables.SESSION_MAP.set(
TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_KEY,
TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_KEY)
/* We will store the PMCommunicationModule Object: */
TS.projects.foundations.globals.processVariables.PM_COMMUNICATION_MODULE = TS.projects.algorithmicTrading.botModules.PMCommunicationModule_Trading.newPMCommunicationModule_Trading(VARIABLES_BY_PROCESS_INDEX.SESSION_KEY);
/* Listen to event to start or stop the session. */
TS.projects.foundations.globals.taskConstants.EVENT_SERVER_CLIENT_MODULE_OBJECT.listenToEvent(
@@ -512,6 +515,7 @@
}
function startBackTesting(message) {
return true
}
@@ -580,6 +584,9 @@
}
function startLiveTrading() {
// Testing:
TS.projects.foundations.globals.processVariables.PM_COMMUNICATION_MODULE.beginListening();
TS.projects.foundations.globals.processVariables.PM_COMMUNICATION_MODULE.getQuoteAssetBalance();
return checkKey()
}
@@ -1,13 +1,13 @@
function newAlgorithmicTradingFunctionLibraryTradingSessionFunctions() {
let thisObject = {
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
synchronizeSessionWithBackEnd: synchronizeSessionWithBackEnd,
runSession: runSession,
stopSession: stopSession
}
return thisObject
function syncronizeSessionWithBackEnd(node) {
function synchronizeSessionWithBackEnd(node) {
let validationsResult = validations(node)
if (validationsResult === undefined) {
/* If something fails at validations we just quit. */
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

File diff suppressed because it is too large. Load diff
@@ -18,7 +18,7 @@
"addLeftIcons": true,
"level": 4,
"attachingRules": {
"compatibleTypes": "->Task->"
"compatibleTypes": "->Task->Portfolio Task->"
},
"referencingRules": {
"compatibleTypes": "->Exchange Account Key->"
@@ -43,7 +43,7 @@
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->Task->"
"compatibleTypes": "->Portfolio Task->"
},
"childrenNodesProperties": [
{
@@ -23,7 +23,7 @@
"addLeftIcons": true,
"level": 3,
"attachingRules": {
"compatibleTypes": "->Task->"
"compatibleTypes": "->Portfolio Task->"
},
"childrenNodesProperties": [
{
@@ -24,7 +24,7 @@
{
"action": "Add UI Object",
"label": "Add Task Manager",
"relatedUiObject": "Task Manager",
"relatedUiObject": "Portfolio Task Manager",
"actionFunction": "payload.executeAction",
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
@@ -35,7 +35,7 @@
"askConfirmation": true,
"confirmationLabel": "Confirm to Proceed",
"workDoneLabel": "Done",
"relatedUiObject": "Task",
"relatedUiObject": "Portfolio Task",
"actionFunction": "payload.executeAction",
"relatedUiObjectProject": "Foundations"
},
@@ -66,9 +66,9 @@
"propertyNameAtParent": "portfolioMineTasks",
"childrenNodesProperties": [
{
"name": "taskManagers",
"name": "portfolioTaskManagers",
"type": "array",
"childType": "Task Manager",
"childType": "Portfolio Task Manager",
"monitorChildrenRunning": true
}
]
@@ -0,0 +1,58 @@
{
"type": "Portfolio Task Manager",
"menuItems": [
{
"action": "Run All Tasks",
"label": "Run All Tasks",
"askConfirmation": true,
"confirmationLabel": "Confirm to Run",
"workDoneLabel": "Run Request Sent",
"iconPathOn": "run",
"iconPathOff": "run",
"actionFunction": "payload.executeAction"
},
{
"action": "Stop All Tasks",
"label": "Stop All Tasks",
"askConfirmation": true,
"confirmationLabel": "Confirm to Stop",
"workDoneLabel": "Stop Request Sent",
"iconPathOn": "stop",
"iconPathOff": "stop",
"actionFunction": "payload.executeAction"
},
{
"action": "Add UI Object",
"label": "Add Portfolio Task",
"relatedUiObject": "Portfolio Task",
"actionFunction": "payload.executeAction",
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Delete UI Object",
"actionProject": "Visual-Scripting",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "Portfolio Mine Tasks->"
},
"childrenNodesProperties": [
{
"name": "portfolioTasks",
"type": "array",
"childType": "Portfolio Task",
"autoAdd": false,
"monitorChildrenRunning": true
}
],
"propertyNameAtParent": "portfolioTaskManagers"
}
@@ -0,0 +1,95 @@
{
"type": "Portfolio Task",
"menuItems": [
{
"action": "Run Task",
"label": "Run",
"workingLabel": "Stop",
"workDoneLabel": "Task Running",
"workFailedLabel": "Task Cannot be Run",
"secondaryAction": "Stop Task",
"secondaryLabel": "Stop",
"secondaryWorkingLabel": "Stopping...",
"secondaryWorkDoneLabel": "Task Stopped",
"secondaryWorkFailedLabel": "Task Cannot be Stopped",
"secondaryIcon": "stop",
"iconPathOn": "run",
"iconPathOff": "run",
"actionFunction": "payload.executeAction"
},
{
"action": "Debug Task",
"label": "Debug",
"workingLabel": "Debugging",
"workDoneLabel": "Debug Request Sent",
"workFailedLabel": "Task Cannot be Debugged",
"iconPathOn": "status-dependency",
"iconPathOff": "status-dependency",
"actionFunction": "payload.executeAction"
},
{
"action": "Add UI Object",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "bot",
"label": "Add Portfolio Bot Instance",
"relatedUiObject": "Portfolio Bot Instance",
"actionFunction": "payload.executeAction",
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Add UI Object",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "keyReference",
"label": "Add Key Reference",
"relatedUiObject": "Key Reference",
"actionFunction": "payload.executeAction",
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Add UI Object",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "managedTasks",
"label": "Add Managed Tasks",
"relatedUiObject": "Managed Tasks",
"actionFunction": "payload.executeAction",
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Delete UI Object",
"actionProject": "Visual-Scripting",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"isTitleAllwaysVisible": true,
"addLeftIcons": true,
"level": 0,
"attachingRules": {
"compatibleTypes": "->Portfolio Task Manager->"
},
"childrenNodesProperties": [
{
"name": "bot",
"type": "node",
"childType": "Portfolio Bot Instance"
},
{
"name": "keyReference",
"type": "node",
"childType": "Key Reference"
},
{
"name": "managedTasks",
"type": "node",
"childType": "Managed Tasks"
}
],
"propertyNameAtParent": "portfolioTasks"
}
@@ -67,16 +67,6 @@
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Add UI Object",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "bot",
"label": "Add Portfolio Bot Instance",
"relatedUiObject": "Portfolio Bot Instance",
"actionFunction": "payload.executeAction",
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Add UI Object",
"disableIfPropertyIsDefined": true,
@@ -97,16 +87,6 @@
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Add UI Object",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "managedTasks",
"label": "Add Managed Tasks",
"relatedUiObject": "Managed Tasks",
"actionFunction": "payload.executeAction",
"actionProject": "Visual-Scripting",
"relatedUiObjectProject": "Foundations"
},
{
"action": "Delete UI Object",
"actionProject": "Visual-Scripting",
@@ -130,11 +110,6 @@
"type": "node",
"childType": "Trading Bot Instance"
},
{
"name": "bot",
"type": "node",
"childType": "Portfolio Bot Instance"
},
{
"name": "bot",
"type": "node",
@@ -159,11 +134,6 @@
"name": "keyReference",
"type": "node",
"childType": "Key Reference"
},
{
"name": "managedTasks",
"type": "node",
"childType": "Managed Tasks"
}
],
"propertyNameAtParent": "tasks"
@@ -35,6 +35,11 @@
"type": "node",
"childType": "Trading Session Reference"
},
{
"name": "portfolioSessionReferences",
"type": "node",
"childType": "Portfolio Session Reference"
},
{
"name": "timeMachines",
"type": "node",
@@ -20,7 +20,7 @@
"compatibleTypes": "->Template Script->"
},
"referencingRules": {
"compatibleTypes": "->Dashboard->Data Mines Data->Trading Mines Data->Data Tasks->Testing Trading Tasks->Production Trading Tasks->"
"compatibleTypes": "->Dashboard->Data Mines Data->Trading Mines Data->Data Tasks->Testing Trading Tasks->Production Trading Tasks->Portfolio Mines Data->Production Portfolio Tasks->"
},
"childrenNodesProperties": []
}
@@ -3,7 +3,7 @@
"pageNumber": "4",
"type": "Plugins-Docs",
"definition": {
"text": "The branch Plugins-Docs is used by contributors of Plugins, documentations or tutorials. This branch in syncronized with Develop and Master everytime a new version is released, and it's purpose is to allow the flow of docs pages, plugins and tutorials into the master branch at a higher rate than changes at the codebase done at the Develop branch. This means that the Master branch might have many updates in between releases.",
"text": "The branch Plugins-Docs is used by contributors of Plugins, documentations or tutorials. This branch in synchronized with Develop and Master everytime a new version is released, and it's purpose is to allow the flow of docs pages, plugins and tutorials into the master branch at a higher rate than changes at the codebase done at the Develop branch. This means that the Master branch might have many updates in between releases.",
"updated": 1622467789596,
"translations": [
{
@@ -3,7 +3,7 @@
"pageNumber": "18",
"type": "Problems With Computer Time",
"definition": {
"text": "Some exchanges force the computer that is running your bot to be highly synchronized with their servers, and to achieve that you need that machine's time to keep itself syncronized with an Internet Time Server.",
"text": "Some exchanges force the computer that is running your bot to be highly synchronized with their servers, and to achieve that you need that machine's time to keep itself synchronized with an Internet Time Server.",
"updated": 1622140103759
},
"paragraphs": [
@@ -7,7 +7,8 @@ exports.newFoundationsGlobalsProcessVariables = function () {
let thisObject = {
ENDED_PROCESSES_COUNTER: 0,
TOTAL_PROCESS_INSTANCES_CREATED: 0,
VARIABLES_BY_PROCESS_INDEX_MAP: new Map()
VARIABLES_BY_PROCESS_INDEX_MAP: new Map(),
PM_COMMUNICATION_MODULE: undefined
}
/*
@@ -8,8 +8,10 @@ exports.newFoundationsGlobalsTaskConstants = function () {
NETWORK_NODE: undefined,
PROJECT_DEFINITION_NODE: undefined,
PROJECTS_SCHEMA: undefined,
EVENT_SERVER_CLIENT_MODULE_OBJECT: undefined, // This is an instance of the Event Server Client pointing to the localhost server
TASK_HEARTBEAT_INTERVAL_HANDLER: undefined
EVENT_SERVER_CLIENT_MODULE_OBJECT: undefined, // This is an instance of the Event Server Client pointing to the localhost server
TASK_HEARTBEAT_INTERVAL_HANDLER: undefined,
MANAGED_TASKS: undefined,
MANAGED_SESSIONS_MAP: new Map() // Naming convention => Key: name-type-id, Value:PMCommunicationModule
}
return thisObject
@@ -53,6 +53,18 @@ function newFoundationsActionSwitch() {
UI.projects.foundations.functionLibraries.taskFunctions.stopAllTaskManagers(action.node)
}
break
case 'Run All Portfolio Task Managers':
{
UI.projects.foundations.functionLibraries.taskFunctions.runAllTaskManagers(action.node)
}
break
case 'Stop All Portfolio Task Managers':
{
UI.projects.foundations.functionLibraries.taskFunctions.stopAllTaskManagers(action.node)
}
break
case 'Run All Managed Tasks':
{ /* Portfolio Task References */
UI.projects.foundations.functionLibraries.taskFunctions.runAllManagedTasks(action.node);
@@ -1,6 +1,6 @@
function newFoundationsFunctionLibraryTaskFunctions() {
let thisObject = {
syncronizeTaskWithBackEnd: syncronizeTaskWithBackEnd,
synchronizeTaskWithBackEnd: synchronizeTaskWithBackEnd,
runTask: runTask,
stopTask: stopTask,
@@ -71,7 +71,7 @@ function newFoundationsFunctionLibraryTaskFunctions() {
return thisObject
function syncronizeTaskWithBackEnd(node) {
function synchronizeTaskWithBackEnd(node) {
let lanNetworkNode = validations(node)
if (lanNetworkNode === undefined) {
/* Nodes that do not belong to a network can not get ready. */
@@ -123,11 +123,6 @@ function newFoundationsFunctionLibraryTaskFunctions() {
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(lanNetworkNode.id)
// Check for Managed-Tasks and run them first prior to bots:
if (node.managedTasks !== undefined) {
runAllManagedTasks(node.managedTasks);
}
for (let i = 0; i < node.bot.processes.length; i++) {
let process = node.bot.processes[i]
process.payload.uiObject.run(eventsServerClient)
@@ -136,28 +131,24 @@ function newFoundationsFunctionLibraryTaskFunctions() {
}
}
let taskLightingPath = '->Task->' +
let taskLightingPath = '->Portfolio Task->Task->' +
'Sensor Bot Instance->' +
'API Data Fetcher Bot Instance->' +
'Indicator Bot Instance->' +
'Trading Bot Instance->' +
'Portfolio Bot Instance->' +
'Learning Bot Instance->' +
'Trading Bot Instance->Portfolio Bot Instance->Learning Bot Instance->' +
'Sensor Process Instance->Time Frames Filter->API Data Fetcher Process Instance->Indicator Process Instance->Trading Process Instance->Portfolio Process Instance->Learning Process Instance->' +
'Social Trading Bot Reference->Social Trading Bot->Signing Account->' +
'Execution Started Event->' +
'Key Reference->Exchange Account Key->' +
'Managed Tasks->' +
'Task Manager->' +
'Task Manager->Portfolio Task Manager->' +
'Data Mine Tasks->Trading Mine Tasks->Portfolio Mine Tasks->Learning Mine Tasks->' +
'Market Data Tasks->Market Trading Tasks->Market Portfolio Tasks->Market Learning Tasks->' +
'Exchange Data Tasks->Exchange Trading Tasks->Exchange Portfolio Tasks->Exchange Learning Tasks->' +
'Market->Exchange Markets->Crypto Exchange->' +
'Market Base Asset->Market Quoted Asset->Asset->' +
'Project Data Tasks->Project Trading Tasks->Project Portfolio Tasks->Project Learning Tasks->Project Definition->' +
'Managed Sessions->' +
'Backtesting Session->Live Trading Session->Paper Trading Session->Forward Testing Session->Live Portfolio Session->' +
'Back Learning Session->Live Learning Session->' +
'Back Learning Session->Live Learning Session->Managed Sessions->Session Reference->' +
'Process Definition->' +
'Process Output->' +
'Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->' +
@@ -211,16 +202,29 @@ function newFoundationsFunctionLibraryTaskFunctions() {
'Exchange Data Tasks->Exchange Trading Tasks->Exchange Portfolio Tasks->Exchange Learning Tasks->Crypto Exchange->' +
'Market Data Tasks->Market Trading Tasks->Market Portfolio Tasks->Market Learning Tasks->Market->' +
'Data Mine Tasks->Trading Mine Tasks->Portfolio Mine Tasks->Learning Mine Tasks->' +
'Task Manager->Task->' +
'Task Manager->Portfolio Task Manager->Portfolio Task->Managed Tasks->Task Reference->Task->' +
'Indicator Bot Instance->Sensor Bot Instance->API Data Fetcher Bot Instance->Trading Bot Instance->Portfolio Bot Instance->Learning Bot Instance->' +
'Indicator Process Instance->Sensor Process Instance->API Data Fetcher Process Instance->Trading Process Instance->Portfolio Process Instance->Learning Process Instance->' +
'Paper Trading Session->Forward Testing Session->Backtesting Session->Live Trading Session->Live Portfolio Session->Back Learning Session->Live Learning Session->' +
'Paper Trading Session->Forward Testing Session->Backtesting Session->Live Trading Session->Live Portfolio Session->Back Learning Session->Live Learning Session->Managed Sessions->' +
'API Map Reference->' +
'Market->' +
'Process Definition->'
let networkDefinition = UI.projects.visualScripting.functionLibraries.protocolNode.getProtocolNode(lanNetworkNode.payload.parentNode, false, true, true, false, false, networkLightingPath)
let managedTasksLightingPath = '->Portfolio Task->Managed Tasks->Portfolio Bot Instance->' +
'Task Reference->Task->Sensor Bot Instance->API Data Fetcher Bot->Indicator Bot Instance->Trading Bot Instance->Learning Bot Instance->' +
'Sensor Process Instance->Time Frames Filter->API Data Fetcher Process Instance->Indicator Process Instance->Trading Process Instance->Learning Process Instance->' +
'Execution Started Event->Key Reference->Exchange Account Key->' +
'Task Manager->Portfolio Task Manager->' +
'Data Mine Tasks->Trading Mine Tasks->Learning Mine Tasks->Portfolio Mine Tasks->' +
'Market Trading Tasks->Market Data Tasks->Market Learning Tasks->Market Portfolio Tasks->' +
'Market->Exchange Markets->Crypto Exchange->Crypto Exchanges->exchange Markets->Market->' +
'Portfolio Process Instance->Live Portfolio Session->Portfolio Parameters->Portfolio Engine Reference->Portfolio System Reference->Managed Sessions->Session Reference->Live Trading Session->Backtesting Session->Forward Testing Session->Live Portfolio Session->Back Learning Session->Paper Trading Session->Trading Parameters->Trading Engine Reference->'
let managedTasksDefinition =
UI.projects.visualScripting.functionLibraries.protocolNode.getProtocolNode(node, false, true, true, false, false, managedTasksLightingPath);
/*
We will also send all the project schemas we have to the Task Server.
*/
@@ -233,12 +237,14 @@ function newFoundationsFunctionLibraryTaskFunctions() {
}
projectSchemas.push(project)
}
let event = {
projectSchemas: JSON.stringify(projectSchemas),
taskId: node.id,
taskName: node.name,
taskDefinition: JSON.stringify(taskDefinition),
networkDefinition: JSON.stringify(networkDefinition)
networkDefinition: JSON.stringify(networkDefinition),
managedTasksDefinition: JSON.stringify(managedTasksDefinition)
}
if (isDebugging === true) {
@@ -249,6 +255,10 @@ function newFoundationsFunctionLibraryTaskFunctions() {
node.payload.uiObject.run(eventsServerClient, callBackFunction)
eventsServerClient.raiseEvent('Task Manager', 'Run Task', event)
if (node.managedTasks !== undefined) {
runAllManagedTasks(node.managedTasks);
}
}
function stopTask(node, callBackFunction) {
@@ -358,17 +368,19 @@ function newFoundationsFunctionLibraryTaskFunctions() {
}
function runAllTasks(taskManager) {
for (let i = 0; i < taskManager.tasks.length; i++) {
let node = taskManager.tasks[i]
let menu = node.payload.uiObject.menu
let tasks = (taskManager.type !== 'Portfolio Task Manager') ? taskManager.tasks : taskManager.portfolioTasks;
for (let i = 0; i < tasks.length; i++) {
let node = 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 tasks = (taskManager.type !== 'Portfolio Task Manager') ? taskManager.tasks : taskManager.portfolioTasks;
for (let i = 0; i < tasks.length; i++) {
let node = tasks[i];
let menu = node.payload.uiObject.menu
menu.internalClick('Stop Task')
@@ -376,9 +388,10 @@ function newFoundationsFunctionLibraryTaskFunctions() {
}
function runAllTaskManagers(parent) {
for (let i = 0; i < parent.taskManagers.length; i++) {
let node = parent.taskManagers[i]
let menu = node.payload.uiObject.menu
let manager = (parent.type !== 'Portfolio Mine Tasks') ? parent.taskManagers : parent.portfolioTaskManagers;
for (let i = 0; i < manager.length; i++) {
let node = manager[i];
let menu = node.payload.uiObject.menu;
menu.internalClick('Run All Tasks')
menu.internalClick('Run All Tasks')
@@ -386,9 +399,10 @@ function newFoundationsFunctionLibraryTaskFunctions() {
}
function stopAllTaskManagers(parent) {
for (let i = 0; i < parent.taskManagers.length; i++) {
let node = parent.taskManagers[i]
let menu = node.payload.uiObject.menu
let manager = (parent.type !== 'Portfolio Mine Tasks') ? parent.taskManagers : parent.portfolioTaskManagers;
for (let i = 0; i < manager.length; i++) {
let node = manager[i];
let menu = node.payload.uiObject.menu;
menu.internalClick('Stop All Tasks')
menu.internalClick('Stop All Tasks')
@@ -715,7 +729,7 @@ function newFoundationsFunctionLibraryTaskFunctions() {
}
}
/* run|stop ManagedTasks(): Portfolio Management managed task runners: */
/* run|stop ManagedTasks(): Portfolio Management managed tasks runners: */
function runAllManagedTasks(managedTasks) {
for (let i = 0; i < managedTasks.taskReference.length; i++) {
managedTasks.taskReference[i].payload.referenceParent.payload.uiObject.menu.internalClick('Run Task');
@@ -870,7 +884,9 @@ function newFoundationsFunctionLibraryTaskFunctions() {
if (node.payload === undefined) { return }
if (node.payload.referenceParent === undefined) { return }
let taskManager = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Task Manager')
let taskManager = (node.type !== 'Portfolio Mine Tasks') ?
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Task Manager') :
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Portfolio Task Manager');
taskManager.name = node.payload.referenceParent.name
taskManager.payload.floatingObject.collapseToggle()
@@ -1013,7 +1029,9 @@ function newFoundationsFunctionLibraryTaskFunctions() {
}
function addTask(taskManager) {
let task = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(taskManager, 'Task')
let task = (taskManager.type !== 'Portfolio Task Manager') ?
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(taskManager, 'Task') :
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(taskManager, 'Portfolio Task');
if (systemNode !== undefined) {
task.name = systemNode.name
@@ -1,13 +1,13 @@
function newMachineLearningFunctionLibraryLearningSessionFunctions() {
let thisObject = {
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
synchronizeSessionWithBackEnd: synchronizeSessionWithBackEnd,
runSession: runSession,
stopSession: stopSession
}
return thisObject
function syncronizeSessionWithBackEnd(node) {
function synchronizeSessionWithBackEnd(node) {
let validationsResult = validations(node)
if (validationsResult === undefined) {
/* If something fails at validations we just quit. */
@@ -1,6 +1,6 @@
exports.newPortfolioManagementBotModulesOrdersCalculations = function (processIndex) {
/*
When we are live portfolio, we need to syncronize with the exchange.
When we are live portfolio, we need to synchronize with the exchange.
*/
let thisObject = {
@@ -48,7 +48,7 @@ exports.newPortfolioManagementBotModulesOrdersCalculations = function (processIn
If it happens that the size accepted (Actual Size) is different than the
size requested (Size), we need to make several adjustments so that the
accounting syncronizes with reality.
accounting synchronizes with reality.
*/
/* This calculation needs to happen only once, the first time the order is checked. */
@@ -146,7 +146,7 @@ exports.newPortfolioManagementBotModulesOrdersCalculations = function (processIn
function recalculateActualSize() {
/*
Now we know the Actual Rate at which the order was filled. Since the actual rate
is not the same as the Rate we defined for the order, we need to syncronize
is not the same as the Rate we defined for the order, we need to synchronize
the Actual Order Size for Quoted Asset since it was calculated with the Order Size that we
now know it is not the one really used at the exchange. We will recalculate the
Actual Size in Quoted Asset and not in Base Asset, since the Actual Size in Base Asset
@@ -1148,7 +1148,7 @@ exports.newPortfolioManagementBotModulesPortfolioOrders = function (processIndex
/*
Close this Order. Note that we are not closing the order until we have the exchange
response with the order details that we can use to syncronize with our accoounting.
response with the order details that we can use to synchronize with our accoounting.
Otherwise if the connection to the exchange fails, we would have a closed order not
accounted in any way.
*/
@@ -1024,7 +1024,7 @@ exports.newPortfolioManagementBotModulesPortfolioStages = function (processIndex
The Target Size is defined by the end user either in Base Asset or Quoted Asset.
Whatever the user chooses defines also the way we check if the Target was met.
Why? Because the counterparty target is estimated with the Target Rate and it
is not syncronized with the reality we later learn when the exchange tell us the
is not synchronized with the reality we later learn when the exchange tell us the
actual rate each of the orders where executed at.
For the same reason that the user does not know exactly which is the rate the orders
@@ -0,0 +1,40 @@
/* PMCommunicationModule - Portfolio-Manager's Version.
* Fascilitates communications between the Portfolio Manager and its managed sessions.
* Session Key naming convention: name + type + id
*/
exports.newPMCommunicationModule_Portfolio = function (callerId) {
const MODULE_NAME = 'PM Communication Module - Portfolio';
moduleObj = {
beginListening: beginListening
}
const SESSION_ID = callerId;
return moduleObj;
/* Listeners Section: */
function beginListening() {
TS.projects.foundations.globals.taskConstants.EVENT_SERVER_CLIENT_MODULE_OBJECT.listenToEvent(
SESSION_ID,
'Quote Asset Balance',
undefined,
SESSION_ID,
undefined,
getQuoteAssetBalance)
}
/* eventsCallBack Section: */
function getQuoteAssetBalance() {
let quoteBal = 100.47;
TS.projects.foundations.globals.taskConstants.EVENT_SERVER_CLIENT_MODULE_OBJECT.raiseEvent(
SESSION_ID,
'Quote Asset Balance Reply',
quoteBal
)
}
}
@@ -40,6 +40,7 @@
} else {
VARIABLES_BY_PROCESS_INDEX.SESSION_FOLDER_NAME = TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName
}
/*
We will store all session keys on a map so as to be able to send an event to all
of them when the task stops.
@@ -117,12 +118,12 @@
TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false
TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = true
setUpSessionFolderName()
setUpSessionFolderName();
/* We validate all parameters received and complete some that might be missing if needed. */
if (checkParemeters() === false) { return }
TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SOCIAL_BOTS_MODULE.initialize()
TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SOCIAL_BOTS_MODULE.initialize();
let allGood
switch (TS.projects.foundations.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.type) {
@@ -580,6 +581,9 @@
}
function startLivePortfolio() {
for (let key of TS.projects.foundations.globals.taskConstants.MANAGED_SESSIONS_MAP.keys()) {
TS.projects.foundations.globals.taskConstants.MANAGED_SESSIONS_MAP.get(key).beginListening();
}
return checkKey()
}
@@ -1,6 +1,6 @@
function newPortfolioManagementFunctionLibraryPortfolioSessionFunctions() {
let thisObject = {
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
synchronizeSessionWithBackEnd: synchronizeSessionWithBackEnd,
runSession: runSession,
stopSession: stopSession,
runManagedSessions: runManagedSessions,
@@ -9,7 +9,7 @@ function newPortfolioManagementFunctionLibraryPortfolioSessionFunctions() {
return thisObject
function syncronizeSessionWithBackEnd(node) {
function synchronizeSessionWithBackEnd(node) {
let validationsResult = validations(node)
if (validationsResult === undefined) {
/* If something fails at validations we just quit. */
@@ -65,11 +65,6 @@ function newPortfolioManagementFunctionLibraryPortfolioSessionFunctions() {
return
}
// Check for Managed-Sessions and run them:
if (node.managedSessions !== undefined) {
runManagedSessions(node.managedSessions);
}
let eventsServerClient = UI.projects.foundations.spaces.designSpace.workspace.eventsServerClients.get(lanNetworkNode.id)
let key = node.name + '-' + node.type + '-' + node.id
@@ -207,6 +202,11 @@ function newPortfolioManagementFunctionLibraryPortfolioSessionFunctions() {
if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) {
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
} else {
// Check for Managed-Sessions and run them:
if (node.managedSessions !== undefined) {
runManagedSessions(node.managedSessions);
}
}
}
@@ -249,7 +249,7 @@ function newPortfolioManagementFunctionLibraryPortfolioSessionFunctions() {
for (let i = 0; i < managedSessions.sessionReference.length; i++) {
let refParent = managedSessions.sessionReference[i].payload.referenceParent;
let sessionType = refParent.type;
if (sessionType === 'Live Trading Session' ||
sessionType === 'Backtesting Session' ||
sessionType === 'Forward Testing Session' ||
+15 -1
View File
@@ -28,6 +28,13 @@
"fileName": "TradingSession.js",
"folderName": "Trading-Bot"
},
{
"name": "PM Communication Module - Trading",
"propertyName": "PMCommunicationModule_Trading",
"functionName": "newPMCommunicationModule_Trading",
"fileName": "PMCommunicationModule_Trading.js",
"folderName": "Trading-Bot"
},
{
"name": "Trading Process",
"propertyName": "tradingProcess",
@@ -165,6 +172,13 @@
},
"TS": {
"botModules": [
{
"name": "PM Communication Module - Portfolio",
"propertyName": "PMCommunicationModule_Portfolio",
"functionName": "newPMCommunicationModule_Portfolio",
"fileName": "PMCommunicationModule_Portfolio.js",
"folderName": "Portfolio-Bot"
},
{
"name": "Single Market Portfolio Bot",
"propertyName": "singleMarketPortfolioBot",
@@ -1697,7 +1711,7 @@
"propertyName": "signal",
"functionName": "newSocialTradingModulesSignal",
"fileName": "Signal.js"
},
},
{
"name": "Client Interface",
"propertyName": "clientInterface",
@@ -5,7 +5,8 @@ exports.newVisualScriptingUtilitiesNodeFunctions = function () {
findNodeInNodeMesh: findNodeInNodeMesh,
nodeMeshToPathArray: nodeMeshToPathArray,
findNodeInNodeArray: findNodeInNodeArray,
filterOutNodeWihtoutReferenceParentFromNodeArray: filterOutNodeWihtoutReferenceParentFromNodeArray
filterOutNodeWihtoutReferenceParentFromNodeArray: filterOutNodeWihtoutReferenceParentFromNodeArray,
getManagedSessions: getManagedSessions
}
return thisObject
@@ -51,6 +52,47 @@ exports.newVisualScriptingUtilitiesNodeFunctions = function () {
}
}
/* findManagedSessions(startingNode) :
* recursively searches startingNode branches to documents managed sessions at ~/taskConstants.MANAGED_SESSIONS_MAP
* Session Key naming convention: name + type + id
*/
function getManagedSessions(startingNode) {
if (startingNode == undefined) { return ; }
let schemaDocument = SA.projects.foundations.globals.schemas.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type);
// Base Cases:
if (schemaDocument == undefined) { return; }
if (startingNode.type === 'Session Reference' &&
startingNode.referenceParent != undefined) {
let key = startingNode.referenceParent.name + '-' +
startingNode.referenceParent.type + '-' + startingNode.referenceParent.id;
let communicationModule = TS.projects.portfolioManagement.botModules.PMCommunicationModule_Portfolio.newPMCommunicationModule_Portfolio(key);
TS.projects.foundations.globals.taskConstants.MANAGED_SESSIONS_MAP.set(key, communicationModule);
return;
}
if (schemaDocument.childrenNodesProperties == undefined) { return; }
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
let child = schemaDocument.childrenNodesProperties[i];
switch (child.type) {
case 'node':
getManagedSessions(startingNode[child.name]);
break;
case 'array':
let startingNodePropertyArray = startingNode[child.name];
if (startingNodePropertyArray != undefined) {
for (let j = 0; j < startingNodePropertyArray.length; j++) {
getManagedSessions(startingNodePropertyArray[j]);
}
}
break;
default:
return;
}
}
}
function findNodeInNodeMesh (node, nodeType) {
/*
This function scans a node mesh for a certain node type and
@@ -43,19 +43,19 @@ function newVisualScriptingActionSwitch() {
}
case 'Syncronize Tasks': {
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.syncronizeTasksFoundAtWorkspaceWithBackEnd()
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.synchronizeTasksFoundAtWorkspaceWithBackEnd()
}
break
case 'Syncronize Trading Sessions': {
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd()
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.synchronizeTradingSessionsFoundAtWorkspaceWithBackEnd()
}
break
case 'Syncronize Portfolio Sessions': {
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.syncronizePortfolioSessionsFoundAtWorkspaceWithBackEnd()
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.synchronizePortfolioSessionsFoundAtWorkspaceWithBackEnd()
}
break
case 'Syncronize Learning Sessions': {
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd()
UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.synchronizeLearningSessionsFoundAtWorkspaceWithBackEnd()
}
break
case 'Play Tutorials': {
@@ -1,9 +1,9 @@
function newVisualScritingFunctionLibraryUiObjectsFromNodes() {
let thisObject = {
syncronizeTasksFoundAtWorkspaceWithBackEnd: syncronizeTasksFoundAtWorkspaceWithBackEnd,
syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd: syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd,
syncronizePortfolioSessionsFoundAtWorkspaceWithBackEnd: syncronizePortfolioSessionsFoundAtWorkspaceWithBackEnd,
syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd: syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd,
synchronizeTasksFoundAtWorkspaceWithBackEnd: synchronizeTasksFoundAtWorkspaceWithBackEnd,
synchronizeTradingSessionsFoundAtWorkspaceWithBackEnd: synchronizeTradingSessionsFoundAtWorkspaceWithBackEnd,
synchronizePortfolioSessionsFoundAtWorkspaceWithBackEnd: synchronizePortfolioSessionsFoundAtWorkspaceWithBackEnd,
synchronizeLearningSessionsFoundAtWorkspaceWithBackEnd: synchronizeLearningSessionsFoundAtWorkspaceWithBackEnd,
playTutorials: playTutorials,
recreateWorkspace: recreateWorkspace,
getNodeById: getNodeById,
@@ -277,34 +277,34 @@ function newVisualScritingFunctionLibraryUiObjectsFromNodes() {
}
}
function syncronizeTasksFoundAtWorkspaceWithBackEnd() {
function synchronizeTasksFoundAtWorkspaceWithBackEnd() {
for (let i = 0; i < tasksFoundAtWorkspace.length; i++) {
let node = tasksFoundAtWorkspace[i]
UI.projects.foundations.functionLibraries.taskFunctions.syncronizeTaskWithBackEnd(node)
UI.projects.foundations.functionLibraries.taskFunctions.synchronizeTaskWithBackEnd(node)
}
tasksFoundAtWorkspace = undefined
}
function syncronizeTradingSessionsFoundAtWorkspaceWithBackEnd() {
function synchronizeTradingSessionsFoundAtWorkspaceWithBackEnd() {
for (let i = 0; i < tradingSessionsFoundAtWorkspace.length; i++) {
let node = tradingSessionsFoundAtWorkspace[i]
UI.projects.algorithmicTrading.functionLibraries.tradingSessionFunctions.syncronizeSessionWithBackEnd(node)
UI.projects.algorithmicTrading.functionLibraries.tradingSessionFunctions.synchronizeSessionWithBackEnd(node)
}
tradingSessionsFoundAtWorkspace = undefined
}
function syncronizePortfolioSessionsFoundAtWorkspaceWithBackEnd() {
function synchronizePortfolioSessionsFoundAtWorkspaceWithBackEnd() {
for (let i = 0; i < portfolioSessionsFoundAtWorkspace.length; i++) {
let node = portfolioSessionsFoundAtWorkspace[i]
UI.projects.portfolioManagement.functionLibraries.portfolioSessionFunctions.syncronizeSessionWithBackEnd(node)
UI.projects.portfolioManagement.functionLibraries.portfolioSessionFunctions.synchronizeSessionWithBackEnd(node)
}
portfolioSessionsFoundAtWorkspace = undefined
}
function syncronizeLearningSessionsFoundAtWorkspaceWithBackEnd() {
function synchronizeLearningSessionsFoundAtWorkspaceWithBackEnd() {
for (let i = 0; i < learningSessionsFoundAtWorkspace.length; i++) {
let node = learningSessionsFoundAtWorkspace[i]
UI.projects.machineLearning.functionLibraries.learningSessionFunctions.syncronizeSessionWithBackEnd(node)
UI.projects.machineLearning.functionLibraries.learningSessionFunctions.synchronizeSessionWithBackEnd(node)
}
learningSessionsFoundAtWorkspace = undefined
}
+7 -4
View File
@@ -27,7 +27,8 @@ exports.newTaskServer = function newTaskServer() {
if (taskId !== undefined) {
/*
The Task Manager sent the info via a process argument. In this case we listen to
an event with the Task Info that should be emitted at the UI
an event with the Task Info that should be emitted at the UI;
Also here is where any managedTasks will initially be recorded.
*/
try {
TS.projects.foundations.globals.taskConstants.EVENT_SERVER_CLIENT_MODULE_OBJECT.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, 'Task Server - ' + taskId, undefined, eventReceived)
@@ -35,9 +36,11 @@ exports.newTaskServer = function newTaskServer() {
function eventReceived(message) {
try {
setUpAppSchema(JSON.parse(message.event.projectSchemas))
TS.projects.foundations.globals.taskConstants.TASK_NODE = JSON.parse(message.event.taskDefinition)
TS.projects.foundations.globals.taskConstants.NETWORK_NODE = JSON.parse(message.event.networkDefinition)
bootingProcess()
TS.projects.foundations.globals.taskConstants.TASK_NODE = JSON.parse(message.event.taskDefinition);
TS.projects.foundations.globals.taskConstants.NETWORK_NODE = JSON.parse(message.event.networkDefinition);
TS.projects.foundations.globals.taskConstants.MANAGED_TASKS = JSON.parse(message.event.managedTasksDefinition);
SA.projects.visualScripting.utilities.nodeFunctions.getManagedSessions(TS.projects.foundations.globals.taskConstants.MANAGED_TASKS);
bootingProcess();
} catch (err) {
console.log('[ERROR] Task Server -> Task -> preLoader -> eventReceived -> ' + err.stack)
}