Trading Stages Moduule

This commit is contained in:
Luis Fernando Molina committed 2020-08-04 11:32:08 +02:00
1 parent 983bb10567
commit 9fecfc8c87
7 files changed
+1250 -1124

No files matched your search

+3 -4
View File
@@ -5,7 +5,7 @@ exports.newSnapshots = function newSnapshots(bot, logger) {
const MODULE_NAME = 'Snapshots'
let thisObject = {
reset: reset,
updateChart: updateChart,
strategyEntry: strategyEntry,
strategyExit: strategyExit,
positionEntry: positionEntry,
@@ -60,9 +60,8 @@ exports.newSnapshots = function newSnapshots(bot, logger) {
chart = undefined
}
function reset(pChart) {
/* This function helps reset data structures at every cycle of the simulation loop/=. */
chart = pChart // We need chat to be a local object accessible from conditions and formulas.
function updateChart(pChart) {
chart = pChart
}
function strategyEntry() {
+4 -4
View File
@@ -5,7 +5,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE
const MODULE_NAME = 'Trading Execution'
let thisObject = {
checkExecution: checkExecution,
runExecution: runExecution,
initialize: initialize,
finalize: finalize
}
@@ -43,7 +43,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE
announcementsModule = undefined
}
async function checkExecution(
async function runExecution(
executionNode,
stageIsOpening,
stageIsClosing,
@@ -884,10 +884,10 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE
}
} catch (err) {
if (typeof err === 'string' || err instanceof String) {
logger.write(MODULE_NAME, '[ERROR] checkExecution -> err = ' + err)
logger.write(MODULE_NAME, '[ERROR] runExecution -> err = ' + err)
}
if (err.stack !== undefined) {
logger.write(MODULE_NAME, '[ERROR] checkExecution -> err = ' + err.stack)
logger.write(MODULE_NAME, '[ERROR] runExecution -> err = ' + err.stack)
}
}
}
+1
View File
@@ -71,6 +71,7 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng
function closePosition() {
tradingEngine.current.position.status.value = 'Closed'
tradingEngine.current.position.end.value = tradingEngine.current.candle.end.value
tradingEngine.current.position.endRate.value = tradingEngine.current.candle.close.value
/*
Now that the position is closed, it is the right time to move this position from current to last at the Trading Engine data structure.
*/
+8 -23
View File
@@ -33,14 +33,6 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
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) }
/* Stop Loss Management TODO */
const MIN_STOP_LOSS_VALUE = 0.0000000001 // We can not let the stop be zero to avoid division by 0 error or infinity numbers as a result.
const MAX_STOP_LOSS_VALUE = Number.MAX_SAFE_INTEGER
/* Take Profit Management TODO */
const MIN_TAKE_PROFIT_VALUE = 0.0000000001 // We can not let the buy order be zero to avoid division by 0 error or infinity numbers as a result.
const MAX_TAKE_PROFIT_VALUE = Number.MAX_SAFE_INTEGER
/* These are the Modules we will need to run the Simulation */
const TRADING_ENGINE_MODULE = require('./TradingEngine.js')
let tradingEngineModule = TRADING_ENGINE_MODULE.newTradingEngine(bot, logger)
@@ -131,25 +123,18 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
heartBeat()
positionChartAtCurrentCandle()
tradingSystemModule.reset(chart)
tradingSystemModule.mantainPositions()
tradingSystemModule.mantainStrategies()
tradingSystemModule.mantainOrders()
/* The chart was recalculated based on the current candle. */
tradingSystemModule.updateChart(chart)
/* Do the stuff needed previous to the run */
tradingSystemModule.mantain()
tradingEngineModule.updateEpisodeCountersAndStatistics()
tradingEngineModule.updateDistanceToEventsCounters()
/* Run the Trigger Stage */
tradingSystemModule.triggerStage()
/* Run the Open Stage */
await tradingSystemModule.openStage()
/* Run the Manage Stage */
tradingSystemModule.manageStage()
/* Run the Close Stage */
await tradingSystemModule.closeStage()
/* Run one cycle of the Trading System*/
await tradingSystemModule.run()
/* Add new records to the process output */
tradingRecordsModule.appendRecords()
File diff suppressed because it is too large. Load diff
-28
View File
@@ -7,7 +7,6 @@ exports.newTradingStrategy = function newTradingStrategy(bot, logger, tradingEng
openStrategy: openStrategy,
closeStrategy: closeStrategy,
updateEnds: updateEnds,
updateStageStatus: updateStageStatus,
updateStatus: updateStatus,
updateCounters: updateCounters,
resetStrategy: resetStrategy,
@@ -63,33 +62,6 @@ exports.newTradingStrategy = function newTradingStrategy(bot, logger, tradingEng
}
}
function updateStageStatus(stage, status, exitType) {
switch (stage) {
case 'Trigger Stage': {
tradingEngine.current.strategyTriggerStage.status.value = status
break
}
case 'Open Stage': {
tradingEngine.current.strategyOpenStage.status.value = status
if (exitType !== undefined) {
tradingEngine.current.strategyOpenStage.exitType.value = exitType
}
break
}
case 'Manage Stage': {
tradingEngine.current.strategyManageStage.status.value = status
break
}
case 'Close Stage': {
tradingEngine.current.strategyCloseStage.status.value = status
if (exitType !== undefined) {
tradingEngine.current.strategyCloseStage.exitType.value = exitType
}
break
}
}
}
function updateStatus() {
if (tradingEngine.current.strategy.status.value === 'Closed') {
resetStrategy()
File diff suppressed because it is too large. Load diff