Trading Engine Loop Improved

This commit is contained in:
Luis Fernando Molina committed 2019-09-11 17:04:43 +02:00
1 parent 5128358bac
commit 0e606c971b
2 files changed
+32 -21

No files matched your search

+28 -3
View File
@@ -94,6 +94,7 @@
bot.enableCheckLoopHealth = true;
let fixedTimeLoopIntervalHandle;
let skipProcessing = true;
if (bot.runAtFixedInterval === true) {
@@ -101,10 +102,25 @@
} else {
loop();
backtestingEventListenerSubscriptionId = global.SYSTEM_EVENT_HANDLER.listenToEvent('Cockpit-Restart-Button', 'Backstesting Started', undefined, undefined, undefined, startBackTesting)
liveTradingEventListenerSubscriptionId = global.SYSTEM_EVENT_HANDLER.listenToEvent('Cockpit-Restart-Button', 'Live-Trading Started', undefined, undefined, undefined, startLiveTrading)
stopRequestedEventListenerSubscriptionId = global.SYSTEM_EVENT_HANDLER.listenToEvent('Cockpit-Restart-Button', 'Stop Requested', undefined, undefined, undefined, stopRequested)
function startBackTesting() {
skipProcessing = false
}
function startLiveTrading() {
skipProcessing = false
}
function stopRequested() {
skipProcessing = true
}
}
loop();
function loop() {
try {
@@ -125,6 +141,17 @@
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Entering function."); }
let nextWaitTime;
/* Checking if we should process this loop or not.*/
if (skipProcessing === true) {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start."); }
console.log("[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start.")
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return
}
/* Loop Heartbeat sent to the UI */
hearBeat()
@@ -155,8 +182,6 @@
let statusDependencies;
let dataDependencies;
let nextWaitTime;
initializeStatusDependencies();
function initializeStatusDependencies() {
+4 -18
View File
@@ -105,23 +105,6 @@ global.SYSTEM_EVENT_HANDLER.initialize('Task Server', bootLoader)
function bootLoader() {
//global.SYSTEM_EVENT_HANDLER.createEventHandler(global.USER_DEFINITION.name)
/*
tryToListenToCockpit()
function tryToListenToCockpit() {
global.SYSTEM_EVENT_HANDLER.listenToEvent('Cockpit-Restart-Simulation', 'Simulation Started', undefined, 'Task Server Boot Loader', onResponse, startSequence)
function onResponse(message) {
if (message.result !== global.DEFAULT_OK_RESPONSE.result) {
setTimeout(tryToListenToCockpit, 3000)
}
}
}
*/
for (let i = 0; i < global.USER_DEFINITION.bot.processes.length; i++) {
let code = global.USER_DEFINITION.bot.processes[i].code
@@ -136,12 +119,15 @@ function bootLoader() {
}
/* Heartbeat sent to the UI */
let key = global.USER_DEFINITION.name + '-' + global.USER_DEFINITION.type + '-' + global.USER_DEFINITION.id
global.SYSTEM_EVENT_HANDLER.createEventHandler(key)
global.HEARTBEAT_INTERVAL_HANDLER = setInterval(hearBeat, 1000)
function hearBeat() {
/* The heartbeat event is raised at the event handler of the instance of this task, created at the UI. */
let key = global.USER_DEFINITION.name + '-' + global.USER_DEFINITION.type + '-' + global.USER_DEFINITION.id
let event = {
seconds: (new Date()).getSeconds()
}