saving objects
This commit is contained in:
1 parent
b42fcf0038
commit
083788d36c
3 files changed
+58
-30
No files matched your search
@@ -37,16 +37,41 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
|
||||
let outputDatasetNode = outputDatasets[i]
|
||||
let dataset = outputDatasetNode.referenceParent
|
||||
let product = dataset.parentNode
|
||||
let record
|
||||
let outputDatasetArray = outputDatasetsMap.get(product.config.codeName)
|
||||
|
||||
if (bot.processingDailyFiles === true && dataset.config.type === 'Daily Files') {
|
||||
record = scanRecordDefinition(product)
|
||||
outputDatasetArray.push(record)
|
||||
persistRecord()
|
||||
}
|
||||
|
||||
if (bot.processingDailyFiles === false && dataset.config.type === 'Market Files') {
|
||||
record = scanRecordDefinition(product)
|
||||
persistRecord()
|
||||
}
|
||||
|
||||
function persistRecord() {
|
||||
let record = scanRecordDefinition(product)
|
||||
|
||||
if (product.config.saveAsObjects === true) {
|
||||
/*
|
||||
We check that the existing file does not contain at the end a record that
|
||||
does not signal that the object is closed.
|
||||
If it does, we replace it with the new one until at some point it will signal
|
||||
does the object is closed.
|
||||
*/
|
||||
let lastRecord = outputDatasetArray[outputDatasetArray.length - 1]
|
||||
if (lastRecord !== undefined) {
|
||||
for (let j = 0; j < product.record.properties.length; j++) {
|
||||
let recordProperty = product.record.properties[j]
|
||||
if (recordProperty.config.codeName === product.config.propertyNameThatDefinesObject) {
|
||||
let propertyValue = record[j]
|
||||
if (propertyValue !== product.config.propertyValueThatClosesObject) {
|
||||
outputDatasetArray.splice(outputDatasetArray.length - 1, 1)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* We add every record to the existing file. */
|
||||
outputDatasetArray.push(record)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
let heartBeatDate
|
||||
let previousHeartBeatDate
|
||||
|
||||
/* This determines where we are standing */
|
||||
/* This determines where we are standing */
|
||||
bot.sessionAndMarketBaseAssetsAreEqual = (sessionParameters.sessionBaseAsset.referenceParent.referenceParent.config.codeName === bot.market.baseAsset)
|
||||
|
||||
initializeLoop()
|
||||
@@ -207,7 +207,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
}
|
||||
|
||||
/* After a position was closed, we need to close the strategy. */
|
||||
tradingSystem.exitStrategyAfterPosition()
|
||||
tradingSystemModule.exitStrategyAfterPosition()
|
||||
|
||||
snapshotsModule.manageSnapshots()
|
||||
tradingRecordsModule.appendRecords()
|
||||
|
||||
@@ -77,10 +77,8 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
/* Here we check if there is a codition to be evaluated */
|
||||
if (node.type === 'Condition' && evaluating === 'Conditions') {
|
||||
if (node.code !== undefined) {
|
||||
/* We will eval this condition */
|
||||
evalCondition(node)
|
||||
}
|
||||
/* We will eval this condition */
|
||||
evalCondition(node)
|
||||
}
|
||||
|
||||
/* Here we check if there is a formula to be evaluated */
|
||||
@@ -127,11 +125,21 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
function evalCondition(node) {
|
||||
let value
|
||||
let error
|
||||
/*
|
||||
The code can be at the condition node if it was done with the Conditions Editor, or it can also be
|
||||
at a Javascript Code node. If there is a Javascript object we will give it preference and take the code
|
||||
from there. Otherwise we will take the code from the Condition node.
|
||||
*/
|
||||
let code = node.code
|
||||
if (node.javascriptCode !== undefined) {
|
||||
if (node.javascriptCode.code !== undefined) {
|
||||
code = node.javascriptCode.code
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] evalCondition -> code = ' + node.code) }
|
||||
|
||||
value = eval(node.code)
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] evalCondition -> code = ' + code) }
|
||||
value = eval(code)
|
||||
} catch (err) {
|
||||
/*
|
||||
One possible error is that the conditions references a .previous that is undefined. This
|
||||
@@ -139,8 +147,8 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
*/
|
||||
value = false
|
||||
|
||||
if (node.code.indexOf('previous') > -1 && err.message.indexOf('of undefined') > -1 ||
|
||||
node.code.indexOf('chart') > -1 && err.message.indexOf('of undefined') > -1
|
||||
if (code.indexOf('previous') > -1 && err.message.indexOf('of undefined') > -1 ||
|
||||
code.indexOf('chart') > -1 && err.message.indexOf('of undefined') > -1
|
||||
) {
|
||||
/*
|
||||
We are not going to set an error for the casess we are using previous and the error is that the indicator is undefined.
|
||||
@@ -154,10 +162,6 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
if (value === true) {
|
||||
tradingSystem.highlights.push(node.id)
|
||||
tradingSystem.errors.push([node.id, 'La concha del mono'])
|
||||
tradingSystem.progress.push([node.id, 85])
|
||||
tradingSystem.status.push([node.id, 'Waiting for la concha del mono'])
|
||||
tradingSystem.running.push([node.id, true])
|
||||
}
|
||||
if (error !== undefined) {
|
||||
tradingSystem.errors.push([node.id, error])
|
||||
@@ -240,9 +244,9 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
let condition = situation.conditions[m]
|
||||
let value = false
|
||||
if (conditions.get(condition.id) !== undefined) {
|
||||
value = conditions.get(condition.id).value
|
||||
value = conditions.get(condition.id)
|
||||
}
|
||||
if (value === false) { passed = false }
|
||||
if (value !== true) { passed = false }
|
||||
}
|
||||
|
||||
tradingSystem.values.push([situation.id, passed])
|
||||
@@ -298,9 +302,9 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
let condition = situation.conditions[m]
|
||||
let value = false
|
||||
if (conditions.get(condition.id) !== undefined) {
|
||||
value = conditions.get(condition.id).value
|
||||
value = conditions.get(condition.id)
|
||||
}
|
||||
if (value === false) { passed = false }
|
||||
if (value !== true) { passed = false }
|
||||
}
|
||||
|
||||
tradingSystem.values.push([situation.id, passed])
|
||||
@@ -350,10 +354,10 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
let condition = situation.conditions[m]
|
||||
let value = false
|
||||
if (conditions.get(condition.id) !== undefined) {
|
||||
value = conditions.get(condition.id).value
|
||||
value = conditions.get(condition.id)
|
||||
}
|
||||
|
||||
if (value === false) { passed = false }
|
||||
if (value !== true) { passed = false }
|
||||
}
|
||||
|
||||
tradingSystem.values.push([situation.id, passed])
|
||||
@@ -363,11 +367,10 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
tradingSystem.highlights.push(triggerStage.id)
|
||||
|
||||
tradingEngine.current.strategy.stageType.value = 'Open Stage'
|
||||
tradingEngine.current.position.stopLossStage.value = 'Open Stage'
|
||||
tradingEngine.current.position.takeProfitStage.value = 'Open Stage'
|
||||
tradingEngine.current.position.stopLossPhase.value = 0
|
||||
tradingEngine.current.position.takeProfitPhase.value = 0
|
||||
|
||||
tradingEngine.current.position.stopLoss.stopLossStage.value = 'Open Stage'
|
||||
tradingEngine.current.position.takeProfit.takeProfitStage.value = 'Open Stage'
|
||||
tradingEngine.current.position.stopLoss.stopLossPhase.value = 0
|
||||
tradingEngine.current.position.takeProfit.takeProfitPhase.value = 0
|
||||
tradingEngine.current.position.situationName.value = situation.name
|
||||
|
||||
/* TODO See what to do with this:
|
||||
|
||||
Reference in new issue
Block a user