Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit ba95a57

Browse files
authored
Merge pull request #1534 from aaron-binary/bot-restarting-incorrectly
Bot restarting incorrectly
2 parents 0c12d0c + df2bd48 commit ba95a57

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

src/botPage/bot/Interpreter.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ const botInitialized = bot => bot && bot.tradeEngine.options;
1717
const botStarted = bot => botInitialized(bot) && bot.tradeEngine.tradeOptions;
1818
const shouldRestartOnError = (bot, errorName = '') =>
1919
!unrecoverableErrors.includes(errorName) && botInitialized(bot) && bot.tradeEngine.options.shouldRestartOnError;
20+
21+
const shouldStopOnError = (bot, errorName = '') => {
22+
const stopErrors = ['SellNotAvailable'];
23+
if (stopErrors.includes(errorName) && botInitialized(bot)) {
24+
return true;
25+
}
26+
return false;
27+
};
28+
2029
const timeMachineEnabled = bot => botInitialized(bot) && bot.tradeEngine.options.timeMachineEnabled;
2130

2231
export default class Interpreter {
@@ -94,11 +103,20 @@ export default class Interpreter {
94103
if (this.stopped) {
95104
return;
96105
}
106+
107+
if (shouldStopOnError(this.bot, e.name)) {
108+
globalObserver.emit('ui.log.error', e.message);
109+
$('#stopButton').trigger('click');
110+
this.stop();
111+
return;
112+
}
113+
97114
this.isErrorTriggered = true;
98115
if (!shouldRestartOnError(this.bot, e.name) || !botStarted(this.bot)) {
99116
reject(e);
100117
return;
101118
}
119+
102120
globalObserver.emit('Error', e);
103121
const { initArgs, tradeOptions } = this.bot.tradeEngine;
104122
this.terminateSession();

src/botPage/bot/TradeEngine/OpenContract.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,20 @@ export default Engine =>
9090
}
9191
}
9292
setContractFlags(contract) {
93-
const { is_expired: isExpired, is_valid_to_sell: isValidToSell, is_sold: isSold } = contract;
93+
const {
94+
is_expired: isExpired,
95+
is_valid_to_sell: isValidToSell,
96+
is_sold: isSold,
97+
entry_tick: entryTick,
98+
} = contract;
9499

95100
this.isSold = Boolean(isSold);
96101

97102
this.isSellAvailable = !this.isSold && Boolean(isValidToSell);
98103

99104
this.isExpired = Boolean(isExpired);
105+
106+
this.hasEntryTick = Boolean(entryTick);
100107
}
101108
expectedContractId(contractId) {
102109
return this.contractId && contractId === this.contractId;

src/botPage/bot/TradeEngine/Proposal.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ export default Engine =>
5656
uuid : getUUID(),
5757
},
5858
})
59+
// eslint-disable-next-line consistent-return
5960
.catch(e => {
60-
if (e.error.error.code === 'ContractBuyValidationError') {
61+
if (e && e.name === 'RateLimit') {
62+
return Promise.reject(e);
63+
}
64+
65+
const errorCode = e.error && e.error.error && e.error.error.code;
66+
67+
if (errorCode === 'ContractBuyValidationError') {
6168
const { uuid } = e.error.echo_req.passthrough;
6269

6370
if (!this.data.hasIn(['forgetProposals', uuid])) {

src/botPage/bot/TradeEngine/Sell.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ export default Engine =>
1717
}
1818

1919
if (!this.isSellAtMarketAvailable()) {
20-
throw Error(translate('Sell is not available'));
20+
if (this.hasEntryTick) {
21+
const error = new Error(translate('Resale of this contract is not offered.'));
22+
error.name = 'SellNotAvailable';
23+
throw error;
24+
} else {
25+
return Promise.resolve();
26+
}
2127
}
2228

2329
const onSuccess = ({ sell: { sold_for: soldFor } }) => {

0 commit comments

Comments
 (0)