Multiple Fixes to allow it to run without user keys, in BACKTEST mode.

This commit is contained in:
Luis Fernando Molina committed 2019-08-11 14:18:09 +02:00
1 parent b110e8be68
commit 1afc012a2f
7 files changed
+78 -17

No files matched your search

+7 -5
View File
@@ -157,11 +157,13 @@
let candleArray;
if (err.result === global.CUSTOM_FAIL_RESPONSE.result) { // Just past midnight, this file will not exist for a couple of minutes.
if (err.message === "File does not exist." || err.message === "The specified key does not exist.") {
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
return;
}
if (err.result === global.CUSTOM_FAIL_RESPONSE.result || err.code === "The specified key does not exist." || err.message === "File does not exist.") { // Just past midnight, this file will not exist for a couple of minutes.
logger.write(MODULE_NAME, "[WARN] initialize -> getMarketRateFromIndicator -> onFileReceived -> err = " + JSON.stringify(err));
logger.write(MODULE_NAME, "[WARN] initialize -> getMarketRateFromIndicator -> This could happen when there are still holes on trades and the process needs to catch up. ");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
+12 -2
View File
@@ -409,7 +409,12 @@
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> Entering function."); }
let dateForPath = previousDay.getUTCFullYear() + '/' + utilities.pad(previousDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(previousDay.getUTCDate(), 2);
let filePath = dependency.product + '/' + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
let filePath
if (dependency.dataSet === "Multi-Period-Daily") {
filePath = dependency.product + '/' + dependency.dataSet + "/" + outputPeriodLabel + "/" + dateForPath;
} else {
filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath;
}
let fileName = market.assetA + '_' + market.assetB + ".json";
storage.getTextFile(filePath, fileName, onFileReceived);
@@ -474,7 +479,12 @@
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Entering function."); }
let dateForPath = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2);
let filePath = dependency.product + '/' + "Multi-Period-Daily" + "/" + outputPeriodLabel + "/" + dateForPath;
let filePath
if (dependency.dataSet === "Multi-Period-Daily") {
filePath = dependency.product + '/' + dependency.dataSet + "/" + outputPeriodLabel + "/" + dateForPath;
} else {
filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath;
}
let fileName = market.assetA + '_' + market.assetB + ".json";
storage.getTextFile(filePath, fileName, onFileReceived);
+7 -2
View File
@@ -168,10 +168,15 @@
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); }
let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2);
let fileName = market.assetA + '_' + market.assetB + ".json";
let filePath = dependency.product + "/" + "Multi-Period-Market" + "/" + outputPeriodLabel;
let filePath
if (dependency.dataSet === "Multi-Period-Market") {
filePath = dependency.product + '/' + dependency.dataSet + "/" + outputPeriodLabel;
} else {
filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath;
}
storage.getTextFile(filePath, fileName, onFileReceived);
function onFileReceived(err, text) {
+4
View File
@@ -443,6 +443,10 @@
runTradingBot(botConfig, processConfig);
break;
}
case 'Trading-Engine': {
runTradingEngine(botConfig, processConfig);
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
+47 -2
View File
@@ -82,7 +82,7 @@ function sequenceExecution(currentStep) {
process.env.KEY = key.name
process.env.SECRET = key.code
}
}
}
@@ -90,7 +90,6 @@ function sequenceExecution(currentStep) {
}
}
let stepKey = execution.devTeam + '.' + execution.bot + '.' + execution.process;
if (processedSteps.has(stepKey)) {
processedSteps.set(stepKey, processedSteps.get(stepKey) + 1);
@@ -142,6 +141,14 @@ async function readExecutionConfiguration(execution) {
let finalDatetime = process.env.END_DATE_TIME
if (execution.type === 'Trading-Engine') {
/* We set the START MODE of the Trading Engine */
if (process.env.KEY === undefined || process.env.SECRET === undefined) {
process.env.START_MODE = "backtest" // if we dont have keys, we swtich to backtest mode to avoid exchange errors.
} else {
process.env.START_MODE = "live" // If we have keys, then we are in live mode.
}
if (definition !== undefined) {
if (definition.simulationParams !== undefined) {
if (definition.simulationParams.beginDatetime !== undefined) {
@@ -178,6 +185,44 @@ async function readExecutionConfiguration(execution) {
}
}
}
/* Get the initial balance from the definition */
let tradingSystem = definition.tradingSystem
if (tradingSystem) {
if (tradingSystem.parameters !== undefined) {
if (tradingSystem.parameters.baseAsset !== undefined) {
if (tradingSystem.parameters.baseAsset.formula !== undefined) {
let receivedParameters
try {
receivedParameters = JSON.parse(tradingSystem.parameters.baseAsset.formula.code);
if (receivedParameters.name !== undefined) {
baseAsset = receivedParameters.name;
if (baseAsset !== 'BTC' && baseAsset !== 'USDT') {
/* using BTC as default */
baseAsset = 'BTC'
}
}
if (baseAsset === 'BTC') {
if (receivedParameters.initialBalance !== undefined) {
process.env.INITIAL_BALANCE_ASSET_A = receivedParameters.initialBalance;
process.env.INITIAL_BALANCE_ASSET_B = 0
}
} else {
if (receivedParameters.initialBalance !== undefined) {
process.env.INITIAL_BALANCE_ASSET_B = receivedParameters.initialBalance;
process.env.INITIAL_BALANCE_ASSET_A = 0
}
}
} catch (err) {
process.env.INITIAL_BALANCE_ASSET_A = 0.001 // default
process.env.INITIAL_BALANCE_ASSET_B = 0 // default
}
}
}
}
}
}
}
-2
View File
@@ -36,8 +36,6 @@
try {
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
bot.startMode = 'Live' // The Trading Engine does not support different start modes. Only live for background compatibility.
UI_COMMANDS = pUI_COMMANDS;
processConfig = pProcessConfig;
+1 -4
View File
@@ -140,9 +140,6 @@
"exchangeName": "Poloniex",
"process": "Multi-Period-Daily",
"beginDatetime": "2019-08-01T08:00:00.000Z",
"timePeriod": "05-min",
"baseAsset": "assetB",
"balanceAssetA": "0",
"balanceAssetB": "0.001"
"timePeriod": "05-min"
}
]