Refactoring out of Intel and AI

This commit is contained in:
Luis Fernando Molina committed 2020-11-03 15:55:05 +01:00
1 parent 4ebdb86a6f
commit 38244f4fc1
10 files changed
+131 -131

No files matched your search

+5 -5
View File
@@ -100,7 +100,7 @@
botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Trading Bot')
}
if (botNode === undefined) {
botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'AI Bot')
botNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Learning Bot')
}
if (botNode === undefined) {
logger.write(MODULE_NAME, "[ERROR] start -> Product Definition not attached to a Bot. Product Definition = ");
@@ -118,14 +118,14 @@
if (dataMineNode === undefined) {
let tradingMineNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Trading Mine')
if (tradingMineNode === undefined) {
let intelMineNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Intel Mine')
if (intelMineNode === undefined) {
logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine, Trading Mine or Intel Mine.");
let learningMineNode = global.FIND_NODE_IN_NODE_MESH(outputDatasetNode, 'Learning Mine')
if (learningMineNode === undefined) {
logger.write(MODULE_NAME, "[ERROR] start -> Bot not attached to a Data Mine, Trading Mine or Learning Mine.");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return
} else {
if (tradingMineNode.config.codeName === undefined) {
logger.write(MODULE_NAME, "[ERROR] start -> Intel Mine witn no codeName defined.");
logger.write(MODULE_NAME, "[ERROR] start -> Learning Mine witn no codeName defined.");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return
}
+1 -1
View File
@@ -65,7 +65,7 @@
let skipCount = 0
/*
The current nodeArray that we have includes all the dependencies daclared in the Data Mine | Trading Mine | Intel Mine
The current nodeArray that we have includes all the dependencies daclared in the Data Mine | Trading Mine | Learning Mine
process dependencies, minus the ones without reference parent, meaning that references Data Mines that are
not present at the workspace. From all the remaining dependencies there will be others that we need to
filter out, and they are the ones which the user does not have a data product anywhere on the network where
+2 -2
View File
@@ -83,8 +83,8 @@ exports.newDebugLog = function newDebugLog() {
if (thisObject.bot.TRADING_SESSION !== undefined) {
filePath = filePath + thisObject.bot.TRADING_SESSION.folderName + "/" + executionDatetime;
} else {
if (thisObject.bot.AI_SESSION !== undefined) {
filePath = filePath + thisObject.bot.AI_SESSION.folderName + "/" + executionDatetime;
if (thisObject.bot.LEARNING_SESSION !== undefined) {
filePath = filePath + thisObject.bot.LEARNING_SESSION.folderName + "/" + executionDatetime;
} else {
filePath = filePath + executionDatetime;
}
+76 -76
View File
@@ -1,6 +1,6 @@
exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
exports.newLearningSession = function newLearningSession(bot, parentLogger) {
const MODULE_NAME = "Training Session"
const MODULE_NAME = "Learning Session"
const FULL_LOG = true;
let thisObject = {
@@ -15,16 +15,16 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
function initialize(pProcessConfig, callBackFunction) {
try {
/* Initialize this info so that everything is logged propeerly */
bot.AI_SESSION = {
bot.LEARNING_SESSION = {
name: bot.processNode.session.name,
id: bot.processNode.session.id
}
/* Set the folderName for early logging */
if (bot.processNode.session.config.folderName === undefined) {
bot.AI_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.AI_SESSION.id
bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.LEARNING_SESSION.id
} else {
bot.AI_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName
bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName
}
/* Check if there is a session */
@@ -79,11 +79,11 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
/* We are going to run the Definition comming at the event. */
bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem)
bot.TRADING_ENGINE = JSON.parse(message.event.tradingEngine)
bot.AI_SESSION = JSON.parse(message.event.session)
bot.LEARNING_SESSION = JSON.parse(message.event.session)
bot.DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter)
bot.RESUME = false
bot.FIRST_EXECUTION = true
bot.AI_SESSION.stop = stopSession // stop function
bot.LEARNING_SESSION.stop = stopSession // stop function
setUpSessionFolderName()
@@ -93,7 +93,7 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
socialBotsModule.initialize()
let allGood
switch (bot.AI_SESSION.type) {
switch (bot.LEARNING_SESSION.type) {
case 'Backtesting Session': {
allGood = startBackTesting(message)
break
@@ -119,7 +119,7 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, '[IMPORTANT] onSessionRun -> Stopping the Session now. ') }
}
socialBotsModule.sendMessage(bot.AI_SESSION.type + " '" + bot.AI_SESSION.name + "' is starting.")
socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + bot.LEARNING_SESSION.name + "' is starting.")
} catch (err) {
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionRun -> err = " + err.stack);
}
@@ -131,7 +131,7 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
function onSessionResume(message) {
try {
if (bot.AI_SESSION.stop === undefined) {
if (bot.LEARNING_SESSION.stop === undefined) {
parentLogger.write(MODULE_NAME, "[WARN] onSessionResume -> Event received to resume the Session that have never be ran before. ")
return
}
@@ -145,7 +145,7 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
bot.RESUME = true
bot.STOP_SESSION = false
socialBotsModule.sendMessage(bot.AI_SESSION.type + " '" + bot.AI_SESSION.name + "' is resuming.")
socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + bot.LEARNING_SESSION.name + "' is resuming.")
} catch (err) {
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionResume -> err = " + err.stack);
}
@@ -153,11 +153,11 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
function stopSession(commandOrigin) {
socialBotsModule.sendMessage(bot.AI_SESSION.type + " '" + bot.AI_SESSION.name + "' is stopping " + commandOrigin)
socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + bot.LEARNING_SESSION.name + "' is stopping " + commandOrigin)
socialBotsModule.finalize()
bot.STOP_SESSION = true
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, '[IMPORTANT] stopSession -> Stopping the Session now. ') }
sessionInfo(bot.AI_SESSION, commandOrigin)
sessionInfo(bot.LEARNING_SESSION, commandOrigin)
}
function setUpSessionFolderName() {
@@ -167,12 +167,12 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
Set the folderName for logging, reports, context and data output
*/
let config
if (bot.AI_SESSION.config !== undefined) {
config = bot.AI_SESSION.config
if (bot.LEARNING_SESSION.config !== undefined) {
config = bot.LEARNING_SESSION.config
if (config.folderName === undefined) {
bot.AI_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.AI_SESSION.id
bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.LEARNING_SESSION.id
} else {
bot.AI_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName
bot.LEARNING_SESSION.folderName = bot.processNode.session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.processNode.session.config.folderName
}
}
}
@@ -183,16 +183,16 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
non critical is missing, we complete it with a default value.
*/
if (bot.AI_SESSION.parameters === undefined) {
if (bot.LEARNING_SESSION.parameters === undefined) {
let errorMessage = "Session Node with no Parameters."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION, errorMessage)
bot.sessionError(bot.LEARNING_SESSION, errorMessage)
return false
}
/* Time Range */
if (bot.AI_SESSION.parameters.timeRange === undefined) { // if the Time Range is missing we create a default one.
bot.AI_SESSION.parameters.timeRange = {
if (bot.LEARNING_SESSION.parameters.timeRange === undefined) { // if the Time Range is missing we create a default one.
bot.LEARNING_SESSION.parameters.timeRange = {
name: 'Missing Time Range',
type: 'Time Range',
config: {
@@ -202,18 +202,18 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
}
} else {
/* Check that we received valid dates */
if (bot.AI_SESSION.type === 'Backtesting Session') {
if (isNaN(new Date(bot.AI_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()) {
if (bot.LEARNING_SESSION.type === 'Backtesting Session') {
if (isNaN(new Date(bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()) {
let errorMessage = "sessionParameters.timeRange.config.initialDatetime is not a valid date."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
return false
}
}
if (isNaN(new Date(bot.AI_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()) {
if (isNaN(new Date(bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()) {
let errorMessage = "sessionParameters.timeRange.config.initialDatetime is not a valid date."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
return false
}
}
@@ -222,7 +222,7 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
let today = (new Date()).valueOf()
let aYearAgo = today - global.ONE_YEAR_IN_MILISECONDS
let aYearFromNow = today + global.ONE_YEAR_IN_MILISECONDS
switch (bot.AI_SESSION.type) {
switch (bot.LEARNING_SESSION.type) {
case 'Backtesting Session': {
useDefaultDatetimes(aYearAgo, today)
break
@@ -248,81 +248,81 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
*/
/* Initial Datetime */
if (bot.AI_SESSION.type === 'Backtesting Session') {
if (bot.AI_SESSION.parameters.timeRange.config.initialDatetime === undefined) {
bot.AI_SESSION.parameters.timeRange.config.initialDatetime = initialDefault
if (bot.LEARNING_SESSION.type === 'Backtesting Session') {
if (bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime === undefined) {
bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime = initialDefault
} else {
bot.AI_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.AI_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
}
} else {
/* Non backtest session can start from the past only if explicitly configured that way */
if (bot.AI_SESSION.parameters.timeRange.config.initialDatetime === undefined || bot.AI_SESSION.parameters.timeRange.config.allowStartingFromThePast !== true) {
bot.AI_SESSION.parameters.timeRange.config.initialDatetime = initialDefault
if (bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime === undefined || bot.LEARNING_SESSION.parameters.timeRange.config.allowStartingFromThePast !== true) {
bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime = initialDefault
} else {
bot.AI_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.AI_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
}
}
/* Final Datetime */
if (bot.AI_SESSION.parameters.timeRange.config.finalDatetime === undefined) {
bot.AI_SESSION.parameters.timeRange.config.finalDatetime = finalDefault
if (bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime === undefined) {
bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime = finalDefault
} else {
bot.AI_SESSION.parameters.timeRange.config.finalDatetime = (new Date(bot.AI_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()
bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime = (new Date(bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()
}
}
/* Time Frame */
if (bot.AI_SESSION.parameters.timeFrame === undefined) {
if (bot.LEARNING_SESSION.parameters.timeFrame === undefined) {
let errorMessage = "Session Parameters Node with no Time Frame."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
return false
}
if (bot.AI_SESSION.parameters.timeFrame.config.label === undefined) {
if (bot.LEARNING_SESSION.parameters.timeFrame.config.label === undefined) {
let errorMessage = "Session Parameters Node with no Time Frame Label configuration."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters.timeFrame, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters.timeFrame, errorMessage)
return false
}
bot.AI_SESSION.parameters.timeFrame.config.value = getTimeFrameFromLabel(bot.AI_SESSION.parameters.timeFrame.config.label)
if (bot.AI_SESSION.parameters.timeFrame.config.value === undefined) {
bot.LEARNING_SESSION.parameters.timeFrame.config.value = getTimeFrameFromLabel(bot.LEARNING_SESSION.parameters.timeFrame.config.label)
if (bot.LEARNING_SESSION.parameters.timeFrame.config.value === undefined) {
let errorMessage = "Config error: label value not recognized. Try 01-min or 01-hs for example."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters.timeFrame, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters.timeFrame, errorMessage)
return false
}
/* Session Base Asset */
if (bot.AI_SESSION.parameters.sessionBaseAsset === undefined) {
if (bot.LEARNING_SESSION.parameters.sessionBaseAsset === undefined) {
let errorMessage = "Session Parameters Node with no Session Base Asset."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
return false
}
if (bot.AI_SESSION.parameters.sessionBaseAsset.config.initialBalance === undefined) {
if (bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.initialBalance === undefined) {
let errorMessage = "Session Parameters Session Base Asset with no initialBalance configuration."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters.sessionBaseAsset, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters.sessionBaseAsset, errorMessage)
return false
}
/* Session Quoted Asset */
if (bot.AI_SESSION.parameters.sessionQuotedAsset === undefined) {
if (bot.LEARNING_SESSION.parameters.sessionQuotedAsset === undefined) {
let errorMessage = "Session Parameters Node with no Session Quoted Asset."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
return false
}
if (bot.AI_SESSION.parameters.sessionQuotedAsset.config.initialBalance === undefined) {
if (bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.initialBalance === undefined) {
let errorMessage = "Session Parameters Session Quoted Asset with no initialBalance configuration."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.AI_SESSION.parameters.sessionQuotedAsset, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters.sessionQuotedAsset, errorMessage)
return false
}
/* Slippage */
if (bot.AI_SESSION.parameters.slippage === undefined) { // if the Slippage is missing we create a default one.
bot.AI_SESSION.parameters.slippage = {
if (bot.LEARNING_SESSION.parameters.slippage === undefined) { // if the Slippage is missing we create a default one.
bot.LEARNING_SESSION.parameters.slippage = {
name: 'Missing Slippage',
type: 'Slippage',
config: {
@@ -332,19 +332,19 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
}
}
}
if (bot.AI_SESSION.parameters.slippage.config.marketOrderRate === undefined) { // if the marketOrderRate is missing we create a default one.
bot.AI_SESSION.parameters.slippage.config.marketOrderRate = 0
if (bot.LEARNING_SESSION.parameters.slippage.config.marketOrderRate === undefined) { // if the marketOrderRate is missing we create a default one.
bot.LEARNING_SESSION.parameters.slippage.config.marketOrderRate = 0
}
if (bot.AI_SESSION.parameters.slippage.config.stopLoss === undefined) { // if the stopLoss is missing we create a default one.
bot.AI_SESSION.parameters.slippage.config.stopLoss = 0
if (bot.LEARNING_SESSION.parameters.slippage.config.stopLoss === undefined) { // if the stopLoss is missing we create a default one.
bot.LEARNING_SESSION.parameters.slippage.config.stopLoss = 0
}
if (bot.AI_SESSION.parameters.slippage.config.takeProfit === undefined) { // if the takeProfit is missing we create a default one.
bot.AI_SESSION.parameters.slippage.config.takeProfit = 0
if (bot.LEARNING_SESSION.parameters.slippage.config.takeProfit === undefined) { // if the takeProfit is missing we create a default one.
bot.LEARNING_SESSION.parameters.slippage.config.takeProfit = 0
}
/* Fee Structure */
if (bot.AI_SESSION.parameters.feeStructure === undefined) { // if the Fee Structure is missing we create a default one.
bot.AI_SESSION.parameters.feeStructure = {
if (bot.LEARNING_SESSION.parameters.feeStructure === undefined) { // if the Fee Structure is missing we create a default one.
bot.LEARNING_SESSION.parameters.feeStructure = {
name: 'Missing Fee Structure',
type: 'Fee Structure',
config: {
@@ -353,11 +353,11 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
}
}
}
if (bot.AI_SESSION.parameters.feeStructure.config.maker === undefined) { // if the maker is missing we create a default one.
bot.AI_SESSION.parameters.feeStructure.config.maker = 0
if (bot.LEARNING_SESSION.parameters.feeStructure.config.maker === undefined) { // if the maker is missing we create a default one.
bot.LEARNING_SESSION.parameters.feeStructure.config.maker = 0
}
if (bot.AI_SESSION.parameters.feeStructure.config.taker === undefined) { // if the taker is missing we create a default one.
bot.AI_SESSION.parameters.feeStructure.config.taker = 0
if (bot.LEARNING_SESSION.parameters.feeStructure.config.taker === undefined) { // if the taker is missing we create a default one.
bot.LEARNING_SESSION.parameters.feeStructure.config.taker = 0
}
return true
@@ -371,7 +371,7 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
if (bot.KEY === undefined || bot.SECRET === undefined) {
let errorMessage = "Key 'codeName' or 'secret' not provided. Plese check that and try again."
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> startLiveTrading -> " + errorMessage); }
bot.sessionError(bot.AI_SESSION, errorMessage)
bot.sessionError(bot.LEARNING_SESSION, errorMessage)
return false
}
return true
@@ -387,20 +387,20 @@ exports.newTrainingSession = function newTrainingSession(bot, parentLogger) {
/* Reduce the balance */
let balancePercentage = 1 // This is the default value
if (bot.AI_SESSION.config.balancePercentage !== undefined) {
balancePercentage = bot.AI_SESSION.config.balancePercentage
if (bot.LEARNING_SESSION.config.balancePercentage !== undefined) {
balancePercentage = bot.LEARNING_SESSION.config.balancePercentage
}
bot.AI_SESSION.parameters.sessionBaseAsset.config.initialBalance = bot.AI_SESSION.parameters.sessionBaseAsset.config.initialBalance * balancePercentage / 100
bot.AI_SESSION.parameters.sessionQuotedAsset.config.initialBalance = bot.AI_SESSION.parameters.sessionQuotedAsset.config.initialBalance * balancePercentage / 100
bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.initialBalance = bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.initialBalance * balancePercentage / 100
bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.initialBalance = bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.initialBalance * balancePercentage / 100
bot.AI_SESSION.parameters.sessionBaseAsset.config.minimumBalance = bot.AI_SESSION.parameters.sessionBaseAsset.config.minimumBalance * balancePercentage / 100
bot.AI_SESSION.parameters.sessionQuotedAsset.config.minimumBalance = bot.AI_SESSION.parameters.sessionQuotedAsset.config.minimumBalance * balancePercentage / 100
bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.minimumBalance = bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.minimumBalance * balancePercentage / 100
bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.minimumBalance = bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.minimumBalance * balancePercentage / 100
bot.AI_SESSION.parameters.sessionBaseAsset.config.maximumBalance = bot.AI_SESSION.parameters.sessionBaseAsset.config.maximumBalance * balancePercentage / 100
bot.AI_SESSION.parameters.sessionQuotedAsset.config.maximumBalance = bot.AI_SESSION.parameters.sessionQuotedAsset.config.maximumBalance * balancePercentage / 100
bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.maximumBalance = bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.maximumBalance * balancePercentage / 100
bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.maximumBalance = bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.maximumBalance * balancePercentage / 100
pProcessConfig.normalWaitTime = bot.AI_SESSION.parameters.timeFrame.config.value
pProcessConfig.normalWaitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
return true
}
+3 -3
View File
@@ -33,7 +33,7 @@
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Sensor Bot')
}
if (botNode === undefined) {
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'AI Bot')
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Learning Bot')
}
/* Some validations to verify that everything is in place. */
@@ -123,7 +123,7 @@
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Sensor Bot')
}
if (botNode === undefined) {
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'AI Bot')
botNode = global.FIND_NODE_IN_NODE_MESH(outputDataset, 'Learning Bot')
}
/* Some validations to verify that everything is in place. */
@@ -148,7 +148,7 @@
throw (global.DEFAULT_FAIL_RESPONSE);
}
} else {
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine | Trading Mine | Intel Mine. Bot = " + JSON.stringify(botNode));
logger.write(MODULE_NAME, "[ERROR] raiseEvents -> Bot not attached to a Data Mine | Trading Mine | Learning Mine. Bot = " + JSON.stringify(botNode));
throw (global.DEFAULT_FAIL_RESPONSE);
}
} else {
@@ -1,6 +1,6 @@
exports.newAiBot = function newAiBot(bot, parentLogger) {
exports.newLearningBot = function newLearningBot(bot, parentLogger) {
const MODULE_NAME = "Ai Bot";
const MODULE_NAME = "Learning Bot";
const FULL_LOG = true;
const TRADING_PROCESS_MODULE = require(global.ROOT_DIR + '/LowFrequencyTrading/MachineLearningProcess.js');
@@ -8,7 +8,7 @@ exports.newAiBot = function newAiBot(bot, parentLogger) {
const SESSION = require(global.ROOT_DIR + 'TradingSession');
let fileStorage = FILE_STORAGE.newFileStorage(parentLogger);
let session = SESSION.newTrainingSession(bot, parentLogger)
let session = SESSION.newLearningSession(bot, parentLogger)
const DEBUG_MODULE = require(global.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.
@@ -560,17 +560,17 @@ exports.newAiBot = function newAiBot(bot, parentLogger) {
if (processConfig.waitsForExecutionFinishedEvent === true) {
waitTime = 0
} else {
switch (bot.AI_SESSION.type) {
switch (bot.LEARNING_SESSION.type) {
case 'Live Trading Session': {
waitTime = bot.AI_SESSION.parameters.timeFrame.config.value
waitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
break
}
case 'Fordward Tessting Session': {
waitTime = bot.AI_SESSION.parameters.timeFrame.config.value
waitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
break
}
case 'Paper Trading Session': {
waitTime = bot.AI_SESSION.parameters.timeFrame.config.value
waitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
break
}
case 'Backtesting Session': {
@@ -1,10 +1,10 @@
exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES) {
exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES) {
/*
This Module will load all the process data dependencies from files and send them downstream.
After execution, will save the time range and status report of the process.
*/
const FULL_LOG = true;
const MODULE_NAME = "Training Process";
const MODULE_NAME = "Learning Process";
const GMT_SECONDS = ':00.000 GMT+0000';
thisObject = {
@@ -115,7 +115,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
the simulation loop, once we discover that all candles from a certain date have benn processed.
Here is the point where we sync one and the other.
*/
let TrainingProcessDate = global.REMOVE_TIME(bot.simulationState.tradingEngine.current.episode.processDate.value)
let LearningProcessDate = global.REMOVE_TIME(bot.simulationState.tradingEngine.current.episode.processDate.value)
await processSingleFiles()
if (await processMarketFiles() === false) {
@@ -166,7 +166,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
use it to save Output Files and later the Data Ranges. This is the point where
the date calculated by the Simulation is applied at the Trading Process Level.
*/
TrainingProcessDate = global.REMOVE_TIME(bot.simulationState.tradingEngine.current.episode.processDate.value)
LearningProcessDate = global.REMOVE_TIME(bot.simulationState.tradingEngine.current.episode.processDate.value)
if (checkStopTaskGracefully() === false) { break }
if (checkStopProcessing() === false) { break }
@@ -447,7 +447,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
async function processDailyFiles() {
/* Telling the world we are alive and doing well and which date we are processing right now. */
let processingDateString = TrainingProcessDate.getUTCFullYear() + '-' + utilities.pad(TrainingProcessDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(TrainingProcessDate.getUTCDate(), 2);
let processingDateString = LearningProcessDate.getUTCFullYear() + '-' + utilities.pad(LearningProcessDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(LearningProcessDate.getUTCDate(), 2);
bot.processHeartBeat(processingDateString, undefined, "Running...")
/*
@@ -493,7 +493,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
}
}
let dateForPath = TrainingProcessDate.getUTCFullYear() + '/' + utilities.pad(TrainingProcessDate.getUTCMonth() + 1, 2) + '/' + utilities.pad(TrainingProcessDate.getUTCDate(), 2);
let dateForPath = LearningProcessDate.getUTCFullYear() + '/' + utilities.pad(LearningProcessDate.getUTCMonth() + 1, 2) + '/' + utilities.pad(LearningProcessDate.getUTCDate(), 2);
let filePath
if (dependency.referenceParent.config.codeName === "Multi-Period-Daily") {
filePath = dependency.referenceParent.parentNode.config.codeName + '/' + dependency.referenceParent.config.codeName + "/" + timeFrameLabel + "/" + dateForPath;
@@ -612,7 +612,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
chart,
currentTimeFrame,
currentTimeFrameLabel,
TrainingProcessDate
LearningProcessDate
)
/*
@@ -648,7 +648,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
async function writeDataRange(productCodeName) {
let dataRange = {
begin: contextVariables.dateBeginOfMarket.valueOf(),
end: TrainingProcessDate.valueOf() + global.ONE_DAY_IN_MILISECONDS
end: LearningProcessDate.valueOf() + global.ONE_DAY_IN_MILISECONDS
}
let fileContent = JSON.stringify(dataRange);
@@ -707,7 +707,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
let thisReport = statusDependencies.statusReports.get(reportKey)
thisReport.file.lastExecution = bot.currentDaytime
thisReport.file.lastFile = TrainingProcessDate
thisReport.file.lastFile = LearningProcessDate
thisReport.file.simulationState = bot.simulationState
thisReport.file.timeFrames = currentTimeFrameLabel
await thisReport.asyncSave()
@@ -721,7 +721,7 @@ exports.newTrainingProcess = function newTrainingProcess(bot, logger, UTILITIES)
thisReport.file.simulationState = bot.simulationState
thisReport.file.timeFrames = currentTimeFrameLabel
logger.newInternalLoop(bot.codeName, bot.process, TrainingProcessDate)
logger.newInternalLoop(bot.codeName, bot.process, LearningProcessDate)
await thisReport.asyncSave()
}
}
@@ -25,7 +25,7 @@ exports.newMarkovDecisionProcess = function newMarkovDecisionProcess(bot, logger
function initialize() {
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.AI_SESSION.parameters
sessionParameters = bot.LEARNING_SESSION.parameters
initializeNodeMap(tradingEngine)
+23 -23
View File
@@ -266,8 +266,8 @@
runTradingBot(botConfig, processConfig);
break;
}
case 'AI Bot': {
runAIBot(botConfig, processConfig);
case 'Learning Bot': {
runLearningBot(botConfig, processConfig);
break;
}
default: {
@@ -300,8 +300,8 @@
runTradingBot(botConfig, processConfig);
break;
}
case 'AI Bot': {
runAIBot(botConfig, processConfig);
case 'Learning Bot': {
runLearningBot(botConfig, processConfig);
break;
}
default: {
@@ -347,8 +347,8 @@
runTradingBot(botConfig, processConfig);
break;
}
case 'AI Bot': {
runAIBot(botConfig, processConfig);
case 'Learning Bot': {
runLearningBot(botConfig, processConfig);
break;
}
default: {
@@ -553,7 +553,7 @@
}
}
function runAIBot(pBotConfig, pProcessConfig) {
function runLearningBot(pBotConfig, pProcessConfig) {
global.TOTAL_PROCESS_INSTANCES_CREATED++
@@ -562,19 +562,19 @@
let logger;
logger = DEBUG_MODULE.newDebugLog();
global.LOGGER_MAP.set('runAIBot', logger)
global.LOGGER_MAP.set('runLearningBot', logger)
logger.bot = pBotConfig;
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runAIBot -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runLearningBot -> Entering function."); }
let aiBot = TRADING_BOT_MODULE.newAIBot(pBotConfig, logger);
aiBot.initialize(pProcessConfig, onInitializeReady);
let learningBot = TRADING_BOT_MODULE.newLearningBot(pBotConfig, logger);
learningBot.initialize(pProcessConfig, onInitializeReady);
function onInitializeReady(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
aiBot.run(whenRunFinishes);
learningBot.run(whenRunFinishes);
function whenRunFinishes(err) {
@@ -586,34 +586,34 @@
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runAIBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully.");
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runAIBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runLearningBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully.");
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runLearningBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
logger.persist();
} else {
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> whenStartFinishes -> Bye.");
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished with errors. Please check the logs.");
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> whenStartFinishes -> Bye.");
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished with errors. Please check the logs.");
logger.persist();
}
setTimeout(exitProcessInstance, WAIT_TIME_FOR_ALL_PROCESS_INSTANCES_TO_START)
}
} else {
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> Failed to initialize the bot. ");
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runAIBot -> onInitializeReady -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> Failed to initialize the bot. ");
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runLearningBot -> onInitializeReady -> err = " + err.message);
logger.persist();
setTimeout(exitProcessInstance, WAIT_TIME_FOR_ALL_PROCESS_INSTANCES_TO_START)
}
}
}
catch (err) {
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runAIBot -> err = " + err.stack);
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runLearningBot -> err = " + err.stack);
setTimeout(exitProcessInstance, WAIT_TIME_FOR_ALL_PROCESS_INSTANCES_TO_START)
}
}
+3 -3
View File
@@ -104,8 +104,8 @@
sessionPath = bot.TRADING_SESSION.folderName + "/"
}
if (bot.AI_SESSION !== undefined && statusDependencyNode.bottype === "AI Bot") {
sessionPath = bot.AI_SESSION.folderName + "/"
if (bot.LEARNING_SESSION !== undefined && statusDependencyNode.bottype === "Learning Bot") {
sessionPath = bot.LEARNING_SESSION.folderName + "/"
}
/* Now we will see where do we need to fetch this status report from. */
@@ -268,7 +268,7 @@
On the contraty, if we are running a Sensor bot or an Indicator bot, we might, if necesary, use a previous version of a Status Report since
there will be no big impact, just some reprocessing.
*/
if (bot.TRADING_SESSION !== undefined || bot.AI_SESSION !== undefined) {
if (bot.TRADING_SESSION !== undefined || bot.LEARNING_SESSION !== undefined) {
canUserPrevious = false
} else {
canUserPrevious = true