Running Again

This commit is contained in:
Luis Fernando Molina committed 2020-08-02 20:32:10 +02:00
1 parent d9b06694e2
commit 519da0ea2c
4 files changed
+41 -26

No files matched your search

+10 -10
View File
@@ -53,16 +53,16 @@ exports.newTradingExecution = function newTradingExecution(bot, logger, tradingE
) {
/* Trading Stage Validations */
if (tradingEngineStage.stageBaseAsset === undefined) { continue }
if (tradingEngineStage.stageBaseAsset.size === undefined) { continue }
if (tradingEngineStage.stageBaseAsset.sizeFilled === undefined) { continue }
if (tradingEngineStage.stageBaseAsset.amountReceived === undefined) { continue }
if (tradingEngineStage.stageBaseAsset.feesPaid === undefined) { continue }
if (tradingEngineStage.stageQuotedAsset === undefined) { continue }
if (tradingEngineStage.stageQuotedAsset.size === undefined) { continue }
if (tradingEngineStage.stageQuotedAsset.sizeFilled === undefined) { continue }
if (tradingEngineStage.stageQuotedAsset.amountReceived === undefined) { continue }
if (tradingEngineStage.stageQuotedAsset.feesPaid === undefined) { continue }
if (tradingEngineStage.stageBaseAsset === undefined) { return }
if (tradingEngineStage.stageBaseAsset.size === undefined) { return }
if (tradingEngineStage.stageBaseAsset.sizeFilled === undefined) { return }
if (tradingEngineStage.stageBaseAsset.amountReceived === undefined) { return }
if (tradingEngineStage.stageBaseAsset.feesPaid === undefined) { return }
if (tradingEngineStage.stageQuotedAsset === undefined) { return }
if (tradingEngineStage.stageQuotedAsset.size === undefined) { return }
if (tradingEngineStage.stageQuotedAsset.sizeFilled === undefined) { return }
if (tradingEngineStage.stageQuotedAsset.amountReceived === undefined) { return }
if (tradingEngineStage.stageQuotedAsset.feesPaid === undefined) { return }
/*
The user choice of asset to define the size of the position,
+3
View File
@@ -23,17 +23,20 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng
}
let tradingEngine
let tradingSystem
let sessionParameters
return thisObject
function initialize() {
tradingSystem = bot.simulationState.tradingSystem
tradingEngine = bot.simulationState.tradingEngine
sessionParameters = bot.SESSION.parameters
}
function finalize() {
tradingEngine = undefined
tradingSystem = undefined
sessionParameters = undefined
}
+11 -2
View File
@@ -133,7 +133,12 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
We will use the codeName of the Record Property to match it with
the any of the properties of the Root Node to get the Target Node.
*/
let targetNode = propertyRootNode[recordProperty.config.codeName]
let targetNode
try {
targetNode = propertyRootNode[recordProperty.config.codeName]
} catch (err) {
console.log(err.stack)
}
/*
If the codeName of the Record Property can not match the name of the property at
the target node, the user can explicitly specify the property name at the configuration,
@@ -167,7 +172,11 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
value = targetNode.value
if (recordProperty.config.decimals !== undefined) {
value = Number(value.toFixed(recordProperty.config.decimals))
try {
value = Number(value.toFixed(recordProperty.config.decimals))
} catch (err) {
console.log(err.stack)
}
}
} else {
/*
+17 -14
View File
@@ -549,7 +549,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
false,
tradingEngine.current.position.positionBaseAsset.size, // Stage Size Limit
tradingEngine.current.position.positionQuotedAsset.size, // Stage Size Limit
tradingEngine.current.position.strategyOpenStage
tradingEngine.current.strategyOpenStage
)
/* From here on, the state is officialy Open */
@@ -576,15 +576,15 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
false,
tradingEngine.current.position.positionBaseAsset.size, // Stage Size Limit
tradingEngine.current.position.positionQuotedAsset.size, // Stage Size Limit
tradingEngine.current.position.strategyOpenStage
tradingEngine.current.strategyOpenStage
)
/*
The Open is finished when the fillSize + feesPaid reaches the Position Size.
This can happens at any time when we update the filledSize value when we see
This can happens at any time when we update the sizeFilled value when we see
at the exchange that orders were filled.
*/
if (
tradingEngine.current.strategyOpenStage.stageBaseAsset.filledSize.value +
tradingEngine.current.strategyOpenStage.stageBaseAsset.sizeFilled.value +
tradingEngine.current.strategyOpenStage.stageBaseAsset.feesPaid.value >=
tradingEngine.current.position.positionBaseAsset.size.value * 0.999) {
tradingStrategyModule.updateStageStatus('Open Stage', 'Closed', 'Position Size Filled')
@@ -607,7 +607,10 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
let executionNode = stageNode.openExecution
/* Check if there are unfilled orders */
if (tradingEngine.current.position.openStageOrdersSize.value !== tradingEngine.current.position.openStageFilledSize.value) {
if (
tradingEngine.current.strategyOpenStage.stageBaseAsset.sizeFilled.value +
tradingEngine.current.strategyOpenStage.stageBaseAsset.feesPaid.value <
tradingEngine.current.position.positionBaseAsset.size.value * 0.999) {
/* There are unfilled orders, we will check if they were executed, and cancel the ones that were not. */
evalConditions(stageNode, 'Open Execution')
@@ -619,18 +622,18 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
true,
tradingEngine.current.position.positionBaseAsset.size, // Stage Size Limit
tradingEngine.current.position.positionQuotedAsset.size, // Stage Size Limit
tradingEngine.current.position.strategyOpenStage
tradingEngine.current.strategyOpenStage
)
}
/*
The Closing is finished when the fillSize + feesPaid reaches the ordersSize.
This can happens either because we update the filledSize value when we see
This can happens either because we update the sizeFilled value when we see
at the exchange that orders were filled, or we reduce the ordersSize when
we cancel not yet filled orders.
*/
if (
tradingEngine.current.strategyOpenStage.stageBaseAsset.filledSize.value +
tradingEngine.current.strategyOpenStage.stageBaseAsset.sizeFilled.value +
tradingEngine.current.strategyOpenStage.stageBaseAsset.feesPaid.value >=
tradingEngine.current.position.positionBaseAsset.size.value * 0.999) {
tradingStrategyModule.updateStageStatus('Open Stage', 'Closed')
@@ -675,7 +678,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
checkStopLossOrTakeProfitWasHit()
}
function calculateTakeProfitPosition() {
function calculateStopLossPosition() {
/*
The position of the Stop Loss (above or below the price) is needed in order to know
later if the price hit the Stop Loss or not at every Simulation cycle. When we get
@@ -980,7 +983,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
This will happen only once, as soon as the Take Profit or Stop was hit.
We wil not be placing orders at this time because we do not know
the total filled size of the Open Stage. By skiping execution now
we allow the open stage to get a final value for filledSize that we can use.
we allow the open stage to get a final value for sizeFilled that we can use.
*/
tradingStrategyModule.updateStageStatus('Close Stage', 'Open')
return
@@ -1003,18 +1006,18 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
false,
tradingEngine.current.strategyOpenStage.stageBaseAsset.sizeFilled, // Stage Size Limit
tradingEngine.current.strategyOpenStage.stageQuotedAsset.sizeFilled, // Stage Size Limit
tradingEngine.current.position.strategyCloseStage
tradingEngine.current.strategyCloseStage
)
/*
The Close Stage is finished when the fillSize + feesPaid reaches the Open Fill Size.
This can happens at any time when we update the filledSize value when we see
This can happens at any time when we update the sizeFilled value when we see
at the exchange that orders were filled.
*/
if (
tradingEngine.current.strategyCloseStage.stageBaseAsset.filledSize.value +
tradingEngine.current.strategyCloseStage.stageBaseAsset.sizeFilled.value +
tradingEngine.current.strategyCloseStage.stageBaseAsset.feesPaid.value >=
tradingEngine.current.strategyOpenStage.stageBaseAsset.filledSize.value * 0.999) {
tradingEngine.current.strategyOpenStage.stageBaseAsset.sizeFilled.value * 0.999) {
tradingStrategyModule.updateStageStatus('Close Stage', 'Closed', 'Open Stage fillSize Filled')
} else {
/* Check the Close Stage Event */