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(); 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; diff --git a/src/botPage/bot/TradeEngine/Proposal.js b/src/botPage/bot/TradeEngine/Proposal.js index 05a0fa257e..b9c70de348 100644 --- a/src/botPage/bot/TradeEngine/Proposal.js +++ b/src/botPage/bot/TradeEngine/Proposal.js @@ -56,8 +56,15 @@ export default Engine => uuid : getUUID(), }, }) + // eslint-disable-next-line consistent-return .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])) { diff --git a/src/botPage/bot/TradeEngine/Sell.js b/src/botPage/bot/TradeEngine/Sell.js index 9751e7c181..568fa6a15a 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('Resale of this contract is not offered.')); + error.name = 'SellNotAvailable'; + throw error; + } else { + return Promise.resolve(); + } } const onSuccess = ({ sell: { sold_for: soldFor } }) => {