bug fixed
This commit is contained in:
1 parent
d5b1aaded5
commit
4281ec7ae9
4 files changed
+17
-17
No files matched your search
@@ -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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
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
|
||||
@@ -242,7 +242,7 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) {
|
||||
|
||||
let feePaid = 0
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
|
||||
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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
orderSide = 'buy'
|
||||
|
||||
orderPrice = ticker.last + 100 // This is provisional and totally arbitrary, until we have a formula on the designer that defines this stuff.
|
||||
|
||||
@@ -417,7 +417,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
|
||||
let maximumBalance
|
||||
let balance
|
||||
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
balance = tradingEngine.current.balance.baseAsset.value
|
||||
minimumBalance = sessionParameters.sessionBaseAsset.config.minimumBalance
|
||||
maximumBalance = sessionParameters.sessionBaseAsset.config.maximumBalance
|
||||
|
||||
@@ -719,8 +719,8 @@ 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.marketBaseAsset && tradingEngine.current.candle.max.value >= tradingEngine.current.position.stopLoss.value) ||
|
||||
(sessionParameters.sessionBaseAsset.name !== bot.market.marketBaseAsset && tradingEngine.current.candle.min.value <= tradingEngine.current.position.stopLoss.value)
|
||||
(sessionParameters.sessionBaseAsset.name === bot.market.baseAsset && 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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
slippedStopLoss = slippedStopLoss + slippageAmount
|
||||
} else {
|
||||
slippedStopLoss = slippedStopLoss - slippageAmount
|
||||
@@ -766,8 +766,8 @@ 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.marketBaseAsset && tradingEngine.current.candle.min.value <= tradingEngine.current.position.takeProfit.value) ||
|
||||
(sessionParameters.sessionBaseAsset.name !== bot.market.marketBaseAsset && tradingEngine.current.candle.max.value >= tradingEngine.current.position.takeProfit.value)
|
||||
(sessionParameters.sessionBaseAsset.name === bot.market.baseAsset && 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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
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.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
slippedTakeProfit = slippedTakeProfit + slippageAmount
|
||||
} else {
|
||||
slippedTakeProfit = slippedTakeProfit - slippageAmount
|
||||
@@ -838,7 +838,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
|
||||
|
||||
function getPositionSize() {
|
||||
let balance
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.marketBaseAsset) {
|
||||
if (sessionParameters.sessionBaseAsset.name === bot.market.baseAsset) {
|
||||
balance = tradingEngine.current.balance.baseAsset.value
|
||||
} else {
|
||||
balance = tradingEngine.current.balance.quotedAsset.value
|
||||
|
||||
Reference in new issue
Block a user