Forward testing and paper trading
This commit is contained in:
1 parent
53c396e55c
commit
2311838023
3 files changed
+75
-18
No files matched your search
@@ -160,6 +160,17 @@
|
||||
|
||||
contextVariables.dateEndOfMarket = new Date(thisReport.lastFile.valueOf());
|
||||
|
||||
/* Validation that the data is not up-to-date. */
|
||||
|
||||
if (bot.multiPeriodProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS > contextVariables.dateEndOfMarket.valueOf() && bot.SESSION.type !== "Backtesting Session") {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> " + "Head of the market is @ " + contextVariables.dateEndOfMarket); }
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> You need to UPDATE your datasets in order to run a " + bot.SESSION.type) }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/* Finally we get our own Status Report. */
|
||||
|
||||
|
||||
+63
-17
@@ -36,12 +36,12 @@
|
||||
|
||||
/* Listen to event to start or stop the session. */
|
||||
bot.sessionKey = bot.processNode.session.name + '-' + bot.processNode.session.type + '-' + bot.processNode.session.id
|
||||
|
||||
|
||||
global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Run Session', undefined, undefined, undefined, runSession)
|
||||
global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Stop Session', undefined, undefined, undefined, stopSession)
|
||||
|
||||
function runSession(message) {
|
||||
|
||||
console.log("runSession")
|
||||
/* We are going to run the Definition comming at the event. */
|
||||
bot.DEFINITION = JSON.parse(message.event.definition)
|
||||
bot.SESSION = JSON.parse(message.event.session)
|
||||
@@ -73,6 +73,14 @@
|
||||
startLiveTrading(message)
|
||||
break
|
||||
}
|
||||
case 'Fordward Testing Session': {
|
||||
startFordwardTesting(message)
|
||||
break
|
||||
}
|
||||
case 'Paper Trading Session': {
|
||||
startPaperTrading(message)
|
||||
break
|
||||
}
|
||||
}
|
||||
bot.SESSION_STATUS = 'Idle'
|
||||
bot.STOP_SESSION = false
|
||||
@@ -84,13 +92,65 @@
|
||||
|
||||
function startBackTesting(message) {
|
||||
bot.startMode = "Backtest"
|
||||
if (bot.VALUES_TO_USE.timeRange.finalDatetime.valueOf() > (new Date()).valueOf()) {
|
||||
bot.VALUES_TO_USE.timeRange.finalDatetime = new Date()
|
||||
}
|
||||
bot.resumeExecution = false;
|
||||
bot.hasTheBotJustStarted = true
|
||||
bot.multiPeriodProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime
|
||||
bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf())
|
||||
}
|
||||
|
||||
function startLiveTrading(message) {
|
||||
|
||||
setKeyToUse()
|
||||
|
||||
if (process.env.KEY === undefined || process.env.SECRET === undefined) {
|
||||
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Live mode."); }
|
||||
return
|
||||
}
|
||||
|
||||
bot.startMode = "Live"
|
||||
if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) {
|
||||
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date()
|
||||
}
|
||||
bot.resumeExecution = false;
|
||||
bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf())
|
||||
bot.hasTheBotJustStarted = true
|
||||
|
||||
}
|
||||
|
||||
function startFordwardTesting(message) {
|
||||
|
||||
setKeyToUse()
|
||||
|
||||
if (process.env.KEY === undefined || process.env.SECRET === undefined) {
|
||||
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Forward Testing mode."); }
|
||||
return
|
||||
}
|
||||
|
||||
bot.startMode = "Live"
|
||||
if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) {
|
||||
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date()
|
||||
}
|
||||
bot.resumeExecution = false;
|
||||
bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf())
|
||||
bot.hasTheBotJustStarted = true
|
||||
|
||||
}
|
||||
|
||||
function startPaperTrading(message) {
|
||||
bot.startMode = "Backtest"
|
||||
console.log("startPaperTrading")
|
||||
if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf()) {
|
||||
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date()
|
||||
}
|
||||
bot.resumeExecution = false;
|
||||
bot.hasTheBotJustStarted = true
|
||||
bot.multiPeriodProcessDatetime = new Date(bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf())
|
||||
|
||||
}
|
||||
|
||||
function setKeyToUse() {
|
||||
/* The last place where we can find a key to use is the key pool at the exchange account. */
|
||||
if (bot.DEFINITION.personalData) {
|
||||
if (bot.DEFINITION.personalData.exchangeAccounts) {
|
||||
@@ -130,20 +190,6 @@
|
||||
process.env.SECRET = key.code
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.KEY === undefined || process.env.SECRET === undefined) {
|
||||
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Live mode."); }
|
||||
return
|
||||
}
|
||||
|
||||
bot.startMode = "Live"
|
||||
if (bot.VALUES_TO_USE.timeRange.initialDatetime.valueOf() < (new Date()).valueOf) {
|
||||
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date()
|
||||
}
|
||||
bot.resumeExecution = false;
|
||||
bot.multiPeriodProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime
|
||||
bot.hasTheBotJustStarted = true
|
||||
|
||||
}
|
||||
|
||||
function setValuesToUse(message) {
|
||||
|
||||
@@ -212,7 +212,7 @@ function bootLoader() {
|
||||
}
|
||||
|
||||
if (global.TASK_NODE.bot.processes[processIndex].code.process === undefined) {
|
||||
console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[processIndex].name);
|
||||
console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' at object Process is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[processIndex].name);
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user