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

perf: removed individual POC calls made against contracts, added glob… #7707

Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 0 additions & 1 deletion packages/bot-skeleton/src/scratch/dbot-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class DBotStore extends DBotStoreInterface {
this.is_dark_mode_on = store.is_dark_mode_on || false;
this.client = store.client;
this.flyout = store.flyout;
this.populateConfig = store.populateConfig;
this.toolbar = store.toolbar;
this.toolbox = store.toolbox;
this.save_modal = store.save_modal;
Expand Down
1 change: 1 addition & 0 deletions packages/bot-skeleton/src/services/api/api-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class APIBase {
subscribe() {
doUntilDone(() => this.api.send({ balance: 1, subscribe: 1 }));
doUntilDone(() => this.api.send({ transaction: 1, subscribe: 1 }));
doUntilDone(() => this.api.send({ proposal_open_contract: 1, subscribe: 1 }));
}

getActiveSymbols = async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getRoundedNumber } from '@deriv/shared';
import { sell, openContractReceived } from './state/actions';
import { contractStatus, contract as broadcastContract } from '../utils/broadcast';
import { doUntilDone } from '../utils/helpers';
import DBotStore from '../../../scratch/dbot-store';
import { api_base } from '../../api/api-base';

export default Engine =>
Expand Down Expand Up @@ -51,29 +49,6 @@ export default Engine =>
});
}

subscribeToOpenContract(contract_id = this.contractId) {
this.contractId = contract_id;
const request_object = {
proposal_open_contract: 1,
contract_id,
subscribe: 1,
};

doUntilDone(() => api_base.api.send(request_object))
.then(data => {
const { populateConfig } = DBotStore.instance;
populateConfig(data.proposal_open_contract);
this.openContractId = data.proposal_open_contract.id;
})
.catch(error => {
if (error.error.code !== 'AlreadySubscribed') {
doUntilDone(() => api_base.api.send(request_object)).then(
response => (this.openContractId = response.proposal_open_contract.id)
);
}
});
}

setContractFlags(contract) {
const { is_expired, is_valid_to_sell, is_sold, entry_tick } = contract;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ export default Engine =>
}

renewProposalsOnPurchase() {
this.unsubscribeProposals().then(() => this.requestProposals());
}

clearProposals() {
this.data.proposals = [];
this.store.dispatch(clearProposals());
this.requestProposals();
}

requestProposals() {
Expand Down Expand Up @@ -98,11 +95,7 @@ export default Engine =>
const subscription = api_base.api.onMessage().subscribe(response => {
if (response.data.msg_type === 'proposal') {
const { passthrough, proposal } = response.data;
if (
proposal &&
this.data.proposals.findIndex(p => p.id === proposal.id) === -1 &&
!this.data.forget_proposal_ids.includes(proposal.id)
) {
if (proposal && this.data.proposals.findIndex(p => p.id === proposal.id) === -1) {
// Add proposals based on the ID returned by the API.
this.data.proposals.push({ ...proposal, ...passthrough });
this.checkProposalReady();
Expand All @@ -112,31 +105,6 @@ export default Engine =>
api_base.pushSubscription(subscription);
}

unsubscribeProposals() {
const { proposals } = this.data;
const removeForgetProposalById = forget_proposal_id =>
(this.data.forget_proposal_ids = this.data.forget_proposal_ids.filter(id => id !== forget_proposal_id));

this.clearProposals();

return Promise.all(
proposals.map(proposal => {
if (!this.data.forget_proposal_ids.includes(proposal.id)) {
this.data.forget_proposal_ids.push(proposal.id);
}

if (proposal.error) {
removeForgetProposalById(proposal.id);
return Promise.resolve();
}

return doUntilDone(() => api_base.api.forget(proposal.id)).then(() => {
removeForgetProposalById(proposal.id);
});
})
);
}

checkProposalReady() {
// Proposals are considered ready when the proposals in our memory match the ones
// we've requested from the API, we determine this by checking the passthrough of the response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default Engine =>
buy,
});

this.subscribeToOpenContract(buy.contract_id);
this.contractId = buy.contract_id;
this.store.dispatch(purchaseSuccessful());
this.renewProposalsOnPurchase();
delayIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
this.data = {
contract: {},
proposals: [],
forget_proposal_ids: [],
};
this.store = createStore(rootReducer, applyMiddleware(thunk));
}
Expand Down
3 changes: 1 addition & 2 deletions packages/bot-web-ui/src/stores/app-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,12 @@ export default class AppStore {
const { handleFileChange } = load_modal;
const { toggleStrategyModal } = quick_strategy;
const { startLoading, endLoading } = blockly_store;
const { populateConfig, setContractUpdateConfig } = summary_card;
const { setContractUpdateConfig } = summary_card;

this.dbot_store = {
is_mobile: false,
client,
flyout,
populateConfig,
toolbar,
save_modal,
startLoading,
Expand Down
9 changes: 0 additions & 9 deletions packages/bot-web-ui/src/stores/summary-card-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default class SummaryCardStore {
getLimitOrder: action.bound,
onBotContractEvent: action.bound,
onChange: action.bound,
populateConfig: action.bound,
populateContractUpdateConfig: action.bound,
setContractUpdateConfig: action.bound,
updateLimitOrder: action.bound,
Expand Down Expand Up @@ -141,14 +140,6 @@ export default class SummaryCardStore {
this.validateProperty(name, this[name]);
}

populateConfig(contract_info) {
this.contract_info = contract_info;

if (this.is_multiplier && contract_info.contract_id && contract_info.limit_order) {
this.populateContractUpdateConfig(this.contract_info);
}
}

populateContractUpdateConfig(response) {
const contract_update_config = getContractUpdateConfig(response);

Expand Down
27 changes: 12 additions & 15 deletions packages/bot-web-ui/src/stores/transactions-store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { action, computed, observable, reaction, makeObservable } from 'mobx';
import { formatDate, isEnded } from '@deriv/shared';
import { formatDate, isEnded, isBot } from '@deriv/shared';
import { log_types } from '@deriv/bot-skeleton';
import { transaction_elements } from '../constants/transactions';
import { getStoredItemsByKey, getStoredItemsByUser, setStoredItemsByKey } from '../utils/session-storage';
Expand Down Expand Up @@ -150,12 +150,6 @@ export default class TransactionsStore {
}
);

// Attempt to load cached transactions on client loginid change.
const disposeClientLoginIdListener = reaction(
() => client.loginid,
() => (this.elements = getStoredItemsByUser(this.TRANSACTION_CACHE, client.loginid, []))
);

// User could've left the page mid-contract. On initial load, try
// to recover any pending contracts so we can reflect accurate stats
// and transactions.
Expand All @@ -166,7 +160,6 @@ export default class TransactionsStore {

return () => {
disposeTransactionElementsListener();
disposeClientLoginIdListener();
disposeRecoverContracts();
};
}
Expand Down Expand Up @@ -213,13 +206,17 @@ export default class TransactionsStore {
const { ws, core } = this.root_store;
const positions = core.portfolio.positions;

ws.authorized.subscribeProposalOpenContract(contract_id, response => {
this.is_called_proposal_open_contract = true;
if (!response.error) {
const { proposal_open_contract } = response;
this.updateResultsCompletedContract(proposal_open_contract);
}
});
// TODO: the idea is to remove the POC calls completely
// but adding this check to prevent making POC calls only for bot as of now
if (!isBot()) {
ws.authorized.subscribeProposalOpenContract(contract_id, response => {
this.is_called_proposal_open_contract = true;
if (!response.error) {
const { proposal_open_contract } = response;
this.updateResultsCompletedContract(proposal_open_contract);
}
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user is on bot platform the core POC should not be called, it is causing duplicate calls.


if (!this.is_called_proposal_open_contract) {
if (!this.elements.length) {
Expand Down