pollishiing code
This commit is contained in:
1 parent
d36c6e7b7f
commit
83ffc6b24b
5 files changed
+20
-23
No files matched your search
@@ -5,7 +5,7 @@ exports.newTradingEpisode = function newTradingEpisode(bot, logger) {
|
||||
const MODULE_NAME = 'Trading Episode'
|
||||
let thisObject = {
|
||||
openEpisode: openEpisode,
|
||||
closingEpisode: closingEpisode,
|
||||
updateExitType: updateExitType,
|
||||
closeEpisode: closeEpisode,
|
||||
updateEnds: updateEnds,
|
||||
resetTradingEngineDataStructure: resetTradingEngineDataStructure,
|
||||
@@ -45,8 +45,7 @@ exports.newTradingEpisode = function newTradingEpisode(bot, logger) {
|
||||
tradingEngine.current.episode.beginRate.value = tradingEngine.current.candle.close.value
|
||||
}
|
||||
|
||||
function closingEpisode(exitType) {
|
||||
tradingEngine.current.episode.status.value = 'Closing'
|
||||
function updateExitType(exitType) {
|
||||
tradingEngine.current.episode.exitType.value = exitType
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng
|
||||
updateEnds: updateEnds,
|
||||
resetTradingEngineDataStructure: resetTradingEngineDataStructure,
|
||||
updateCounters: updateCounters,
|
||||
resetPosition: resetPosition,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -80,10 +79,6 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng
|
||||
tradingEngineModule.cloneValues(tradingEngine.current.position, tradingEngine.last.position)
|
||||
}
|
||||
|
||||
function resetPosition() {
|
||||
tradingEngine.current.position.initialize(tradingEngine.current.position)
|
||||
}
|
||||
|
||||
function applyStopLossFormula(formulas, formulaId) {
|
||||
tradingEngine.current.position.stopLoss.value = formulas.get(formulaId)
|
||||
}
|
||||
@@ -230,7 +225,7 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng
|
||||
|
||||
function resetTradingEngineDataStructure() {
|
||||
if (tradingEngine.current.position.status.value === 'Closed') {
|
||||
resetPosition()
|
||||
tradingEngine.current.position.initialize(tradingEngine.current.position)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -157,14 +157,14 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
if (bot.STOP_SESSION === true) {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> controlLoop -> We are going to stop here bacause we were requested to stop processing this session.') }
|
||||
console.log('[INFO] runSimulation -> controlLoop -> We are going to stop here bacause we were requested to stop processing this session.')
|
||||
closeEpisode('Session Stopped')
|
||||
updateEpisode('Session Stopped')
|
||||
return
|
||||
}
|
||||
|
||||
if (global.STOP_TASK_GRACEFULLY === true) {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> controlLoop -> We are going to stop here bacause we were requested to stop processing this task.') }
|
||||
console.log('[INFO] runSimulation -> controlLoop -> We are going to stop here bacause we were requested to stop processing this task.')
|
||||
closeEpisode('Task Stopped')
|
||||
updateEpisode('Task Stopped')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
}
|
||||
|
||||
function closeEpisode(exitType) {
|
||||
tradingEpisodeModule.closingEpisode(exitType)
|
||||
tradingEpisodeModule.updateExitType(exitType)
|
||||
tradingEpisodeModule.closeEpisode()
|
||||
|
||||
/* Add new records to the process output */
|
||||
@@ -191,6 +191,15 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
afterLoop()
|
||||
}
|
||||
|
||||
function updateEpisode(exitType) {
|
||||
tradingEpisodeModule.updateExitType(exitType)
|
||||
|
||||
/* Add new records to the process output */
|
||||
tradingRecordsModule.appendRecords()
|
||||
|
||||
afterLoop()
|
||||
}
|
||||
|
||||
function afterLoop() {
|
||||
|
||||
tradingEngineModule.finalize()
|
||||
|
||||
@@ -14,7 +14,6 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM
|
||||
resetTradingEngineDataStructure: resetTradingEngineDataStructure,
|
||||
updateCounters: updateCounters,
|
||||
updateStatistics: updateStatistics,
|
||||
resetStage: resetStage,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -1101,10 +1100,6 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM
|
||||
}
|
||||
}
|
||||
|
||||
function resetStage(stage) {
|
||||
stage.initialize(stage)
|
||||
}
|
||||
|
||||
function updateEnds() {
|
||||
if (tradingEngine.current.strategyTriggerStage.status.value === 'Open') {
|
||||
tradingEngine.current.strategyTriggerStage.end.value = tradingEngine.current.candle.end.value
|
||||
@@ -1136,6 +1131,10 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM
|
||||
resetStage(tradingEngine.current.strategyManageStage)
|
||||
resetStage(tradingEngine.current.strategyCloseStage)
|
||||
}
|
||||
|
||||
function resetStage(stage) {
|
||||
stage.initialize(stage)
|
||||
}
|
||||
}
|
||||
|
||||
function updateCounters() {
|
||||
|
||||
@@ -9,7 +9,6 @@ exports.newTradingStrategy = function newTradingStrategy(bot, logger, tradingEng
|
||||
updateEnds: updateEnds,
|
||||
resetTradingEngineDataStructure: resetTradingEngineDataStructure,
|
||||
updateCounters: updateCounters,
|
||||
resetStrategy: resetStrategy,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -53,10 +52,6 @@ exports.newTradingStrategy = function newTradingStrategy(bot, logger, tradingEng
|
||||
tradingEngineModule.cloneValues(tradingEngine.current.strategy, tradingEngine.last.strategy)
|
||||
}
|
||||
|
||||
function resetStrategy() {
|
||||
tradingEngine.current.strategy.initialize(tradingEngine.current.strategy)
|
||||
}
|
||||
|
||||
function updateEnds() {
|
||||
if (tradingEngine.current.strategy.status.value === 'Open') {
|
||||
tradingEngine.current.strategy.end.value = tradingEngine.current.candle.end.value
|
||||
@@ -66,7 +61,7 @@ exports.newTradingStrategy = function newTradingStrategy(bot, logger, tradingEng
|
||||
|
||||
function resetTradingEngineDataStructure() {
|
||||
if (tradingEngine.current.strategy.status.value === 'Closed') {
|
||||
resetStrategy()
|
||||
tradingEngine.current.strategy.initialize(tradingEngine.current.strategy)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user