Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "sandeep/fix: dbot-slowness issue v2" #7407

Merged
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
2 changes: 0 additions & 2 deletions packages/bot-skeleton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
"immutable": "^3.8.2",
"localforage": "^1.9.0",
"lz-string": "^1.4.4",
"mobx": "^6.6.1",
"mobx-react": "^7.5.1",
"redux": "^4.0.1",
"redux-thunk": "^2.2.0",
"scratch-blocks": "0.1.0-prerelease.20200917235131",
Expand Down
8 changes: 0 additions & 8 deletions packages/bot-skeleton/src/scratch/dbot-store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { reaction } from 'mobx';
import { api_base } from '../services/api/api-base';

class DBotStoreInterface {
// TODO here we are suppose to define an interface and implement fields of DBotStore.
handleFileChange = () => {
Expand Down Expand Up @@ -30,11 +27,6 @@ class DBotStore extends DBotStoreInterface {
this.handleFileChange = store.handleFileChange;
this.startLoading = store.startLoading;
this.endLoading = store.endLoading;

reaction(
() => this.client.loginid,
() => api_base.createNewInstance(this.client.loginid)
);
}

static setInstance(store) {
Expand Down
10 changes: 2 additions & 8 deletions packages/bot-skeleton/src/scratch/dbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { observer as globalObserver } from '../utils/observer';
import ApiHelpers from '../services/api/api-helpers';
import Interpreter from '../services/tradeEngine/utils/interpreter';
import { setColors } from './hooks/colours';
import { api_base } from '../services/api/api-base';

class DBot {
constructor() {
Expand Down Expand Up @@ -98,7 +97,7 @@ class DBot {
window.dispatchEvent(new Event('resize'));
window.addEventListener('dragover', DBot.handleDragOver);
window.addEventListener('drop', e => DBot.handleDropOver(e, handleFileChange));
api_base.init();

// disable overflow
el_scratch_div.parentNode.style.overflow = 'hidden';
resolve();
Expand Down Expand Up @@ -135,7 +134,7 @@ class DBot {
}

this.interpreter = Interpreter();
api_base.setIsRunning(true);

this.interpreter.run(code).catch(error => {
globalObserver.emit('Error', error);
this.stopBot();
Expand Down Expand Up @@ -227,7 +226,6 @@ class DBot {
* that trade will be completed first to reflect correct contract status in UI.
*/
stopBot() {
api_base.setIsRunning(false);
if (this.interpreter) {
this.interpreter.stop();
}
Expand All @@ -243,10 +241,6 @@ class DBot {
}
}

terminateConnection = () => {
api_base.terminate();
};

/**
* Unselects any selected block before running the bot.
*/
Expand Down
132 changes: 0 additions & 132 deletions packages/bot-skeleton/src/services/api/api-base.js

This file was deleted.

16 changes: 0 additions & 16 deletions packages/bot-skeleton/src/services/api/appId.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,3 @@ export const generateDerivApiInstance = () => {
});
return deriv_api;
};

export const getLoginId = () => {
const login_id = localStorage.getItem('active_loginid');
if (login_id && login_id !== 'null') return login_id;
return null;
};

export const getToken = () => {
const active_loginid = getLoginId();
const client_accounts = JSON.parse(localStorage.getItem('client.accounts')) || undefined;
const active_account = (client_accounts && client_accounts[active_loginid]) || {};
return {
token: active_account?.token || undefined,
account_id: active_loginid || undefined,
};
};
49 changes: 18 additions & 31 deletions packages/bot-skeleton/src/services/api/ticks_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Map } from 'immutable';
import { historyToTicks, getLast } from 'binary-utils';
import { doUntilDone, getUUID } from '../tradeEngine/utils/helpers';
import { observer as globalObserver } from '../../utils/observer';
import { api_base } from './api-base';

const parseTick = tick => ({
epoch: +tick.epoch,
Expand Down Expand Up @@ -40,7 +39,8 @@ const updateCandles = (candles, ohlc) => {
const getType = isCandle => (isCandle ? 'candles' : 'ticks');

export default class TicksService {
constructor() {
constructor(api) {
this.api = api;
this.ticks = new Map();
this.candles = new Map();
this.tickListeners = new Map();
Expand All @@ -60,13 +60,23 @@ export default class TicksService {

if (!this.active_symbols_promise) {
this.active_symbols_promise = new Promise(resolve => {
this.pipSizes = api_base.pip_sizes;
resolve(this.pipSizes);
this.getActiveSymbols().then(active_symbols => {
this.pipSizes = active_symbols
.reduce((s, i) => s.set(i.symbol, +(+i.pip).toExponential().substring(3)), new Map())
.toObject();
resolve(this.pipSizes);
});
});
}
return this.active_symbols_promise;
}

getActiveSymbols = async () => {
await this.api.expectResponse('authorize');
const active_symbols = await this.api.send({ active_symbols: 'brief' });
return active_symbols.active_symbols;
};

request(options) {
const { symbol, granularity } = options;

Expand All @@ -79,6 +89,7 @@ export default class TicksService {
if (style === 'candles' && this.candles.hasIn([symbol, Number(granularity)])) {
return Promise.resolve(this.candles.getIn([symbol, Number(granularity)]));
}

return this.requestStream({ ...options, style });
}

Expand Down Expand Up @@ -152,7 +163,7 @@ export default class TicksService {
...(tickSubscription || []),
];

Promise.all(subscription.map(id => doUntilDone(() => api_base.api.forget(id))));
Promise.all(subscription.map(id => doUntilDone(() => this.api.forget(id))));

this.subscriptions = new Map();
}
Expand Down Expand Up @@ -184,7 +195,7 @@ export default class TicksService {
}

observe() {
const subscription = api_base.api.onMessage().subscribe(({ data }) => {
this.api.onMessage().subscribe(({ data }) => {
if (data.msg_type === 'tick') {
const { tick } = data;
const { symbol, id } = tick;
Expand All @@ -207,7 +218,6 @@ export default class TicksService {
}
}
});
api_base.pushSubscription(subscription);
}

requestStream(options) {
Expand Down Expand Up @@ -250,7 +260,7 @@ export default class TicksService {
style,
};
return new Promise((resolve, reject) => {
doUntilDone(() => api_base.api.send(request_object), [], api_base)
doUntilDone(() => this.api.send(request_object))
.then(r => {
if (style === 'ticks') {
const ticks = historyToTicks(r.history);
Expand All @@ -268,27 +278,4 @@ export default class TicksService {
.catch(reject);
});
}

forget = subscription_id => {
if (subscription_id) {
api_base.api.forget(subscription_id);
}
};

unsubscribeFromTicksService() {
if (this.ticks_history_promise) {
const { stringified_options } = this.ticks_history_promise;
const { symbol = '' } = JSON.parse(stringified_options);
if (symbol) {
this.forget(this.subscriptions.getIn(['tick', symbol]));
}
}
if (this.candles_promise) {
const { stringified_options } = this.candles_promise;
const { symbol = '' } = JSON.parse(stringified_options);
if (symbol) {
this.forget(this.subscriptions.getIn(['candle', symbol]));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { getFormattedText } from '@deriv/shared';
import { info } from '../utils/broadcast';
import DBotStore from '../../../scratch/dbot-store';
import { api_base } from '../../api/api-base';

let balance_string = '';

export default Engine =>
class Balance extends Engine {
observeBalance() {
const subscription = api_base.api.onMessage().subscribe(({ data }) => {
this.api.onMessage().subscribe(({ data }) => {
if (data.msg_type === 'balance') {
const {
balance: { balance: b, currency },
Expand All @@ -19,7 +18,6 @@ export default Engine =>
info({ accountID: this.accountInfo.loginid, balance: balance_string });
}
});
api_base.pushSubscription(subscription);
}

// eslint-disable-next-line class-methods-use-this
Expand Down
Loading