Parameters and Bug Fix

This commit is contained in:
Luis Fernando Molina committed 2020-11-05 15:57:29 +01:00
1 parent 5a82a3bd35
commit 7dd461ca8d
29 files changed
+286 -205

No files matched your search

+52 -52
View File
@@ -183,7 +183,7 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
non critical is missing, we complete it with a default value.
*/
if (bot.LEARNING_SESSION.parameters === undefined) {
if (bot.LEARNING_SESSION.learningParameters === undefined) {
let errorMessage = "Session Node with no Parameters."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.LEARNING_SESSION, errorMessage)
@@ -191,8 +191,8 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
}
/* Time Range */
if (bot.LEARNING_SESSION.parameters.timeRange === undefined) { // if the Time Range is missing we create a default one.
bot.LEARNING_SESSION.parameters.timeRange = {
if (bot.LEARNING_SESSION.learningParameters.timeRange === undefined) { // if the Time Range is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.timeRange = {
name: 'Missing Time Range',
type: 'Time Range',
config: {
@@ -203,17 +203,17 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
} else {
/* Check that we received valid dates */
if (bot.LEARNING_SESSION.type === 'Backtesting Session') {
if (isNaN(new Date(bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()) {
if (isNaN(new Date(bot.LEARNING_SESSION.learningParameters.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.LEARNING_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters, errorMessage)
return false
}
}
if (isNaN(new Date(bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()) {
if (isNaN(new Date(bot.LEARNING_SESSION.learningParameters.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.LEARNING_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters, errorMessage)
return false
}
}
@@ -249,80 +249,80 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
/* Initial Datetime */
if (bot.LEARNING_SESSION.type === 'Backtesting Session') {
if (bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime === undefined) {
bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime = initialDefault
if (bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime === undefined) {
bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime = initialDefault
} else {
bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime = (new Date(bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime)).valueOf()
}
} else {
/* Non backtest session can start from the past only if explicitly configured that way */
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
if (bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime === undefined || bot.LEARNING_SESSION.learningParameters.timeRange.config.allowStartingFromThePast !== true) {
bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime = initialDefault
} else {
bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.LEARNING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime = (new Date(bot.LEARNING_SESSION.learningParameters.timeRange.config.initialDatetime)).valueOf()
}
}
/* Final Datetime */
if (bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime === undefined) {
bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime = finalDefault
if (bot.LEARNING_SESSION.learningParameters.timeRange.config.finalDatetime === undefined) {
bot.LEARNING_SESSION.learningParameters.timeRange.config.finalDatetime = finalDefault
} else {
bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime = (new Date(bot.LEARNING_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()
bot.LEARNING_SESSION.learningParameters.timeRange.config.finalDatetime = (new Date(bot.LEARNING_SESSION.learningParameters.timeRange.config.finalDatetime)).valueOf()
}
}
/* Time Frame */
if (bot.LEARNING_SESSION.parameters.timeFrame === undefined) {
if (bot.LEARNING_SESSION.learningParameters.timeFrame === undefined) {
let errorMessage = "Session Parameters Node with no Time Frame."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters, errorMessage)
return false
}
if (bot.LEARNING_SESSION.parameters.timeFrame.config.label === undefined) {
if (bot.LEARNING_SESSION.learningParameters.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.LEARNING_SESSION.parameters.timeFrame, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters.timeFrame, errorMessage)
return false
}
bot.LEARNING_SESSION.parameters.timeFrame.config.value = getTimeFrameFromLabel(bot.LEARNING_SESSION.parameters.timeFrame.config.label)
if (bot.LEARNING_SESSION.parameters.timeFrame.config.value === undefined) {
bot.LEARNING_SESSION.learningParameters.timeFrame.config.value = getTimeFrameFromLabel(bot.LEARNING_SESSION.learningParameters.timeFrame.config.label)
if (bot.LEARNING_SESSION.learningParameters.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.LEARNING_SESSION.parameters.timeFrame, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters.timeFrame, errorMessage)
return false
}
/* Session Base Asset */
if (bot.LEARNING_SESSION.parameters.sessionBaseAsset === undefined) {
if (bot.LEARNING_SESSION.learningParameters.sessionBaseAsset === undefined) {
let errorMessage = "Session Parameters Node with no Session Base Asset."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters, errorMessage)
return false
}
if (bot.LEARNING_SESSION.parameters.sessionBaseAsset.config.initialBalance === undefined) {
if (bot.LEARNING_SESSION.learningParameters.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.LEARNING_SESSION.parameters.sessionBaseAsset, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters.sessionBaseAsset, errorMessage)
return false
}
/* Session Quoted Asset */
if (bot.LEARNING_SESSION.parameters.sessionQuotedAsset === undefined) {
if (bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset === undefined) {
let errorMessage = "Session Parameters Node with no Session Quoted Asset."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.sessionError(bot.LEARNING_SESSION.parameters, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters, errorMessage)
return false
}
if (bot.LEARNING_SESSION.parameters.sessionQuotedAsset.config.initialBalance === undefined) {
if (bot.LEARNING_SESSION.learningParameters.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.LEARNING_SESSION.parameters.sessionQuotedAsset, errorMessage)
bot.sessionError(bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset, errorMessage)
return false
}
/* Slippage */
if (bot.LEARNING_SESSION.parameters.slippage === undefined) { // if the Slippage is missing we create a default one.
bot.LEARNING_SESSION.parameters.slippage = {
if (bot.LEARNING_SESSION.learningParameters.slippage === undefined) { // if the Slippage is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.slippage = {
name: 'Missing Slippage',
type: 'Slippage',
config: {
@@ -332,19 +332,19 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
}
}
}
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.LEARNING_SESSION.learningParameters.slippage.config.marketOrderRate === undefined) { // if the marketOrderRate is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.slippage.config.marketOrderRate = 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.LEARNING_SESSION.learningParameters.slippage.config.stopLoss === undefined) { // if the stopLoss is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.slippage.config.stopLoss = 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
if (bot.LEARNING_SESSION.learningParameters.slippage.config.takeProfit === undefined) { // if the takeProfit is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.slippage.config.takeProfit = 0
}
/* Fee Structure */
if (bot.LEARNING_SESSION.parameters.feeStructure === undefined) { // if the Fee Structure is missing we create a default one.
bot.LEARNING_SESSION.parameters.feeStructure = {
if (bot.LEARNING_SESSION.learningParameters.feeStructure === undefined) { // if the Fee Structure is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.feeStructure = {
name: 'Missing Fee Structure',
type: 'Fee Structure',
config: {
@@ -353,11 +353,11 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
}
}
}
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.LEARNING_SESSION.learningParameters.feeStructure.config.maker === undefined) { // if the maker is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.feeStructure.config.maker = 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
if (bot.LEARNING_SESSION.learningParameters.feeStructure.config.taker === undefined) { // if the taker is missing we create a default one.
bot.LEARNING_SESSION.learningParameters.feeStructure.config.taker = 0
}
return true
@@ -391,16 +391,16 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
balancePercentage = bot.LEARNING_SESSION.config.balancePercentage
}
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.LEARNING_SESSION.learningParameters.sessionBaseAsset.config.initialBalance = bot.LEARNING_SESSION.learningParameters.sessionBaseAsset.config.initialBalance * balancePercentage / 100
bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset.config.initialBalance = bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset.config.initialBalance * 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.LEARNING_SESSION.learningParameters.sessionBaseAsset.config.minimumBalance = bot.LEARNING_SESSION.learningParameters.sessionBaseAsset.config.minimumBalance * balancePercentage / 100
bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset.config.minimumBalance = bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset.config.minimumBalance * 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
bot.LEARNING_SESSION.learningParameters.sessionBaseAsset.config.maximumBalance = bot.LEARNING_SESSION.learningParameters.sessionBaseAsset.config.maximumBalance * balancePercentage / 100
bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset.config.maximumBalance = bot.LEARNING_SESSION.learningParameters.sessionQuotedAsset.config.maximumBalance * balancePercentage / 100
pProcessConfig.normalWaitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
pProcessConfig.normalWaitTime = bot.LEARNING_SESSION.learningParameters.timeFrame.config.value
return true
}
@@ -23,7 +23,7 @@ exports.newOrdersCalculations = function newOrdersCalculations(bot, logger) {
return thisObject
function initialize() {
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
tradingEngine = bot.simulationState.tradingEngine
tradingSystem = bot.simulationState.tradingSystem
}
@@ -23,7 +23,7 @@ exports.newOrdersSimulations = function newOrdersSimulations(bot, logger) {
return thisObject
function initialize() {
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
tradingEngine = bot.simulationState.tradingEngine
tradingSystem = bot.simulationState.tradingSystem
}
+1 -1
View File
@@ -45,7 +45,7 @@ exports.newSnapshots = function newSnapshots(bot, logger) {
function initialize() {
tradingEngine = bot.simulationState.tradingEngine
tradingSystem = bot.simulationState.tradingSystem
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
}
function finalize() {
@@ -25,7 +25,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
function initialize() {
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
initializeNodeMap(tradingEngine)
@@ -23,7 +23,7 @@ exports.newTradingEpisode = function newTradingEpisode(bot, logger, tradingEngin
function initialize() {
tradingSystem = bot.simulationState.tradingSystem
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
}
function finalize() {
@@ -24,7 +24,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE
function initialize() {
tradingSystem = bot.simulationState.tradingSystem
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
tradingOrdersModule.initialize()
}
@@ -27,7 +27,7 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM
function initialize() {
tradingSystem = bot.simulationState.tradingSystem
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
exchangeAPIModule.initialize()
announcementsModule.initialize()
@@ -31,7 +31,7 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng
function initialize() {
tradingSystem = bot.simulationState.tradingSystem
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
}
function finalize() {
@@ -103,7 +103,7 @@
This variable tell us which day we are standing at, specially while working
with Daily Files. From this Date is that we are going to load the Daily Files.
*/
bot.simulationState.tradingEngine.current.episode.processDate.value = global.REMOVE_TIME(bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime).valueOf()
bot.simulationState.tradingEngine.current.episode.processDate.value = global.REMOVE_TIME(bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime).valueOf()
}
/*
@@ -219,7 +219,7 @@
callBackFunction(global.DEFAULT_OK_RESPONSE)
function checkThereAreCandles(chart) {
let sessionParameters = bot.TRADING_SESSION.parameters
let sessionParameters = bot.TRADING_SESSION.tradingParameters
let propertyName = 'at' + sessionParameters.timeFrame.config.label.replace('-', '')
let candles = chart[propertyName].candles
@@ -236,7 +236,7 @@
let statusReport;
/* We are going to use the start date as beging of market date. */
contextVariables.dateBeginOfMarket = global.REMOVE_TIME(bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime)
contextVariables.dateBeginOfMarket = global.REMOVE_TIME(bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime)
/*
Here we get the status report from the bot who knows which is the end of the market.
*/
@@ -371,7 +371,7 @@
dataFiles = new Map();
if (bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel) {
if (bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel) {
currentTimeFrame = global.marketFilesPeriods[n][0];
currentTimeFrameLabel = global.marketFilesPeriods[n][1];
}
@@ -384,7 +384,7 @@
}
if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
if (!(bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
if (!(bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
continue
}
}
@@ -431,8 +431,8 @@
let dataRecord = dataFile[i]
let begin = dataRecord[beginIndex]
let end = dataRecord[endIndex]
if (end + timeFrame < bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime - 1) { continue } // /1 because we need the previous closed element
if (begin > bot.TRADING_SESSION.parameters.timeRange.config.finalDatetime) { continue }
if (end + timeFrame < bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime - 1) { continue } // /1 because we need the previous closed element
if (begin > bot.TRADING_SESSION.tradingParameters.timeRange.config.finalDatetime) { continue }
result.push(dataRecord)
}
return result
@@ -468,7 +468,7 @@
}
}
if (bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel) {
if (bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel) {
currentTimeFrame = global.dailyFilePeriods[n][0];
currentTimeFrameLabel = global.dailyFilePeriods[n][1];
}
@@ -488,7 +488,7 @@
}
if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
if (!(bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
if (!(bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
continue
}
}
@@ -20,7 +20,7 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
function initialize(pOutputDatasetsMap) {
tradingEngine = bot.simulationState.tradingEngine
tradingSystem = bot.simulationState.tradingSystem
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
outputDatasetsMap = pOutputDatasetsMap // These are the files turned into arrays, stored in a Map by Product codeName.
}
@@ -28,7 +28,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin
let tradingSystem = bot.simulationState.tradingSystem
let tradingEngine = bot.simulationState.tradingEngine
let sessionParameters = bot.TRADING_SESSION.parameters
let sessionParameters = bot.TRADING_SESSION.tradingParameters
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> initialDatetime = ' + sessionParameters.timeRange.config.initialDatetime) }
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> finalDatetime = ' + sessionParameters.timeRange.config.finalDatetime) }
@@ -47,7 +47,7 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM
function initialize() {
tradingSystem = bot.simulationState.tradingSystem
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
tradingStrategyModule.initialize()
tradingPositionModule.initialize()
@@ -19,7 +19,7 @@ exports.newTradingStrategy = function newTradingStrategy(bot, logger, tradingEng
function initialize() {
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
}
function finalize() {
@@ -28,7 +28,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
function initialize() {
tradingSystem = bot.simulationState.tradingSystem
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.TRADING_SESSION.parameters
sessionParameters = bot.TRADING_SESSION.tradingParameters
tradingSystem.conditions = new Map()
tradingSystem.formulas = new Map()
@@ -562,15 +562,15 @@ exports.newLearningBot = function newLearningBot(bot, parentLogger) {
} else {
switch (bot.LEARNING_SESSION.type) {
case 'Live Trading Session': {
waitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
waitTime = bot.LEARNING_SESSION.learningParameters.timeFrame.config.value
break
}
case 'Fordward Tessting Session': {
waitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
waitTime = bot.LEARNING_SESSION.learningParameters.timeFrame.config.value
break
}
case 'Paper Trading Session': {
waitTime = bot.LEARNING_SESSION.parameters.timeFrame.config.value
waitTime = bot.LEARNING_SESSION.learningParameters.timeFrame.config.value
break
}
case 'Backtesting Session': {
@@ -103,7 +103,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
This variable tell us which day we are standing at, specially while working
with Daily Files. From this Date is that we are going to load the Daily Files.
*/
bot.simulationState.tradingEngine.current.episode.processDate.value = global.REMOVE_TIME(bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime).valueOf()
bot.simulationState.tradingEngine.current.episode.processDate.value = global.REMOVE_TIME(bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime).valueOf()
}
/*
@@ -219,7 +219,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
callBackFunction(global.DEFAULT_OK_RESPONSE)
function checkThereAreCandles(chart) {
let sessionParameters = bot.TRADING_SESSION.parameters
let sessionParameters = bot.TRADING_SESSION.tradingParameters
let propertyName = 'at' + sessionParameters.timeFrame.config.label.replace('-', '')
let candles = chart[propertyName].candles
@@ -236,7 +236,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
let statusReport;
/* We are going to use the start date as beging of market date. */
contextVariables.dateBeginOfMarket = global.REMOVE_TIME(bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime)
contextVariables.dateBeginOfMarket = global.REMOVE_TIME(bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime)
/*
Here we get the status report from the bot who knows which is the end of the market.
*/
@@ -371,7 +371,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
dataFiles = new Map();
if (bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel) {
if (bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel) {
currentTimeFrame = global.marketFilesPeriods[n][0];
currentTimeFrameLabel = global.marketFilesPeriods[n][1];
}
@@ -384,7 +384,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
}
if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
if (!(bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
if (!(bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
continue
}
}
@@ -431,8 +431,8 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
let dataRecord = dataFile[i]
let begin = dataRecord[beginIndex]
let end = dataRecord[endIndex]
if (end + timeFrame < bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime - 1) { continue } // /1 because we need the previous closed element
if (begin > bot.TRADING_SESSION.parameters.timeRange.config.finalDatetime) { continue }
if (end + timeFrame < bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime - 1) { continue } // /1 because we need the previous closed element
if (begin > bot.TRADING_SESSION.tradingParameters.timeRange.config.finalDatetime) { continue }
result.push(dataRecord)
}
return result
@@ -468,7 +468,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
}
}
if (bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel) {
if (bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel) {
currentTimeFrame = global.dailyFilePeriods[n][0];
currentTimeFrameLabel = global.dailyFilePeriods[n][1];
}
@@ -488,7 +488,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
}
if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.config.singularVariableName) !== true) {
if (!(bot.TRADING_SESSION.parameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
if (!(bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === timeFrameLabel && datasetModule.node.parentNode.config.pluralVariableName === 'candles')) {
continue
}
}
@@ -25,7 +25,7 @@ exports.newMarkovDecisionProcess = function newMarkovDecisionProcess(bot, logger
function initialize() {
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.LEARNING_SESSION.parameters
sessionParameters = bot.LEARNING_SESSION.learningParameters
initializeNodeMap(tradingEngine)
+3 -3
View File
@@ -562,15 +562,15 @@
} else {
switch (bot.TRADING_SESSION.type) {
case 'Live Trading Session': {
waitTime = bot.TRADING_SESSION.parameters.timeFrame.config.value
waitTime = bot.TRADING_SESSION.tradingParameters.timeFrame.config.value
break
}
case 'Fordward Tessting Session': {
waitTime = bot.TRADING_SESSION.parameters.timeFrame.config.value
waitTime = bot.TRADING_SESSION.tradingParameters.timeFrame.config.value
break
}
case 'Paper Trading Session': {
waitTime = bot.TRADING_SESSION.parameters.timeFrame.config.value
waitTime = bot.TRADING_SESSION.tradingParameters.timeFrame.config.value
break
}
case 'Backtesting Session': {
+52 -52
View File
@@ -183,7 +183,7 @@
non critical is missing, we complete it with a default value.
*/
if (bot.TRADING_SESSION.parameters === undefined) {
if (bot.TRADING_SESSION.tradingParameters === undefined) {
let errorMessage = "Session Node with no Parameters."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION, errorMessage)
@@ -191,8 +191,8 @@
}
/* Time Range */
if (bot.TRADING_SESSION.parameters.timeRange === undefined) { // if the Time Range is missing we create a default one.
bot.TRADING_SESSION.parameters.timeRange = {
if (bot.TRADING_SESSION.tradingParameters.timeRange === undefined) { // if the Time Range is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.timeRange = {
name: 'Missing Time Range',
type: 'Time Range',
config: {
@@ -203,17 +203,17 @@
} else {
/* Check that we received valid dates */
if (bot.TRADING_SESSION.type === 'Backtesting Session') {
if (isNaN(new Date(bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()) {
if (isNaN(new Date(bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime)).valueOf()) {
let errorMessage = "sessionParameters.timeRange.config.initialDatetime is not a valid date."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters, errorMessage)
return false
}
}
if (isNaN(new Date(bot.TRADING_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()) {
if (isNaN(new Date(bot.TRADING_SESSION.tradingParameters.timeRange.config.finalDatetime)).valueOf()) {
let errorMessage = "sessionParameters.timeRange.config.initialDatetime is not a valid date."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters, errorMessage)
return false
}
}
@@ -249,80 +249,80 @@
/* Initial Datetime */
if (bot.TRADING_SESSION.type === 'Backtesting Session') {
if (bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime === undefined) {
bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime = initialDefault
if (bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime === undefined) {
bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime = initialDefault
} else {
bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime = (new Date(bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime)).valueOf()
}
} else {
/* Non backtest session can start from the past only if explicitly configured that way */
if (bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime === undefined || bot.TRADING_SESSION.parameters.timeRange.config.allowStartingFromThePast !== true) {
bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime = initialDefault
if (bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime === undefined || bot.TRADING_SESSION.tradingParameters.timeRange.config.allowStartingFromThePast !== true) {
bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime = initialDefault
} else {
bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.TRADING_SESSION.parameters.timeRange.config.initialDatetime)).valueOf()
bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime = (new Date(bot.TRADING_SESSION.tradingParameters.timeRange.config.initialDatetime)).valueOf()
}
}
/* Final Datetime */
if (bot.TRADING_SESSION.parameters.timeRange.config.finalDatetime === undefined) {
bot.TRADING_SESSION.parameters.timeRange.config.finalDatetime = finalDefault
if (bot.TRADING_SESSION.tradingParameters.timeRange.config.finalDatetime === undefined) {
bot.TRADING_SESSION.tradingParameters.timeRange.config.finalDatetime = finalDefault
} else {
bot.TRADING_SESSION.parameters.timeRange.config.finalDatetime = (new Date(bot.TRADING_SESSION.parameters.timeRange.config.finalDatetime)).valueOf()
bot.TRADING_SESSION.tradingParameters.timeRange.config.finalDatetime = (new Date(bot.TRADING_SESSION.tradingParameters.timeRange.config.finalDatetime)).valueOf()
}
}
/* Time Frame */
if (bot.TRADING_SESSION.parameters.timeFrame === undefined) {
if (bot.TRADING_SESSION.tradingParameters.timeFrame === undefined) {
let errorMessage = "Session Parameters Node with no Time Frame."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters, errorMessage)
return false
}
if (bot.TRADING_SESSION.parameters.timeFrame.config.label === undefined) {
if (bot.TRADING_SESSION.tradingParameters.timeFrame.config.label === undefined) {
let errorMessage = "Session Parameters Node with no Time Frame Label configuration."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters.timeFrame, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters.timeFrame, errorMessage)
return false
}
bot.TRADING_SESSION.parameters.timeFrame.config.value = getTimeFrameFromLabel(bot.TRADING_SESSION.parameters.timeFrame.config.label)
if (bot.TRADING_SESSION.parameters.timeFrame.config.value === undefined) {
bot.TRADING_SESSION.tradingParameters.timeFrame.config.value = getTimeFrameFromLabel(bot.TRADING_SESSION.tradingParameters.timeFrame.config.label)
if (bot.TRADING_SESSION.tradingParameters.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.TRADING_SESSIONError(bot.TRADING_SESSION.parameters.timeFrame, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters.timeFrame, errorMessage)
return false
}
/* Session Base Asset */
if (bot.TRADING_SESSION.parameters.sessionBaseAsset === undefined) {
if (bot.TRADING_SESSION.tradingParameters.sessionBaseAsset === undefined) {
let errorMessage = "Session Parameters Node with no Session Base Asset."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters, errorMessage)
return false
}
if (bot.TRADING_SESSION.parameters.sessionBaseAsset.config.initialBalance === undefined) {
if (bot.TRADING_SESSION.tradingParameters.sessionBaseAsset.config.initialBalance === undefined) {
let errorMessage = "Session Parameters Session Base Asset with no initialBalance configuration."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters.sessionBaseAsset, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters.sessionBaseAsset, errorMessage)
return false
}
/* Session Quoted Asset */
if (bot.TRADING_SESSION.parameters.sessionQuotedAsset === undefined) {
if (bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset === undefined) {
let errorMessage = "Session Parameters Node with no Session Quoted Asset."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters, errorMessage)
return false
}
if (bot.TRADING_SESSION.parameters.sessionQuotedAsset.config.initialBalance === undefined) {
if (bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset.config.initialBalance === undefined) {
let errorMessage = "Session Parameters Session Quoted Asset with no initialBalance configuration."
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.parameters.sessionQuotedAsset, errorMessage)
bot.TRADING_SESSIONError(bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset, errorMessage)
return false
}
/* Slippage */
if (bot.TRADING_SESSION.parameters.slippage === undefined) { // if the Slippage is missing we create a default one.
bot.TRADING_SESSION.parameters.slippage = {
if (bot.TRADING_SESSION.tradingParameters.slippage === undefined) { // if the Slippage is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.slippage = {
name: 'Missing Slippage',
type: 'Slippage',
config: {
@@ -332,19 +332,19 @@
}
}
}
if (bot.TRADING_SESSION.parameters.slippage.config.marketOrderRate === undefined) { // if the marketOrderRate is missing we create a default one.
bot.TRADING_SESSION.parameters.slippage.config.marketOrderRate = 0
if (bot.TRADING_SESSION.tradingParameters.slippage.config.marketOrderRate === undefined) { // if the marketOrderRate is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.slippage.config.marketOrderRate = 0
}
if (bot.TRADING_SESSION.parameters.slippage.config.stopLoss === undefined) { // if the stopLoss is missing we create a default one.
bot.TRADING_SESSION.parameters.slippage.config.stopLoss = 0
if (bot.TRADING_SESSION.tradingParameters.slippage.config.stopLoss === undefined) { // if the stopLoss is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.slippage.config.stopLoss = 0
}
if (bot.TRADING_SESSION.parameters.slippage.config.takeProfit === undefined) { // if the takeProfit is missing we create a default one.
bot.TRADING_SESSION.parameters.slippage.config.takeProfit = 0
if (bot.TRADING_SESSION.tradingParameters.slippage.config.takeProfit === undefined) { // if the takeProfit is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.slippage.config.takeProfit = 0
}
/* Fee Structure */
if (bot.TRADING_SESSION.parameters.feeStructure === undefined) { // if the Fee Structure is missing we create a default one.
bot.TRADING_SESSION.parameters.feeStructure = {
if (bot.TRADING_SESSION.tradingParameters.feeStructure === undefined) { // if the Fee Structure is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.feeStructure = {
name: 'Missing Fee Structure',
type: 'Fee Structure',
config: {
@@ -353,11 +353,11 @@
}
}
}
if (bot.TRADING_SESSION.parameters.feeStructure.config.maker === undefined) { // if the maker is missing we create a default one.
bot.TRADING_SESSION.parameters.feeStructure.config.maker = 0
if (bot.TRADING_SESSION.tradingParameters.feeStructure.config.maker === undefined) { // if the maker is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.feeStructure.config.maker = 0
}
if (bot.TRADING_SESSION.parameters.feeStructure.config.taker === undefined) { // if the taker is missing we create a default one.
bot.TRADING_SESSION.parameters.feeStructure.config.taker = 0
if (bot.TRADING_SESSION.tradingParameters.feeStructure.config.taker === undefined) { // if the taker is missing we create a default one.
bot.TRADING_SESSION.tradingParameters.feeStructure.config.taker = 0
}
return true
@@ -391,16 +391,16 @@
balancePercentage = bot.TRADING_SESSION.config.balancePercentage
}
bot.TRADING_SESSION.parameters.sessionBaseAsset.config.initialBalance = bot.TRADING_SESSION.parameters.sessionBaseAsset.config.initialBalance * balancePercentage / 100
bot.TRADING_SESSION.parameters.sessionQuotedAsset.config.initialBalance = bot.TRADING_SESSION.parameters.sessionQuotedAsset.config.initialBalance * balancePercentage / 100
bot.TRADING_SESSION.tradingParameters.sessionBaseAsset.config.initialBalance = bot.TRADING_SESSION.tradingParameters.sessionBaseAsset.config.initialBalance * balancePercentage / 100
bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset.config.initialBalance = bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset.config.initialBalance * balancePercentage / 100
bot.TRADING_SESSION.parameters.sessionBaseAsset.config.minimumBalance = bot.TRADING_SESSION.parameters.sessionBaseAsset.config.minimumBalance * balancePercentage / 100
bot.TRADING_SESSION.parameters.sessionQuotedAsset.config.minimumBalance = bot.TRADING_SESSION.parameters.sessionQuotedAsset.config.minimumBalance * balancePercentage / 100
bot.TRADING_SESSION.tradingParameters.sessionBaseAsset.config.minimumBalance = bot.TRADING_SESSION.tradingParameters.sessionBaseAsset.config.minimumBalance * balancePercentage / 100
bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset.config.minimumBalance = bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset.config.minimumBalance * balancePercentage / 100
bot.TRADING_SESSION.parameters.sessionBaseAsset.config.maximumBalance = bot.TRADING_SESSION.parameters.sessionBaseAsset.config.maximumBalance * balancePercentage / 100
bot.TRADING_SESSION.parameters.sessionQuotedAsset.config.maximumBalance = bot.TRADING_SESSION.parameters.sessionQuotedAsset.config.maximumBalance * balancePercentage / 100
bot.TRADING_SESSION.tradingParameters.sessionBaseAsset.config.maximumBalance = bot.TRADING_SESSION.tradingParameters.sessionBaseAsset.config.maximumBalance * balancePercentage / 100
bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset.config.maximumBalance = bot.TRADING_SESSION.tradingParameters.sessionQuotedAsset.config.maximumBalance * balancePercentage / 100
pProcessConfig.normalWaitTime = bot.TRADING_SESSION.parameters.timeFrame.config.value
pProcessConfig.normalWaitTime = bot.TRADING_SESSION.tradingParameters.timeFrame.config.value
return true
}