From 712852588a7707c721abe533a012119a171c8ae1 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 22 May 2019 16:04:34 +0800 Subject: [PATCH 1/6] Create logic for shouldStopOnError --- src/botPage/bot/Interpreter.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/botPage/bot/Interpreter.js b/src/botPage/bot/Interpreter.js index affa998278..57854d4428 100644 --- a/src/botPage/bot/Interpreter.js +++ b/src/botPage/bot/Interpreter.js @@ -17,6 +17,15 @@ const botInitialized = bot => bot && bot.tradeEngine.options; const botStarted = bot => botInitialized(bot) && bot.tradeEngine.tradeOptions; const shouldRestartOnError = (bot, errorName = '') => !unrecoverableErrors.includes(errorName) && botInitialized(bot) && bot.tradeEngine.options.shouldRestartOnError; + +const shouldStopOnError = (bot, errorName = '') => { + const stopErrors = ['SellNotAvailable']; + if (stopErrors.includes(errorName) && botInitialized(bot)) { + return true; + } + return false; +}; + const timeMachineEnabled = bot => botInitialized(bot) && bot.tradeEngine.options.timeMachineEnabled; export default class Interpreter { @@ -94,11 +103,20 @@ export default class Interpreter { if (this.stopped) { return; } + + if (shouldStopOnError(this.bot, e.name)) { + globalObserver.emit('ui.log.error', e.message); + $('#stopButton').trigger('click'); + this.stop(); + return; + } + this.isErrorTriggered = true; if (!shouldRestartOnError(this.bot, e.name) || !botStarted(this.bot)) { reject(e); return; } + globalObserver.emit('Error', e); const { initArgs, tradeOptions } = this.bot.tradeEngine; this.terminateSession(); From 0327fc0650d38341495a59fa8ca4cb5ed9ef4dee Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 22 May 2019 16:04:55 +0800 Subject: [PATCH 2/6] Keep track whether contract has entry_tick available --- src/botPage/bot/TradeEngine/OpenContract.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/botPage/bot/TradeEngine/OpenContract.js b/src/botPage/bot/TradeEngine/OpenContract.js index 94effe6f64..424aebe810 100644 --- a/src/botPage/bot/TradeEngine/OpenContract.js +++ b/src/botPage/bot/TradeEngine/OpenContract.js @@ -90,13 +90,20 @@ export default Engine => } } setContractFlags(contract) { - const { is_expired: isExpired, is_valid_to_sell: isValidToSell, is_sold: isSold } = contract; + const { + is_expired: isExpired, + is_valid_to_sell: isValidToSell, + is_sold: isSold, + entry_tick: entryTick, + } = contract; this.isSold = Boolean(isSold); this.isSellAvailable = !this.isSold && Boolean(isValidToSell); this.isExpired = Boolean(isExpired); + + this.hasEntryTick = Boolean(entryTick); } expectedContractId(contractId) { return this.contractId && contractId === this.contractId; From 8236d94236f4a7c04e2cea8d125cc3ae6e0dc3c2 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 22 May 2019 16:05:55 +0800 Subject: [PATCH 3/6] Reject instead of throwing an error when RateLimited --- src/botPage/bot/TradeEngine/Proposal.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/botPage/bot/TradeEngine/Proposal.js b/src/botPage/bot/TradeEngine/Proposal.js index 05a0fa257e..e2e5202861 100644 --- a/src/botPage/bot/TradeEngine/Proposal.js +++ b/src/botPage/bot/TradeEngine/Proposal.js @@ -57,7 +57,13 @@ export default Engine => }, }) .catch(e => { - if (e.error.error.code === 'ContractBuyValidationError') { + if (e && e.name === 'RateLimit') { + return Promise.reject(e); + } + + const errorCode = e.error && e.error.error && e.error.error.code; + + if (errorCode === 'ContractBuyValidationError') { const { uuid } = e.error.echo_req.passthrough; if (!this.data.hasIn(['forgetProposals', uuid])) { From 594cd5db4e74e08cd3998bd0f2020aa01feb2a1c Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 22 May 2019 16:06:36 +0800 Subject: [PATCH 4/6] Only throw error when contract hasEntryTick and isValidToSell, else resolve --- src/botPage/bot/TradeEngine/Sell.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/botPage/bot/TradeEngine/Sell.js b/src/botPage/bot/TradeEngine/Sell.js index 9751e7c181..7252ca3276 100644 --- a/src/botPage/bot/TradeEngine/Sell.js +++ b/src/botPage/bot/TradeEngine/Sell.js @@ -17,7 +17,13 @@ export default Engine => } if (!this.isSellAtMarketAvailable()) { - throw Error(translate('Sell is not available')); + if (this.hasEntryTick) { + const error = new Error(translate('Sell is not available')); + error.name = 'SellNotAvailable'; + throw error; + } else { + return Promise.resolve(); + } } const onSuccess = ({ sell: { sold_for: soldFor } }) => { From 38efa3a2c6aae77fca707d5c7dd8737c6e346c96 Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 22 May 2019 16:16:31 +0800 Subject: [PATCH 5/6] Update messaging for contracts that cannot be resold --- src/botPage/bot/TradeEngine/Sell.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/botPage/bot/TradeEngine/Sell.js b/src/botPage/bot/TradeEngine/Sell.js index 7252ca3276..568fa6a15a 100644 --- a/src/botPage/bot/TradeEngine/Sell.js +++ b/src/botPage/bot/TradeEngine/Sell.js @@ -18,7 +18,7 @@ export default Engine => if (!this.isSellAtMarketAvailable()) { if (this.hasEntryTick) { - const error = new Error(translate('Sell is not available')); + const error = new Error(translate('Resale of this contract is not offered.')); error.name = 'SellNotAvailable'; throw error; } else { From 350450a41698fa2ad9291e11711c83a5f0593aec Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Wed, 22 May 2019 16:39:41 +0800 Subject: [PATCH 6/6] Add eslint exception --- src/botPage/bot/TradeEngine/Proposal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/botPage/bot/TradeEngine/Proposal.js b/src/botPage/bot/TradeEngine/Proposal.js index e2e5202861..b9c70de348 100644 --- a/src/botPage/bot/TradeEngine/Proposal.js +++ b/src/botPage/bot/TradeEngine/Proposal.js @@ -56,6 +56,7 @@ export default Engine => uuid : getUUID(), }, }) + // eslint-disable-next-line consistent-return .catch(e => { if (e && e.name === 'RateLimit') { return Promise.reject(e);