askPortfolioEventsManager function implemented

This commit is contained in:
Luis Fernando Molina committed 2021-11-29 15:06:51 +01:00
1 parent b577dcc3d5
commit 772c4fe326
2 files changed
+51 -8

No files matched your search

@@ -107,7 +107,7 @@ exports.newAlgorithmicTradingBotModulesTradingStages = function (processIndex) {
checkTriggerOff()
checkTakePosition()
function checkTriggerOn() {
async function checkTriggerOn() {
if (
tradingEngine.tradingCurrent.strategy.index.value === tradingEngine.tradingCurrent.strategy.index.config.initialValue
) {
@@ -140,7 +140,8 @@ exports.newAlgorithmicTradingBotModulesTradingStages = function (processIndex) {
tradingSystem.values.push([situation.id, passed])
portfolioManagerClient.askPortfolioEventManager(triggerStage.triggerOn, { status: passed })
let response = await portfolioManagerClient.askPortfolioEventsManager(triggerStage.triggerOn, passed)
passed = response.raiseEvent
if (passed) {
@@ -172,7 +173,7 @@ exports.newAlgorithmicTradingBotModulesTradingStages = function (processIndex) {
}
}
function checkTriggerOff() {
async function checkTriggerOff() {
if (tradingEngine.tradingCurrent.strategyTriggerStage.status.value === 'Open') {
checkUserDefinedCode('Trigger Stage', 'Running', 'first');
@@ -193,6 +194,10 @@ exports.newAlgorithmicTradingBotModulesTradingStages = function (processIndex) {
passed = tradingSystem.checkConditions(situation, passed)
tradingSystem.values.push([situation.id, passed])
let response = await portfolioManagerClient.askPortfolioEventsManager(triggerStage.triggerOff, passed)
passed = response.raiseEvent
if (passed) {
tradingSystem.highlights.push(situation.id)
tradingSystem.highlights.push(triggerStage.triggerOff.id)
@@ -211,7 +216,7 @@ exports.newAlgorithmicTradingBotModulesTradingStages = function (processIndex) {
}
}
function checkTakePosition() {
async function checkTakePosition() {
if (
tradingEngine.tradingCurrent.strategyTriggerStage.status.value === 'Open'
) {
@@ -233,6 +238,10 @@ exports.newAlgorithmicTradingBotModulesTradingStages = function (processIndex) {
passed = tradingSystem.checkConditions(situation, passed)
tradingSystem.values.push([situation.id, passed])
let response = await portfolioManagerClient.askPortfolioEventsManager(triggerStage.takePosition, passed)
passed = response.raiseEvent
if (passed) {
tradingSystem.highlights.push(situation.id)
tradingSystem.highlights.push(triggerStage.takePosition.id)
@@ -4,8 +4,8 @@ exports.newPortfolioManagementModulesPortfolioManagerClient = function (processI
questions to the Event and Formula Managers and receive their answers.
*/
let thisObject = {
askPortfolioEventManager: askPortfolioEventManager,
askPortfolioFormulaManager: askPortfolioFormulaManager,
askPortfolioEventsManager: askPortfolioEventsManager,
askPortfolioFormulaManager: askPortfolioFormulaManager,
initialize: initialize,
finalize: finalize
}
@@ -20,8 +20,42 @@ exports.newPortfolioManagementModulesPortfolioManagerClient = function (processI
}
async function askPortfolioEventManager(eventNode, conectInfo) {
console.log('here')
async function askPortfolioEventsManager(eventNode, eventStatus) {
let reponse = {
raiseEvent: eventStatus,
reason: "No need to ask Portfolio Manager"
}
if (eventNode.askPortfolioEventsManager === undefined) {
return reponse
}
if (eventStatus === true) {
/*
First we will check if the Portfolio Manager confirms this event
can be raised.
*/
if (eventNode.askPortfolioEventsManager.confirmEvent !== undefined) {
let message = {
question: "Confirm This Event Can Be Raised",
event: eventNode.type
}
reponse = await portfolioManagerEventsClient.sendMessage(message)
}
} else {
/*
In this case, we will check if the Porfolio Manager would like to
raise this event anyways.
*/
if (eventNode.askPortfolioEventsManager.raiseEvent !== undefined) {
let message = {
question: "Must This Event Be Raised",
event: eventNode.type
}
reponse = await portfolioManagerEventsClient.sendMessage(message)
}
}
return response
}
async function askPortfolioFormulaManager() {