Cycles
This commit is contained in:
1 parent
3ba4aae0e8
commit
8c37512760
3 files changed
+34
-6
No files matched your search
@@ -10,6 +10,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
getNodeById: getNodeById,
|
||||
cloneValues: cloneValues,
|
||||
setCurrentCandle: setCurrentCandle,
|
||||
setCurrentCycle: setCurrentCycle,
|
||||
initializeNode: initializeNode,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
@@ -64,6 +65,31 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
tradingEngine.current.episode.candle.max.value = candle.max
|
||||
}
|
||||
|
||||
function setCurrentCycle(cycle) {
|
||||
switch (cycle) {
|
||||
case 'First': {
|
||||
tradingEngine.current.episode.cycle.begin.value = tradingEngine.current.episode.candle.begin.value
|
||||
tradingEngine.current.episode.cycle.end.value =
|
||||
tradingEngine.current.episode.candle.begin.value +
|
||||
(
|
||||
tradingEngine.current.episode.candle.end.value -
|
||||
tradingEngine.current.episode.candle.begin.value + 1
|
||||
) / 2 - 1
|
||||
break
|
||||
}
|
||||
case 'Second': {
|
||||
tradingEngine.current.episode.cycle.begin.value =
|
||||
tradingEngine.current.episode.candle.begin.value +
|
||||
(
|
||||
tradingEngine.current.episode.candle.end.value -
|
||||
tradingEngine.current.episode.candle.begin.value + 1
|
||||
) / 2
|
||||
tradingEngine.current.episode.cycle.end.value = tradingEngine.current.episode.candle.end.value
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cloneValues(originNode, destinationNode) {
|
||||
if (originNode === undefined) { return }
|
||||
if (destinationNode === undefined) { return }
|
||||
|
||||
@@ -155,6 +155,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
give some room so that orders can be canceled or filled and we can
|
||||
write those records into the output memory.
|
||||
*/
|
||||
tradingEngineModule.setCurrentCycle('First')
|
||||
await tradingSystemModule.run()
|
||||
|
||||
/* Add new records to the process output */
|
||||
@@ -172,6 +173,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
first run, and the same Limit Order definition to spawn a new order
|
||||
without the need to wait until the next candle.
|
||||
*/
|
||||
tradingEngineModule.setCurrentCycle('Second')
|
||||
await tradingSystemModule.run()
|
||||
|
||||
controlLoop()
|
||||
|
||||
@@ -98,6 +98,12 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
|
||||
}
|
||||
|
||||
function mantain() {
|
||||
tradingStagesModule.mantain()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
tradingStagesModule.reset()
|
||||
|
||||
tradingSystem.highlights = []
|
||||
tradingSystem.errors = []
|
||||
tradingSystem.values = []
|
||||
@@ -105,12 +111,6 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
|
||||
tradingSystem.progress = []
|
||||
tradingSystem.running = []
|
||||
tradingSystem.announcements = []
|
||||
|
||||
tradingStagesModule.mantain()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
tradingStagesModule.reset()
|
||||
}
|
||||
|
||||
function updateChart(pChart) {
|
||||
|
||||
Reference in new issue
Block a user