diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 733940c64..30328e9e5 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -603,6 +603,13 @@ "functionName": "newSuperalgosBotModulesTradingSystem", "fileName": "TradingSystem.js", "folderName": "Trading-Bot/Low-Frequency-Trading" + }, + { + "name": "Trading Stages", + "propertyName": "tradingStages", + "functionName": "newSuperalgosBotModulesTradingStages", + "fileName": "TradingStages.js", + "folderName": "Trading-Bot/Low-Frequency-Trading" } ] }, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js index b9146d585..a56f10dd6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js @@ -1,4 +1,4 @@ -exports.newSuperalgosBotModulesTradingEpisode = function (processIndex, tradingEngineModule) { +exports.newSuperalgosBotModulesTradingEpisode = function (processIndex, tradingEngineModuleObject) { /* This module packages all functions related to Episodes. */ @@ -83,7 +83,7 @@ exports.newSuperalgosBotModulesTradingEpisode = function (processIndex, tradingE } function resetEpisode() { - tradingEngineModule.initializeNode(tradingEngine.current.episode) + tradingEngineModuleObject.initializeNode(tradingEngine.current.episode) } function updateEnds() { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js index 0612f4d61..151506cd8 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js @@ -1,4 +1,4 @@ -exports.newSuperalgosBotModulesTradingOutput = function (processIndex, tradingEngineModule) { +exports.newSuperalgosBotModulesTradingOutput = function (processIndex, tradingEngineModuleObject) { /* This module will load if necesary all the data outputs so that they can be appended with new records if needed. After running the simulation, it will save all the data outputs. @@ -37,7 +37,7 @@ exports.newSuperalgosBotModulesTradingOutput = function (processIndex, tradingEn } /* Preparing everything for the Simulation */ - let tradingSimulationModuleObject = TS.projects.superalgos.botModules.tradingSimulation.newSuperalgosBotModulesTradingSimulation(processIndex, tradingEngineModule) + let tradingSimulationModuleObject = TS.projects.superalgos.botModules.tradingSimulation.newSuperalgosBotModulesTradingSimulation(processIndex, tradingEngineModuleObject) let outputDatasets = TS.projects.superalgos.utilities.nodeFunctions.nodeBranchToArray(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.processOutput, 'Output Dataset') let outputDatasetsMap = new Map() diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js index c4badc758..b02ba800d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js @@ -1,4 +1,4 @@ -exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradingEngineModule) { +exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradingEngineModuleObject) { /* This Module represents the trading simulacion. Escentially a loop through a set of candles and the execution at each loop cycle of the Trading System Protocol. @@ -37,10 +37,10 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradi let tradingRecordsModuleObject = TS.projects.superalgos.botModules.tradingRecords.newSuperalgosBotModulesTradingRecords(processIndex) tradingRecordsModuleObject.initialize(outputDatasetsMap) - let tradingSystemModuleObject = TS.projects.superalgos.botModules.tradingSystem.newSuperalgosBotModulesTradingSystem(processIndex, tradingEngineModule) + let tradingSystemModuleObject = TS.projects.superalgos.botModules.tradingSystem.newSuperalgosBotModulesTradingSystem(processIndex, tradingEngineModuleObject) tradingSystemModuleObject.initialize() - let tradingEpisodeModuleObject = TS.projects.superalgos.botModules.tradingEpisode.newSuperalgosBotModulesTradingEpisode(processIndex, tradingEngineModule) + let tradingEpisodeModuleObject = TS.projects.superalgos.botModules.tradingEpisode.newSuperalgosBotModulesTradingEpisode(processIndex, tradingEngineModuleObject) tradingEpisodeModuleObject.initialize() /* Setting up the candles array: The whole simulation is based on the array of candles at the time-frame defined at the session parameters. */ @@ -108,7 +108,7 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradi if (FULL_LOG === true) { TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE.write(MODULE_NAME, '[INFO] runSimulation -> loop -> Candle Begin @ ' + (new Date(candle.begin)).toLocaleString()) } if (FULL_LOG === true) { TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE.write(MODULE_NAME, '[INFO] runSimulation -> loop -> Candle End @ ' + (new Date(candle.end)).toLocaleString()) } - tradingEngineModule.setCurrentCandle(candle) // We move the current candle we are standing at, to the trading engine data structure to make it available to anyone, including conditions and formulas. + tradingEngineModuleObject.setCurrentCandle(candle) // We move the current candle we are standing at, to the trading engine data structure to make it available to anyone, including conditions and formulas. /* We emit a heart beat so that the UI can now where we are at the overal process.*/ heartBeat() @@ -133,7 +133,7 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradi */ tradingSystemModuleObject.mantain() tradingEpisodeModuleObject.mantain() - tradingEngineModule.mantain() + tradingEngineModuleObject.mantain() /* Run the first cycle of the Trading System. In this first cycle we @@ -142,7 +142,7 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradi orders can not be created, since otherwise the could be cancelled at the second cycle without spending real time at the order book. */ - tradingEngineModule.setCurrentCycle('First') + tradingEngineModuleObject.setCurrentCycle('First') await runCycle() /* @@ -166,7 +166,7 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradi without the need to wait until the next candle. Orders can not be cancelled during the second cycle. */ - tradingEngineModule.setCurrentCycle('Second') + tradingEngineModuleObject.setCurrentCycle('Second') await runCycle() checkIfWeNeedToStopAfterBothCycles() @@ -180,7 +180,7 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex, tradi /* Reset Data Structures */ tradingSystemModuleObject.reset() tradingEpisodeModuleObject.reset() - tradingEngineModule.reset() + tradingEngineModuleObject.reset() let infoMessage = 'Processing candle # ' + tradingEngine.current.episode.candle.index.value + ' @ the ' + tradingEngine.current.episode.cycle.value + ' cycle.' if (FULL_LOG === true) { TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE.write(MODULE_NAME, '[INFO] runSimulation -> loop -> ' + infoMessage) } diff --git a/TaskServer/LowFrequencyTrading/TradingStages.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js similarity index 99% rename from TaskServer/LowFrequencyTrading/TradingStages.js rename to Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js index a34722eea..bbcd22215 100644 --- a/TaskServer/LowFrequencyTrading/TradingStages.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js @@ -1,4 +1,4 @@ -exports.newTradingStages = function (processIndex, tradingEngineModule) { +exports.newSuperalgosBotModulesTradingStages = function (processIndex, tradingEngineModuleObject) { /* This module packages all functions related to Stages. */ @@ -21,13 +21,13 @@ exports.newTradingStages = function (processIndex, tradingEngineModule) { } const TRADING_STRATEGY_MODULE = require('./TradingStrategy.js') - let tradingStrategyModule = TRADING_STRATEGY_MODULE.newTradingStrategy(processIndex, tradingEngineModule) + let tradingStrategyModule = TRADING_STRATEGY_MODULE.newTradingStrategy(processIndex, tradingEngineModuleObject) const TRADING_POSITION_MODULE = require('./TradingPosition.js') - let tradingPositionModule = TRADING_POSITION_MODULE.newTradingPosition(processIndex, tradingEngineModule) + let tradingPositionModule = TRADING_POSITION_MODULE.newTradingPosition(processIndex, tradingEngineModuleObject) const TRADING_ENGINE_EXECUTION = require('./TradingExecution.js') - let tradingExecutionModule = TRADING_ENGINE_EXECUTION.newTradingExecution(processIndex, tradingEngineModule) + let tradingExecutionModule = TRADING_ENGINE_EXECUTION.newTradingExecution(processIndex, tradingEngineModuleObject) const ANNOUNCEMENTS_MODULE = require('./Announcements.js') let announcementsModule = ANNOUNCEMENTS_MODULE.newAnnouncements(processIndex) @@ -291,7 +291,7 @@ exports.newTradingStages = function (processIndex, tradingEngineModule) { let tradingEngineStage = tradingEngine.current.strategyOpenStage /* Reset the Exchange Orders data structure to its initial value */ - tradingEngineModule.initializeNode(tradingEngine.exchangeOrders) + tradingEngineModuleObject.initializeNode(tradingEngine.exchangeOrders) /* Entry Position size and rate */ tradingSystem.evalFormulas(tradingSystemStage, 'Initial Targets') @@ -1071,7 +1071,7 @@ exports.newTradingStages = function (processIndex, tradingEngineModule) { } function resetStage(stage) { - tradingEngineModule.initializeNode(stage) + tradingEngineModuleObject.initializeNode(stage) } } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js index f5a09d071..ac8af85a3 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js @@ -1,4 +1,4 @@ -exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEngineModule) { +exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEngineModuleObject) { /* The Trading System is the user defined set of rules compliant with the Trading Protocol that defines the trading logic to be applied during each cycle of the Simulation. @@ -19,9 +19,7 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEn let sessionParameters let dynamicIndicators - const TRADING_STAGES_MODULE = require('./TradingStages.js') - let tradingStagesModule = TRADING_STAGES_MODULE.newTradingStages(processIndex, tradingEngineModule) - + let tradingStagesModuleObject = TS.projects.superalgos.botModules.tradingStages.newSuperalgosBotModulesTradingStages(processIndex, tradingEngineModuleObject) return thisObject @@ -33,7 +31,7 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEn tradingSystem.conditions = new Map() tradingSystem.formulas = new Map() - tradingStagesModule.initialize() + tradingStagesModuleObject.initialize() /* Adding Functions used elsewhere to Trading System Definition */ tradingSystem.checkConditions = function (situation, passed) { @@ -78,8 +76,8 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEn } function finalize() { - tradingStagesModule.finalize() - tradingStagesModule = undefined + tradingStagesModuleObject.finalize() + tradingStagesModuleObject = undefined chart = undefined @@ -101,11 +99,11 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEn } function mantain() { - tradingStagesModule.mantain() + tradingStagesModuleObject.mantain() } function reset() { - tradingStagesModule.reset() + tradingStagesModuleObject.reset() tradingSystem.highlights = [] tradingSystem.errors = [] @@ -120,7 +118,7 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEn function updateChart(pChart) { chart = pChart // We need chat to be a local object accessible from conditions and formulas. - tradingStagesModule.updateChart(pChart) + tradingStagesModuleObject.updateChart(pChart) } function buildDynamicIndicators() { @@ -144,18 +142,18 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex, tradingEn buildDynamicIndicators() /* Run the Trigger Stage */ - tradingStagesModule.runTriggerStage() + tradingStagesModuleObject.runTriggerStage() /* Run the Open Stage */ - await tradingStagesModule.runOpenStage() + await tradingStagesModuleObject.runOpenStage() /* Run the Manage Stage */ - tradingStagesModule.runManageStage() + tradingStagesModuleObject.runManageStage() /* Run the Close Stage */ - await tradingStagesModule.runCloseStage() + await tradingStagesModuleObject.runCloseStage() - tradingStagesModule.cycleBasedStatistics() + tradingStagesModuleObject.cycleBasedStatistics() } catch (err) { /*