debugging
This commit is contained in:
1 parent
4281ec7ae9
commit
b42fcf0038
5 files changed
+31
-29
No files matched your search
@@ -62,7 +62,7 @@ exports.newSnapshots = function newSnapshots(bot, logger) {
|
||||
let closeValues = [
|
||||
tradingEngine.episode.positionCounters.positions.value, // Position Number
|
||||
(new Date(candle.begin)).toISOString(), // Datetime
|
||||
tradingSystem.strategies[tradingEngine.current.strategy.index.value].name, // Strategy Name
|
||||
tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value].name, // Strategy Name
|
||||
tradingEngine.current.strategy.situationName.value, // Trigger On Situation
|
||||
tradingEngine.current.position.situationName.value, // Take Position Situation
|
||||
hitOrFial(), // Result
|
||||
|
||||
@@ -193,7 +193,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
/* We take what was calculated at the formula and apply the slippage. */
|
||||
let slippageAmount = tradingEngine.current.position.rate.value * bot.SESSION.parameters.slippage.config.positionRate / 100
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
tradingEngine.current.position.rate.value = tradingEngine.current.position.rate.value - slippageAmount
|
||||
} else {
|
||||
tradingEngine.current.position.rate.value = tradingEngine.current.position.rate.value + slippageAmount
|
||||
@@ -216,7 +216,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
|
||||
let feePaid = 0
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
feePaid = tradingEngine.current.position.size.value * tradingEngine.current.position.rate.value * bot.SESSION.parameters.feeStructure.config.taker / 100
|
||||
|
||||
tradingEngine.current.balance.quotedAsset.value = tradingEngine.current.balance.quotedAsset.value + tradingEngine.current.position.size.value * tradingEngine.current.position.rate.value - feePaid
|
||||
@@ -234,7 +234,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
tradingEngine.current.distanceToEvent.closePosition.value = 1
|
||||
|
||||
/* Position size and rate */
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
}
|
||||
|
||||
function closePosition() {
|
||||
@@ -242,7 +242,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
|
||||
let feePaid = 0
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
|
||||
feePaid = tradingEngine.current.balance.quotedAsset.value / tradingEngine.current.position.endRate.value * bot.SESSION.parameters.feeStructure.config.taker / 100
|
||||
|
||||
@@ -256,7 +256,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
tradingEngine.current.balance.baseAsset.value = 0
|
||||
}
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
tradingEngine.last.position.profitLoss.value = tradingEngine.current.balance.baseAsset.value - tradingEngine.previous.balance.baseAsset.value
|
||||
tradingEngine.last.position.ROI.value = tradingEngine.last.position.profitLoss.value * 100 / tradingEngine.current.position.size.value
|
||||
if (isNaN(tradingEngine.last.position.ROI.value)) { tradingEngine.last.position.ROI.value = 0 }
|
||||
@@ -276,7 +276,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
tradingEngine.episode.episodeCounters.fails.value++
|
||||
}
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
tradingEngine.episode.episodeStatistics.ROI.value = (sessionParameters.sessionBaseAsset.config.initialBalance + tradingEngine.episode.episodeStatistics.profitLoss.value) / sessionParameters.sessionBaseAsset.config.initialBalance - 1
|
||||
tradingEngine.episode.episodeStatistics.hitRatio.value = tradingEngine.episode.episodeCounters.hits.value / tradingEngine.episode.positionCounters.positions.value
|
||||
tradingEngine.episode.episodeStatistics.anualizedRateOfReturn.value = tradingEngine.episode.episodeStatistics.ROI.value / tradingEngine.episode.episodeStatistics.days.value * 365
|
||||
|
||||
@@ -131,7 +131,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger) {
|
||||
let amountB
|
||||
let orderSide
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
orderSide = 'sell'
|
||||
|
||||
orderPrice = tradingEngine.current.position.rate.value
|
||||
@@ -257,7 +257,7 @@ exports.newTradingExecution = function newTradingExecution(bot, logger) {
|
||||
let amountB
|
||||
let orderSide
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
orderSide = 'buy'
|
||||
|
||||
orderPrice = ticker.last + 100 // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff.
|
||||
|
||||
@@ -46,7 +46,6 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
let closingPosition
|
||||
|
||||
/* These are the Modules we will need to run the Simulation */
|
||||
|
||||
const EXCHANGE_API = require('../ExchangeAPI');
|
||||
exchangeAPI = EXCHANGE_API.newExchangeAPI(logger, bot);
|
||||
exchangeAPI.initialize();
|
||||
@@ -83,6 +82,9 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
let heartBeatDate
|
||||
let previousHeartBeatDate
|
||||
|
||||
/* This determines where we are standing */
|
||||
bot.sessionAndMarketBaseAssetsAreEqual = (sessionParameters.sessionBaseAsset.referenceParent.referenceParent.config.codeName === bot.market.baseAsset)
|
||||
|
||||
initializeLoop()
|
||||
|
||||
function initializeLoop() {
|
||||
@@ -417,7 +419,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
let maximumBalance
|
||||
let balance
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
balance = tradingEngine.current.balance.baseAsset.value
|
||||
minimumBalance = sessionParameters.sessionBaseAsset.config.minimumBalance
|
||||
maximumBalance = sessionParameters.sessionBaseAsset.config.maximumBalance
|
||||
|
||||
@@ -219,12 +219,12 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
be outside a strategy again and looking for the conditions to enter all over again.
|
||||
*/
|
||||
|
||||
for (let j = 0; j < tradingSystem.strategies.length; j++) {
|
||||
for (let j = 0; j < tradingSystem.tradingStrategies.length; j++) {
|
||||
if ( // If a strategy was already picked during the loop, we exit the loop
|
||||
tradingEngine.current.strategy.index.value !== tradingEngine.current.strategy.index.config.initialValue
|
||||
) { continue }
|
||||
|
||||
let strategy = tradingSystem.strategies[j]
|
||||
let strategy = tradingSystem.tradingStrategies[j]
|
||||
let triggerStage = strategy.triggerStage
|
||||
|
||||
if (triggerStage !== undefined) {
|
||||
@@ -282,7 +282,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function checkTriggerOff() {
|
||||
if (tradingEngine.current.strategy.stageType.value === 'Trigger Stage') {
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
let triggerStage = strategy.triggerStage
|
||||
|
||||
if (triggerStage !== undefined) {
|
||||
@@ -334,7 +334,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
function checkTakePosition() {
|
||||
/* Take Position Condition */
|
||||
if (tradingEngine.current.strategy.stageType.value === 'Trigger Stage') {
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
let triggerStage = strategy.triggerStage
|
||||
|
||||
if (triggerStage !== undefined) {
|
||||
@@ -388,7 +388,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function checkStopPhasesEvents() {
|
||||
if (tradingEngine.current.strategy.stageType.value === 'Open Stage' || tradingEngine.current.strategy.stageType.value === 'Manage Stage') {
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
let openStage = strategy.openStage
|
||||
let manageStage = strategy.manageStage
|
||||
let parentNode
|
||||
@@ -511,7 +511,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function calculateStopLoss() {
|
||||
if (tradingEngine.current.strategy.stageType.value === 'Open Stage' || tradingEngine.current.strategy.stageType.value === 'Manage Stage') {
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
let openStage = strategy.openStage
|
||||
let manageStage = strategy.manageStage
|
||||
let phase
|
||||
@@ -548,7 +548,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function checkTakeProfitPhaseEvents() {
|
||||
if (tradingEngine.current.strategy.stageType.value === 'Open Stage' || tradingEngine.current.strategy.stageType.value === 'Manage Stage') {
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
let openStage = strategy.openStage
|
||||
let manageStage = strategy.manageStage
|
||||
let parentNode
|
||||
@@ -673,7 +673,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function calculateTakeProfit() {
|
||||
if (tradingEngine.current.strategy.stageType.value === 'Open Stage' || tradingEngine.current.strategy.stageType.value === 'Manage Stage') {
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
let openStage = strategy.openStage
|
||||
let manageStage = strategy.manageStage
|
||||
let phase
|
||||
@@ -711,7 +711,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
function checkStopLossOrTakeProfitWasHit() {
|
||||
{
|
||||
if (tradingEngine.current.strategy.stageType.value === 'Open Stage' || tradingEngine.current.strategy.stageType.value === 'Manage Stage') {
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
/*
|
||||
Checking what happened since the last execution. We need to know if the Stop Loss
|
||||
or our Take Profit were hit.
|
||||
@@ -719,7 +719,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
/* Stop Loss condition: Here we verify if the Stop Loss was hitted or not. */
|
||||
if (
|
||||
(sessionParameters.sessionBaseAsset.name === bot.market.baseAsset && tradingEngine.current.candle.max.value >= tradingEngine.current.position.stopLoss.value) ||
|
||||
(bot.sessionAndMarketBaseAssetsAreEqual && tradingEngine.current.candle.max.value >= tradingEngine.current.position.stopLoss.value) ||
|
||||
(sessionParameters.sessionBaseAsset.name !== bot.market.baseAsset && tradingEngine.current.candle.min.value <= tradingEngine.current.position.stopLoss.value)
|
||||
) {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] checkStopLossOrTakeProfitWasHit -> Stop Loss was hit.') }
|
||||
@@ -729,7 +729,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
This prevents misscalculations when a formula places the stop loss in this case way beyond the market price.
|
||||
If we take the stop loss value at those situation would be a huge distortion of facts.
|
||||
*/
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
if (tradingEngine.current.position.stopLoss.value < tradingEngine.current.candle.min.value) {
|
||||
tradingEngine.current.position.stopLoss.value = tradingEngine.current.candle.min.value
|
||||
}
|
||||
@@ -744,7 +744,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
/* Apply the Slippage */
|
||||
let slippageAmount = slippedStopLoss * bot.SESSION.parameters.slippage.config.stopLoss / 100
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
slippedStopLoss = slippedStopLoss + slippageAmount
|
||||
} else {
|
||||
slippedStopLoss = slippedStopLoss - slippageAmount
|
||||
@@ -766,7 +766,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
/* Take Profit condition: Here we verify if the Take Profit was hit or not. */
|
||||
if (
|
||||
(sessionParameters.sessionBaseAsset.name === bot.market.baseAsset && tradingEngine.current.candle.min.value <= tradingEngine.current.position.takeProfit.value) ||
|
||||
(bot.sessionAndMarketBaseAssetsAreEqual && tradingEngine.current.candle.min.value <= tradingEngine.current.position.takeProfit.value) ||
|
||||
(sessionParameters.sessionBaseAsset.name !== bot.market.baseAsset && tradingEngine.current.candle.max.value >= tradingEngine.current.position.takeProfit.value)
|
||||
) {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] checkStopLossOrTakeProfitWasHit -> Take Profit was hit.') }
|
||||
@@ -776,7 +776,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
This prevents misscalculations when a formula places the take profit in this case way beyond the market price.
|
||||
If we take the stop loss value at those situation would be a huge distortion of facts.
|
||||
*/
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
if (tradingEngine.current.position.takeProfit.value > tradingEngine.current.candle.max.value) {
|
||||
tradingEngine.current.position.takeProfit.value = tradingEngine.current.candle.max.value
|
||||
}
|
||||
@@ -790,7 +790,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
/* Apply the Slippage */
|
||||
let slippageAmount = slippedTakeProfit * bot.SESSION.parameters.slippage.config.takeProfit / 100
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
slippedTakeProfit = slippedTakeProfit + slippageAmount
|
||||
} else {
|
||||
slippedTakeProfit = slippedTakeProfit - slippageAmount
|
||||
@@ -838,13 +838,13 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function getPositionSize() {
|
||||
let balance
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
if (bot.sessionAndMarketBaseAssetsAreEqual) {
|
||||
balance = tradingEngine.current.balance.baseAsset.value
|
||||
} else {
|
||||
balance = tradingEngine.current.balance.quotedAsset.value
|
||||
}
|
||||
const DEFAULT_VALUE = balance
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
|
||||
if (strategy.openStage === undefined) return { DEFAULT_VALUE }
|
||||
if (strategy.openStage.initialDefinition === undefined) return { DEFAULT_VALUE }
|
||||
@@ -858,7 +858,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function getPositionRate() {
|
||||
const DEFAULT_VALUE = tradingEngine.current.candle.close.value
|
||||
let strategy = tradingSystem.strategies[tradingEngine.current.strategy.index.value]
|
||||
let strategy = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value]
|
||||
|
||||
if (strategy.openStage === undefined) return { DEFAULT_VALUE }
|
||||
if (strategy.openStage.initialDefinition === undefined) return { DEFAULT_VALUE }
|
||||
|
||||
Reference in new issue
Block a user