parameters come already parsed

This commit is contained in:
Luis Fernando Molina committed 2019-10-21 13:42:26 +02:00
1 parent e09083e9eb
commit c69318a479
2 files changed
+125 -163

No files matched your search

+124 -162
View File
@@ -44,7 +44,7 @@
return
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)
@@ -146,15 +146,9 @@
/* Reduce the balance */
let balancePercentage = 1 // This is the default value
try {
let code = JSON.parse(bot.SESSION.code)
if (code.balancePercentage !== undefined) {
balancePercentage = code.balancePercentage
}
} catch (err) {
parentLogger.write(MODULE_NAME, "[WARN] initialize -> startFordwardTesting -> Invalid value por balancePercentage. Using Default.");
if (bot.SESSION.code.balancePercentage !== undefined) {
balancePercentage = bot.SESSION.code.balancePercentage
}
bot.VALUES_TO_USE.initialBalanceA = bot.VALUES_TO_USE.initialBalanceA * balancePercentage / 100
@@ -287,15 +281,109 @@
/* Base Asset and Initial Balances. */
{
if (tradingSystem.parameters.baseAsset !== undefined) {
let code
try {
code = JSON.parse(tradingSystem.parameters.baseAsset.code);
let code = tradingSystem.parameters.baseAsset.code
if (code.name !== undefined) {
bot.VALUES_TO_USE.baseAsset = code.name;
}
if (bot.VALUES_TO_USE.baseAsset === 'BTC') {
if (code.initialBalance !== undefined) {
bot.VALUES_TO_USE.initialBalanceA = code.initialBalance;
bot.VALUES_TO_USE.initialBalanceB = 0
}
if (code.minimumBalance !== undefined) {
bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance;
bot.VALUES_TO_USE.minimumBalanceB = 0
}
if (code.maximumBalance !== undefined) {
bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance;
bot.VALUES_TO_USE.maximumBalanceB = 0
}
} else {
if (code.initialBalance !== undefined) {
bot.VALUES_TO_USE.initialBalanceB = code.initialBalance;
bot.VALUES_TO_USE.initialBalanceA = 0
}
if (code.minimumBalance !== undefined) {
bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance;
bot.VALUES_TO_USE.minimumBalanceA = 0
}
if (code.maximumBalance !== undefined) {
bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance;
bot.VALUES_TO_USE.maximumBalanceA = 0
}
}
}
}
/* Time Period */
if (tradingSystem.parameters.timePeriod !== undefined) {
bot.VALUES_TO_USE.timePeriod = tradingSystem.parameters.timePeriod.code
}
/* Slippage */
if (tradingSystem.parameters.slippage !== undefined) {
if (tradingSystem.parameters.slippage.code !== undefined) {
let code = tradingSystem.parameters.slippage.code
if (code.positionRate !== undefined) {
bot.VALUES_TO_USE.slippage.positionRate = code.positionRate
}
if (code.stopLoss !== undefined) {
bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss
}
if (code.takeProfit !== undefined) {
bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit
}
}
}
/* Fee Structure */
if (tradingSystem.parameters.feeStructure !== undefined) {
if (tradingSystem.parameters.feeStructure.code !== undefined) {
let code = tradingSystem.parameters.feeStructure.code
if (code.maker !== undefined) {
bot.VALUES_TO_USE.feeStructure.maker = code.maker
}
if (code.taker !== undefined) {
bot.VALUES_TO_USE.feeStructure.taker = code.taker
}
}
}
/* Time Range */
if (tradingSystem.parameters.timeRange !== undefined) {
if (tradingSystem.parameters.timeRange.code !== undefined) {
let code = tradingSystem.parameters.timeRange.code
if (code.initialDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime)
}
if (code.finalDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime)
}
}
}
}
/* Applying Session Level Parameters */
if (bot.SESSION !== undefined) {
if (bot.SESSION.parameters !== undefined) {
/* Base Asset and Initial Balances. */
{
if (bot.SESSION.parameters.baseAsset !== undefined) {
let code = bot.SESSION.parameters.baseAsset.code
if (code.name !== undefined) {
bot.VALUES_TO_USE.baseAsset = code.name;
}
if (bot.VALUES_TO_USE.baseAsset === 'BTC') {
if (bot.VALUES_TO_USE.baseAsset === 'BTC') {
if (code.initialBalance !== undefined) {
bot.VALUES_TO_USE.initialBalanceA = code.initialBalance;
bot.VALUES_TO_USE.initialBalanceB = 0
@@ -322,121 +410,6 @@
bot.VALUES_TO_USE.maximumBalanceA = 0
}
}
} catch (err) {
tradingSystem.parameters.baseAsset.error = err.message
}
}
}
/* Time Period */
if (tradingSystem.parameters.timePeriod !== undefined) {
bot.VALUES_TO_USE.timePeriod = tradingSystem.parameters.timePeriod.code
}
/* Slippage */
if (tradingSystem.parameters.slippage !== undefined) {
if (tradingSystem.parameters.slippage.code !== undefined) {
try {
let code = JSON.parse(tradingSystem.parameters.slippage.code)
if (code.positionRate !== undefined) {
bot.VALUES_TO_USE.slippage.positionRate = code.positionRate
}
if (code.stopLoss !== undefined) {
bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss
}
if (code.takeProfit !== undefined) {
bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit
}
} catch (err) {
tradingSystem.parameters.slippage.error = err.message
}
}
}
/* Fee Structure */
if (tradingSystem.parameters.feeStructure !== undefined) {
if (tradingSystem.parameters.feeStructure.code !== undefined) {
try {
let code = JSON.parse(tradingSystem.parameters.feeStructure.code)
if (code.maker !== undefined) {
bot.VALUES_TO_USE.feeStructure.maker = code.maker
}
if (code.taker !== undefined) {
bot.VALUES_TO_USE.feeStructure.taker = code.taker
}
} catch (err) {
tradingSystem.parameters.feeStructure.error = err.message
}
}
}
/* Time Range */
if (tradingSystem.parameters.timeRange !== undefined) {
if (tradingSystem.parameters.timeRange.code !== undefined) {
try {
let code = JSON.parse(tradingSystem.parameters.timeRange.code)
if (code.initialDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime)
}
if (code.finalDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime)
}
} catch (err) {
tradingSystem.parameters.timeRange.error = err.message
}
}
}
}
/* Applying Session Level Parameters */
if (bot.SESSION !== undefined) {
if (bot.SESSION.parameters !== undefined) {
/* Base Asset and Initial Balances. */
{
if (bot.SESSION.parameters.baseAsset !== undefined) {
let code
try {
code = JSON.parse(bot.SESSION.parameters.baseAsset.code);
if (code.name !== undefined) {
bot.VALUES_TO_USE.baseAsset = code.name;
}
if (bot.VALUES_TO_USE.baseAsset === 'BTC') {
if (code.initialBalance !== undefined) {
bot.VALUES_TO_USE.initialBalanceA = code.initialBalance;
bot.VALUES_TO_USE.initialBalanceB = 0
}
if (code.minimumBalance !== undefined) {
bot.VALUES_TO_USE.minimumBalanceA = code.minimumBalance;
bot.VALUES_TO_USE.minimumBalanceB = 0
}
if (code.maximumBalance !== undefined) {
bot.VALUES_TO_USE.maximumBalanceA = code.maximumBalance;
bot.VALUES_TO_USE.maximumBalanceB = 0
}
} else {
if (code.initialBalance !== undefined) {
bot.VALUES_TO_USE.initialBalanceB = code.initialBalance;
bot.VALUES_TO_USE.initialBalanceA = 0
}
if (code.minimumBalance !== undefined) {
bot.VALUES_TO_USE.minimumBalanceB = code.minimumBalance;
bot.VALUES_TO_USE.minimumBalanceA = 0
}
if (code.maximumBalance !== undefined) {
bot.VALUES_TO_USE.maximumBalanceB = code.maximumBalance;
bot.VALUES_TO_USE.maximumBalanceA = 0
}
}
} catch (err) {
parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Base Asset Value -> err = " + err.stack);
}
}
}
@@ -448,21 +421,17 @@
/* Slippage */
if (bot.SESSION.parameters.slippage !== undefined) {
if (bot.SESSION.parameters.slippage.code !== undefined) {
try {
let code = JSON.parse(bot.SESSION.parameters.slippage.code)
if (code.positionRate !== undefined) {
bot.VALUES_TO_USE.slippage.positionRate = code.positionRate
}
if (code.stopLoss !== undefined) {
bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss
}
if (code.takeProfit !== undefined) {
bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit
}
let code = bot.SESSION.parameters.slippage.code
} catch (err) {
parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Slippage Value -> err = " + err.stack);
if (code.positionRate !== undefined) {
bot.VALUES_TO_USE.slippage.positionRate = code.positionRate
}
if (code.stopLoss !== undefined) {
bot.VALUES_TO_USE.slippage.stopLoss = code.stopLoss
}
if (code.takeProfit !== undefined) {
bot.VALUES_TO_USE.slippage.takeProfit = code.takeProfit
}
}
}
@@ -470,18 +439,14 @@
/* Fee Structure */
if (bot.SESSION.parameters.feeStructure !== undefined) {
if (bot.SESSION.parameters.feeStructure.code !== undefined) {
try {
let code = JSON.parse(bot.SESSION.parameters.feeStructure.code)
if (code.maker !== undefined) {
bot.VALUES_TO_USE.feeStructure.maker = code.maker
}
if (code.taker !== undefined) {
bot.VALUES_TO_USE.feeStructure.taker = code.taker
}
let code = bot.SESSION.parameters.feeStructure.code
} catch (err) {
parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Fee Structure Value -> err = " + err.stack);
if (code.maker !== undefined) {
bot.VALUES_TO_USE.feeStructure.maker = code.maker
}
if (code.taker !== undefined) {
bot.VALUES_TO_USE.feeStructure.taker = code.taker
}
}
}
@@ -489,16 +454,13 @@
/* Time Range */
if (bot.SESSION.parameters.timeRange !== undefined) {
if (bot.SESSION.parameters.timeRange.code !== undefined) {
try {
let code = JSON.parse(bot.SESSION.parameters.timeRange.code)
if (code.initialDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime)
}
if (code.finalDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime)
}
} catch (err) {
parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Invalid Time Range Value -> err = " + err.stack);
let code = bot.SESSION.parameters.timeRange.code
if (code.initialDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.initialDatetime = new Date(code.initialDatetime)
}
if (code.finalDatetime !== undefined) {
bot.VALUES_TO_USE.timeRange.finalDatetime = new Date(code.finalDatetime)
}
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ if (global.TASK_NODE !== undefined) {
}
else { // I use this section to debug in standalone mode.
let argument = ' {"type":"Task","name":"Runs Backtests","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"20 Minutes","code":{"folderName":"Backtest-01"},"parameters":{"type":"Parameters","name":"Parameters","baseAsset":{"type":"Base Asset","name":"Base Asset","code":{"name":"BTC","initialBalance":0.001,"minimumBalance":0.0001,"maximumBalance":1},"id":"666f6f10-2f17-4f5e-951c-b532bdb574d2"},"timeRange":{"type":"Time Range","name":"Time Range","code":{"initialDatetime":"2019-09-01T00:00:00.000Z","finalDatetime":"2019-09-05T00:00:00.000Z"},"id":"172958dd-b268-4444-8163-70979538ea6e"},"timePeriod":{"type":"Time Period","name":"Time Period","code":"01-hs","id":"37ee839d-9a7c-410c-9251-c33b8f1b99f7"},"slippage":{"type":"Slippage","name":"Slippage","code":{"positionRate":0.1,"stopLoss":0.1,"takeProfit":0.1},"id":"86ebd973-6ad9-4070-aece-a87623f24c2e"},"feeStructure":{"type":"Fee Structure","name":"Fee Structure","code":{"maker":0.15,"taker":0.25},"id":"a0ec3f6f-6047-4740-87fe-393b1c714adb"},"key":{"type":"Exchange Account Key","name":"New Key","code":"Paste your exchange API secret key here and the put the key name as this key object title. Secret keys are filtered out and NOT exported when using the SHARE menu option on any object at your workspace. Secret keys ARE downloaded when using the download button.","id":"368f879d-e363-47c7-b55e-7b927d896b20"},"id":"09db5e1e-a7e8-468c-ad70-0d2ab1c8b8b8"},"layerManager":{"type":"Layer Manager","name":"New Layer Manager","layers":[{"type":"Layer","name":"Live","code":{"product":"Live-Trading-History"},"id":"0ec05e1c-230b-44a1-9f2c-fba0ea2ff9e2"},{"type":"Layer","name":"Trades","code":{"product":"Simulation-Trades"},"id":"6326e03a-96c0-4d21-b877-f2c6a0419fc5"},{"type":"Layer","name":"Strategies","code":{"product":"Simulation-Strategies"},"id":"bda1e06c-e569-4bd5-95fb-90154aafb003"},{"type":"Layer","name":"Simulation","code":{"product":"Trading-Simulation"},"id":"d58d8cd2-f125-4f0c-b241-08e2af8ac4be"},{"type":"Layer","name":"Formulas & Conditions","code":{"product":"Simulation-Conditions"},"id":"15dfeca0-acd9-40d3-afe0-4805654bf0d0"}],"id":"884c4dd7-4beb-43fb-bda5-d6097d58ae09"},"socialBots":{"type":"Social Bots","name":"New Social Bots","bots":[{"type":"Telegram Bot","name":"New Telegram Bot","code":{"botToken":"861966974:AAEx9Gfg4boBDX_ZzqNjxXSzIK4fweFwH9A","chatId":-330926442},"announcements":[],"id":"b7fdad03-d096-4e9c-b7f5-6bf6d697c3dd"}],"id":"281eb022-cf9f-4ac2-978b-c8358bee8fec"},"id":"121202ea-6735-4bf3-8a95-aaa55f00f6e7"},"id":"3f483482-d8a1-4755-ba50-7cac6296fa5f"}],"id":"25fe9099-b53d-4757-8a63-3f8a15875f33"},"id":"5b21d2d2-0f52-4408-83eb-ddaa844ec58c"}'
let argument = '{"type":"Task","name":"Runs Backtests","bot":{"type":"Trading Engine","code":{"team":"AAMasters","bot":"AAJason","repo":"AAJason-Trading-Engine-Bot"},"processes":[{"type":"Process","subType":"Trading Engine Process","name":"Multi Period","code":{"process":"Multi-Period"},"session":{"type":"Backtesting Session","name":"Backtest 01","code":{"folderName":"Backtest-01"},"parameters":{"type":"Parameters","name":"Parameters","baseAsset":{"type":"Base Asset","name":"Base Asset","code":{"name":"BTC","initialBalance":0.001,"minimumBalance":0.0001,"maximumBalance":1},"id":"666f6f10-2f17-4f5e-951c-b532bdb574d2"},"timeRange":{"type":"Time Range","name":"Time Range","code":{"initialDatetime":"2019-09-24T00:00:00.000Z","finalDatetime":"2019-09-27T00:00:00.000Z"},"id":"172958dd-b268-4444-8163-70979538ea6e"},"timePeriod":{"type":"Time Period","name":"Time Period","code":"10-min","id":"37ee839d-9a7c-410c-9251-c33b8f1b99f7"},"slippage":{"type":"Slippage","name":"Slippage","code":{"positionRate":0.1,"stopLoss":0.1,"takeProfit":0.1},"id":"86ebd973-6ad9-4070-aece-a87623f24c2e"},"feeStructure":{"type":"Fee Structure","name":"Fee Structure","code":{"maker":0.15,"taker":0.25},"id":"a0ec3f6f-6047-4740-87fe-393b1c714adb"},"key":{"type":"Exchange Account Key","name":"New Key","code":"Paste your exchange API secret key here and the put the key name as this key object title. Secret keys are filtered out and NOT exported when using the SHARE menu option on any object at your workspace. Secret keys ARE downloaded when using the download button.","id":"368f879d-e363-47c7-b55e-7b927d896b20"},"id":"09db5e1e-a7e8-468c-ad70-0d2ab1c8b8b8"},"layerManager":{"type":"Layer Manager","name":"New Layer Manager","layers":[{"type":"Layer","name":"Live","code":{"product":"Live-Trading-History"},"id":"0ec05e1c-230b-44a1-9f2c-fba0ea2ff9e2"},{"type":"Layer","name":"Trades","code":{"product":"Simulation-Trades"},"id":"6326e03a-96c0-4d21-b877-f2c6a0419fc5"},{"type":"Layer","name":"Strategies","code":{"product":"Simulation-Strategies"},"id":"bda1e06c-e569-4bd5-95fb-90154aafb003"},{"type":"Layer","name":"Simulation","code":{"product":"Trading-Simulation"},"id":"d58d8cd2-f125-4f0c-b241-08e2af8ac4be"},{"type":"Layer","name":"Formulas & Conditions","code":{"product":"Simulation-Conditions"},"id":"15dfeca0-acd9-40d3-afe0-4805654bf0d0"}],"id":"884c4dd7-4beb-43fb-bda5-d6097d58ae09"},"socialBots":{"type":"Social Bots","name":"New Social Bots","bots":[],"id":"281eb022-cf9f-4ac2-978b-c8358bee8fec"},"id":"121202ea-6735-4bf3-8a95-aaa55f00f6e7"},"id":"3f483482-d8a1-4755-ba50-7cac6296fa5f"}],"id":"25fe9099-b53d-4757-8a63-3f8a15875f33"},"id":"5b21d2d2-0f52-4408-83eb-ddaa844ec58c"}'
/* charly argument = '{"type":"Task","name":"Brings Trades Records from the Exchange","bot":{"type":"Sensor","name":"Charly","processes":[{"type":"Process","name":"Live Trades","code":{"team":"AAMasters","bot":"AACharly","process":"Live-Trades"},"id":"5846ebc7-1979-4a80-9cc7-94bb4b8659dc"},{"type":"Process","name":"Hole Fixing","code":{"team":"AAMasters","bot":"AACharly","process":"Hole-Fixing"},"id":"31fc4f05-75d4-419a-9fb0-73e25e856f15"}]},"id":"5bfef4dc-54c1-44db-ace6-1ab27a86746e"}'
// olivia argument = '{"type":"Task","name":"Generates 1 min to 24 hs Candles & Volumes","bot":{"type":"Indicator","name":"Olivia","processes":[{"type":"Process","name":"Daily","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Daily"},"id":"68cc8e1b-e94a-477e-82d0-15ecc9f1b9e2"},{"type":"Process","name":"Market","code":{"team":"AAMasters","bot":"AAOlivia","process":"Multi-Period-Market"},"id":"e1ac5e3d-d491-4e90-baf4-d4e5b71a8b1a"}]},"id":"efe36e05-75ea-41b5-8d92-c6b27635c834"}'
// bruce argument = ' {"type":"Task","name":"Converts Trades into 1 min Candles & Volumes","bot":{"type":"Indicator","name":"Bruce","processes":[{"type":"Process","name":"New Process","code":{"team":"AAMasters","bot":"AABruce","process":"Single-Period-Daily"},"id":"e184744f-5de0-41c1-ad4c-36960f4ced90"}]},"id":"42758590-a7bd-4712-a5c9-80a3a820c5b3"}'