Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/botPage/bot/Interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion src/botPage/bot/TradeEngine/OpenContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/botPage/bot/TradeEngine/Proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
8 changes: 7 additions & 1 deletion src/botPage/bot/TradeEngine/Sell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }) => {
Expand Down