Moving execution update to each execution

This commit is contained in:
mati108@gmail.com committed 2019-02-13 17:25:59 -03:00
1 parent e9e4d6456f
commit 49602bf12f
2 files changed
+19 -21

No files matched your search

+2 -19
View File
@@ -1,7 +1,4 @@
const appRoot = require('app-root-path')
const operationsIntegration = require(`${appRoot}/Integrations/OperationsModuleIntegration`)
exports.newRoot = function newRoot() {
exports.newRoot = function newRoot() {
/* Callbacks default responses. */
@@ -917,21 +914,7 @@ exports.newRoot = function newRoot() {
logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot execution finished with errors. Please check the logs.");
logger.persist();
}
// Update operations module with latest context
if (context !== undefined) {
let lastExecution = context.executionHistory[context.executionHistory.length - 1]
let date = lastExecution[0] / 1000 | 0
let buyAvgRate = lastExecution[1]
let sellAvgRate = lastExecution[2]
let marketRate = lastExecution[7]
let combinedProfitsA = lastExecution[13]
let combinedProfitsB = lastExecution[14]
operationsIntegration.updateExecutionResults(date, buyAvgRate, sellAvgRate,
marketRate, combinedProfitsA, combinedProfitsB)
}
}
}
} else {
+17 -2
View File
@@ -8,8 +8,9 @@
let USER_BOT_MODULE;
let COMMONS_MODULE;
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
const operationsIntegration = require('./Integrations/OperationsModuleIntegration')
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog');
let logger; // We need this here in order for the loopHealth function to work and be able to rescue the loop when it gets in trouble.
@@ -907,12 +908,26 @@
}
}
function saveContext() {
async function saveContext() {
try {
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> saveContext -> Entering function."); }
// Update operations module with latest context
let lastExecution = context.newHistoryRecord
let date = lastExecution.date / 1000 | 0
let buyAvgRate = lastExecution.buyAvgRate
let sellAvgRate = lastExecution.sellAvgRate
let marketRate = lastExecution.marketRate
let combinedProfitsA = lastExecution.combinedProfitsA
let combinedProfitsB = lastExecution.combinedProfitsB
await operationsIntegration.updateExecutionResults(date, buyAvgRate, sellAvgRate,
marketRate, combinedProfitsA, combinedProfitsB)
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> saveContext -> Execution Results updated."); }
context.saveThemAll(onFinished);
function onFinished(err) {