Refactoring and Bug Fixes

This commit is contained in:
Luis Fernando Molina committed 2020-10-31 21:08:57 +01:00
1 parent c94f7fc747
commit c877072b7c
14 files changed
+425 -399

No files matched your search

@@ -63,7 +63,7 @@ exports.newOrdersCalculations = function newOrdersCalculations(bot, logger) {
function recalculateActualSize() {
/*
We will recalculate the Quoted Asset Actual Size. This will also give to it an initial value the first time we do this.
We will recalculate the Quoted Asset Actual Size. This will also give to it an initial value.
In the next formula, we are unsing the rate of the order because we dont know yet the Actual Rate.
This rate might be replaced afteerwards for the Actual Rate when this is calculated again once
the Actual Rate is known.
@@ -279,7 +279,7 @@ exports.newOrdersCalculations = function newOrdersCalculations(bot, logger) {
need to calculate that by ourselves.
*/
tradingEngineOrder.orderQuotedAsset.sizeFilled.value =
tradingEngineOrder.orderQuotedAsset.sizeFilled.value * tradingEngineOrder.orderStatistics.percentageFilled.value / 100
tradingEngineOrder.orderQuotedAsset.actualSize.value * tradingEngineOrder.orderStatistics.percentageFilled.value / 100
tradingEngineOrder.orderQuotedAsset.sizeFilled.value = global.PRECISE(tradingEngineOrder.orderQuotedAsset.sizeFilled.value, 10)
}
@@ -297,7 +297,7 @@ exports.newOrdersCalculations = function newOrdersCalculations(bot, logger) {
/*
In this case the Amount Received is in Base Asset.
*/
tradingEngineOrder.orderBaseAsset.amountReceived.value.value =
tradingEngineOrder.orderBaseAsset.amountReceived.value =
tradingEngineOrder.orderBaseAsset.sizeFilled.value -
tradingEngineOrder.orderBaseAsset.feesPaid.value
break
@@ -306,7 +306,7 @@ exports.newOrdersCalculations = function newOrdersCalculations(bot, logger) {
/*
In this case the Amount Received is in Quoted Asset.
*/
tradingEngineOrder.orderQuotedAsset.amountReceived.value.value =
tradingEngineOrder.orderQuotedAsset.amountReceived.value =
tradingEngineOrder.orderQuotedAsset.sizeFilled.value -
tradingEngineOrder.orderQuotedAsset.feesPaid.value
break
@@ -83,7 +83,7 @@ exports.newOrdersSimulations = function newOrdersSimulations(bot, logger) {
case 'Market Order': {
/* Actual Rate is simulated based on the Session Paremeters */
let slippageAmount = tradingEngineOrder.rate.value * sessionParameters.slippage.config.positionRate / 100
let slippageAmount = tradingEngineOrder.rate.value * sessionParameters.slippage.config.marketOrderRate / 100
if (slippageAmount !== 0) {
switch (tradingSystemOrder.type) {
case 'Market Sell Order': {
@@ -93,7 +93,7 @@ exports.newOrdersSimulations = function newOrdersSimulations(bot, logger) {
tradingSystem.warnings.push(
[
[sessionParameters.slippage.id, tradingEngineOrder.rate.id, tradingEngineOrder.orderStatistics.actualRate.id],
'slippage.config.positionRate Slippage Amount (' + slippageAmount + ') substracted from Order Rate (' + tradingEngineOrder.rate.value + ') to get the Actual Rate (' + tradingEngineOrder.orderStatistics.actualRate.value + ')'
'slippage.config.marketOrderRate Slippage Amount (' + slippageAmount + ') substracted from Order Rate (' + tradingEngineOrder.rate.value + ') to get the Actual Rate (' + tradingEngineOrder.orderStatistics.actualRate.value + ')'
]
)
break
@@ -105,7 +105,7 @@ exports.newOrdersSimulations = function newOrdersSimulations(bot, logger) {
tradingSystem.warnings.push(
[
[sessionParameters.slippage.id, tradingEngineOrder.rate.id, tradingEngineOrder.orderStatistics.actualRate.id],
'slippage.config.positionRate Slippage Amount (' + slippageAmount + ') added to Order Rate (' + tradingEngineOrder.rate.value + ') to get the Actual Rate (' + tradingEngineOrder.orderStatistics.actualRate.value + ')'
'slippage.config.marketOrderRate Slippage Amount (' + slippageAmount + ') added to Order Rate (' + tradingEngineOrder.rate.value + ') to get the Actual Rate (' + tradingEngineOrder.orderStatistics.actualRate.value + ')'
]
)
break
@@ -414,7 +414,7 @@ exports.newOrdersSimulations = function newOrdersSimulations(bot, logger) {
/*
In this case the Amount Received is in Base Asset.
*/
tradingEngineOrder.orderBaseAsset.amountReceived.value.value =
tradingEngineOrder.orderBaseAsset.amountReceived.value =
tradingEngineOrder.orderBaseAsset.sizeFilled.value -
tradingEngineOrder.orderBaseAsset.feesPaid.value
break
@@ -423,7 +423,7 @@ exports.newOrdersSimulations = function newOrdersSimulations(bot, logger) {
/*
In this case the Amount Received is in Quoted Asset.
*/
tradingEngineOrder.orderQuotedAsset.amountReceived.value.value =
tradingEngineOrder.orderQuotedAsset.amountReceived.value =
tradingEngineOrder.orderQuotedAsset.sizeFilled.value -
tradingEngineOrder.orderQuotedAsset.feesPaid.value
break
@@ -17,7 +17,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
let tradingSystem
let tradingEngine
let sessionParameters
let dynamicIndicators
let dynamicIndicators
const TRADING_STAGES_MODULE = require('./TradingStages.js')
let tradingStagesModule = TRADING_STAGES_MODULE.newTradingStages(bot, logger, tradingEngineModule)
@@ -131,8 +131,8 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
for (let i = 0; i < tradingSystem.dynamicIndicators.indicatorFunctions.length; i++) {
let indicatorFunction = tradingSystem.dynamicIndicators.indicatorFunctions[i]
if (indicatorFunction.formula === undefined) { return}
if (indicatorFunction.config.codeName === undefined) { return}
if (indicatorFunction.formula === undefined) { return }
if (indicatorFunction.config.codeName === undefined) { return }
dynamicIndicators[indicatorFunction.config.codeName] = tradingSystem.formulas.get(indicatorFunction.formula.id)
}
}
@@ -257,15 +257,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
will not be considered an error.
*/
value = false
if (code.indexOf('previous') > -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.
*/
} else {
error = err.message
}
error = err.message
}
tradingSystem.conditions.set(node.id, value)
@@ -297,15 +289,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM
will not be considered an error.
*/
value = 0
if (node.code.indexOf('previous') > -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.
*/
} else {
error = err.message
}
error = err.message
}
if (error !== undefined) {
+3 -3
View File
@@ -326,14 +326,14 @@
name: 'Missing Slippage',
type: 'Slippage',
config: {
positionRate: 0,
marketOrderRate: 0,
stopLoss: 0,
takeProfit: 0
}
}
}
if (bot.SESSION.parameters.slippage.config.positionRate === undefined) { // if the positionRate is missing we create a default one.
bot.SESSION.parameters.slippage.config.positionRate = 0
if (bot.SESSION.parameters.slippage.config.marketOrderRate === undefined) { // if the marketOrderRate is missing we create a default one.
bot.SESSION.parameters.slippage.config.marketOrderRate = 0
}
if (bot.SESSION.parameters.slippage.config.stopLoss === undefined) { // if the stopLoss is missing we create a default one.
bot.SESSION.parameters.slippage.config.stopLoss = 0