Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

fix: fixed error flooging with minimun stake is less than the limit #244

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gulp.task(
gulp.series(done => {
connect.server({
root: 'www',
port: 80,
port: 8080,
livereload: true,
fallback: path.resolve('www/index.html'),
});
Expand All @@ -26,7 +26,7 @@ gulp.task(
gulp.series(done => {
gulp.src('www/index.html').pipe(
open({
uri: 'http://localhost:80/',
uri: 'http://localhost:8080/',
})
);
done();
Expand Down
42,515 changes: 21,257 additions & 21,258 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"del": "^6.0.0",
"dotenv-webpack": "^7.0.3",
"es6-plato": "^1.2.3",
"eslint": "^4.14.0",
"eslint": "npm:eslint-nullish-coalescing@^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-binary": "^1.0.2",
"eslint-config-prettier": "^2.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/botPage/bot/CliTools.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Observer from '../../common/utils/observer';
import Interpreter from './Interpreter';
import TicksService from '../common/TicksService';
import api from '../view/deriv/api';
import api from '../view/deriv/api_base';

export const createScope = () => {
const observer = new Observer();
Expand Down
23 changes: 20 additions & 3 deletions src/botPage/bot/Interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createScope } from './CliTools';
import Interface from './Interface';
import { clone } from '../common/clone';
import { observer as globalObserver } from '../../common/utils/observer';
import api_base from '../view/deriv/api_base';

/* eslint-disable func-names, no-underscore-dangle */
JSInterpreter.prototype.takeStateSnapshot = function() {
Expand All @@ -24,12 +25,22 @@ const unrecoverable_errors = [
'CustomLimitsReached',
'OfferingsValidationError',
'InvalidCurrency',
'ContractBuyValidationError',
'NotDefaultCurrency',
'PleaseAuthenticate',
'FinancialAssessmentRequired',
'PositiveIntegerExpected',
'OptionError',
'IncorrectPayoutDecimals',
'IncorrectStakeDecimals',
'NoMFProfessionalClient',
'AuthorizationRequired',
'InvalidToken',
'DailyLossLimitExceeded',
'InputValidationFailed',
'ClientUnwelcome',
'PriceMoved',
'ContractCreationFailure',
];

const botInitialized = bot => bot && bot.tradeEngine.options;
Expand All @@ -38,7 +49,10 @@ const shouldRestartOnError = (bot, error_name = '') =>
!unrecoverable_errors.includes(error_name) && botInitialized(bot) && bot.tradeEngine.options.shouldRestartOnError;

const shouldStopOnError = (bot, error_name = '') => {
const stop_errors = ['SellNotAvailableCustom', 'ContractBuyValidationError', 'CustomInvalidProposal'];
const stop_errors = [
'SellNotAvailableCustom',
'CustomInvalidProposal',
];
if (stop_errors.includes(error_name) && botInitialized(bot)) {
return true;
}
Expand Down Expand Up @@ -152,7 +166,6 @@ export default class Interpreter {
const { initArgs, tradeOptions } = this.bot.tradeEngine;
this.terminateSession();
this.init();
this.$scope.observer.register('Error', onError);
this.bot.tradeEngine.init(...initArgs);
this.bot.tradeEngine.start(tradeOptions);
this.revert(this.startState);
Expand Down Expand Up @@ -181,9 +194,13 @@ export default class Interpreter {
terminateSession() {
this.stopped = true;
this.isErrorTriggered = false;

globalObserver.emit('bot.stop');
globalObserver.setState({ isRunning: false });

const { ticksService } = this.$scope;
ticksService.unsubscribeFromTicksService();

api_base.clearSubscriptions();
}

stop() {
Expand Down
4 changes: 3 additions & 1 deletion src/botPage/bot/TradeEngine/Balance.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { roundBalance } from '../../common/tools';
import { info } from '../broadcast';
import { observer as globalObserver } from '../../../common/utils/observer';
import api_base from '../../view/deriv/api_base';

export default Engine =>
class Balance extends Engine {
observeBalance() {
this.api.onMessage().subscribe(({ data }) => {
const subscription = api_base.api.onMessage().subscribe(({ data }) => {
if (data?.error?.code) {
return;
}
Expand All @@ -18,6 +19,7 @@ export default Engine =>
info({ accountID: this.accountInfo?.loginid, balance: balance_str });
}
});
api_base.pushSubscription(subscription);
}
// eslint-disable-next-line class-methods-use-this
getBalance(type) {
Expand Down
6 changes: 4 additions & 2 deletions src/botPage/bot/TradeEngine/OpenContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { doUntilDone } from '../tools';
import { contractStatus, contractSettled, contract as broadcastContract } from '../broadcast';
import { sell, openContractReceived } from './state/actions';
import { observer } from '../../../common/utils/observer';
import api_base from '../../view/deriv/api_base';

const AFTER_FINISH_TIMEOUT = 5;

export default Engine =>
class OpenContract extends Engine {
observeOpenContract() {
this.api.onMessage().subscribe(({ data }) => {
const subscriptions = api_base.api.onMessage().subscribe(({ data }) => {
if (data?.error?.code) {
return;
}
Expand Down Expand Up @@ -49,6 +50,7 @@ export default Engine =>
}
}
});
api_base.pushSubscription(subscriptions);
}

waitForAfter() {
Expand All @@ -64,7 +66,7 @@ export default Engine =>
this.contractId = contract_id;

doUntilDone(() =>
this.api.send({
api_base.api.send({
proposal_open_contract: 1,
contract_id,
})
Expand Down
13 changes: 9 additions & 4 deletions src/botPage/bot/TradeEngine/Proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { translate } from '../../../common/i18n';
import { tradeOptionToProposal, doUntilDone } from '../tools';
import { proposalsReady, clearProposals } from './state/actions';
import { TrackJSError } from '../../view/logger';
import api_base from '../../view/deriv/api_base';

export default Engine =>
class Proposal extends Engine {
Expand Down Expand Up @@ -72,7 +73,7 @@ export default Engine =>
requestProposals() {
Promise.all(
this.proposalTemplates.map(proposal =>
doUntilDone(() => this.api.send(proposal)).catch(error => {
doUntilDone(() => api_base.api.send(proposal)).catch(error => {
// We intercept ContractBuyValidationError as user may have specified
// e.g. a DIGITUNDER 0 or DIGITOVER 9, while one proposal may be invalid
// the other is valid. We will error on Purchase rather than here.
Expand All @@ -88,11 +89,14 @@ export default Engine =>
throw error;
})
)
).catch(e => this.$scope.observer.emit('Error', e));
).catch(({ error = {} }) => {
this.$scope.observer.emit('Error', { name: error.code, ...error });
sandeep-deriv marked this conversation as resolved.
Show resolved Hide resolved
return { name: error.code, ...error };
});
}

observeProposals() {
this.api.onMessage().subscribe(({ data }) => {
const subscription = api_base.api.onMessage().subscribe(({ data }) => {
if (data?.error?.code) {
return;
}
Expand All @@ -108,6 +112,7 @@ export default Engine =>
}
}
});
api_base.pushSubscription(subscription);
}

unsubscribeProposals() {
Expand All @@ -129,7 +134,7 @@ export default Engine =>
return Promise.resolve();
}

return doUntilDone(() => this.api.forget(proposal.id)).then(() =>
return doUntilDone(() => api_base.api.forget(proposal.id)).then(() =>
removeForgetProposalById(proposal.id)
);
})
Expand Down
3 changes: 2 additions & 1 deletion src/botPage/bot/TradeEngine/Purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { contractStatus, info, notify } from '../broadcast';
import { purchaseSuccessful } from './state/actions';
import { BEFORE_PURCHASE } from './state/constants';
import GTM from '../../../common/gtm';
import api_base from '../../view/deriv/api_base';

let delay_index = 0;
let purchase_reference;
Expand Down Expand Up @@ -55,7 +56,7 @@ export default Engine =>
currency,
});

const action = () => this.api.send({ buy: proposal.id, price: proposal.ask_price });
const action = () => api_base.api.send({ buy: proposal.id, price: proposal.ask_price });

if (!this.options.timeMachineEnabled) {
return doUntilDone(action).then(onSuccess);
Expand Down
3 changes: 2 additions & 1 deletion src/botPage/bot/TradeEngine/Sell.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { translate } from '../../../common/i18n';
import { recoverFromError, doUntilDone } from '../tools';
import { contractStatus, notify } from '../broadcast';
import { DURING_PURCHASE } from './state/constants';
import api_base from '../../view/deriv/api_base';

let delay_index = 0;

Expand Down Expand Up @@ -29,7 +30,7 @@ export default Engine =>
};

const action = () =>
this.api
api_base.api
.sellContract(this.contractId, 0)
.then(response => {
onSuccess(response.sell.sold_for);
Expand Down
20 changes: 7 additions & 13 deletions src/botPage/bot/TradeEngine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import thunk from 'redux-thunk';
import { durationToSecond } from '../../../common/utils/tools';
import { translate } from '../../..//common/i18n';
import { createError } from '../../common/error';
import { doUntilDone } from '../tools';
import { expectInitArg, expectTradeOptions } from '../sanitize';
import Proposal from './Proposal';
import Total from './Total';
Expand All @@ -16,6 +15,7 @@ import rootReducer from './state/reducers';
import * as constants from './state/constants';
import { start } from './state/actions';
import { observer as globalObserver } from '../../../common/utils/observer';
import api_base from '../../view/deriv/api_base';

const watchBefore = store =>
watchScope({
Expand Down Expand Up @@ -102,18 +102,12 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
this.checkProposalReady();
}

loginAndGetBalance(token) {
if (this.token === token) return Promise.resolve();
doUntilDone(() => this.api.authorize(token)).catch(e => this.$scope.observer.emit('Error', e));
return new Promise(resolve =>
this.api.expectResponse('authorize').then(({ authorize }) => {
this.accountInfo = authorize;
this.token = token;
resolve();
})
).catch(error => {
globalObserver.emit('Error', error);
});
loginAndGetBalance() {
return new Promise(resolve => {
this.accountInfo = api_base.account_info;
this.token = api_base.token;
resolve();
})
}

getContractDuration() {
Expand Down
6 changes: 4 additions & 2 deletions src/botPage/common/ChartTicksService.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { observer as globalObserver } from '../../common/utils/observer';
import { doUntilDone } from '../bot/tools';
import api_base from '../view/deriv/api_base';
import TicksService from './TicksService';

export default class ChartTicksService extends TicksService {
observe() {
this.api.onMessage().subscribe(({ data }) => {
const subscription = api_base.api.onMessage().subscribe(({ data }) => {
if (data?.error?.code) {
return;
}
Expand All @@ -30,6 +31,7 @@ export default class ChartTicksService extends TicksService {
}
}
});
api_base.pushSubscription(subscription);
}

requestTicks(options) {
Expand All @@ -44,7 +46,7 @@ export default class ChartTicksService extends TicksService {
};

return new Promise((resolve, reject) => {
doUntilDone(() => this.api.send(request_object))
doUntilDone(() => api_base.api.send(request_object))
.then(r => {
if (style === 'ticks') {
this.updateTicksAndCallListeners(symbol, r);
Expand Down
Loading