Skip to content

Commit

Permalink
Merge pull request #137 from rupato-deriv/Rupato/BOT-2405/Feature--up…
Browse files Browse the repository at this point in the history
…date-standlone-with-qs

Rupato/BOT-2405/Update standalone with quick strategy changes and endpoint url
  • Loading branch information
shafin-deriv authored Nov 25, 2024
2 parents fa0f17e + 24399df commit f769123
Show file tree
Hide file tree
Showing 37 changed files with 8,420 additions and 60 deletions.
5 changes: 3 additions & 2 deletions src/components/layout/header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import clsx from 'clsx';
import { observer } from 'mobx-react-lite';
import { standalone_routes } from '@/components/shared';
import { generateOAuthURL, standalone_routes } from '@/components/shared';
import Button from '@/components/shared_ui/button';
import useActiveAccount from '@/hooks/api/account/useActiveAccount';
import { useApiBase } from '@/hooks/useApiBase';
Expand Down Expand Up @@ -68,7 +69,7 @@ const AppHeader = observer(() => {
<Button
tertiary
onClick={() => {
window.location.assign(getOauthURL());
window.location.replace(generateOAuthURL());
}}
>
<Localize i18n_default_text='Log in' />
Expand Down
15 changes: 15 additions & 0 deletions src/components/shared/utils/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LocalStorageConstants, LocalStorageUtils, URLUtils } from '@deriv-com/utils';
import { isStaging } from '../url/helpers';

export const APP_IDS = {
Expand Down Expand Up @@ -140,3 +141,17 @@ export const getDebugServiceWorker = () => {

return false;
};

export const generateOAuthURL = () => {
const { getOauthURL } = URLUtils;
const oauth_url = getOauthURL();
const original_url = new URL(oauth_url);
const configured_server_url = (LocalStorageUtils.getValue(LocalStorageConstants.configServerURL) ||
original_url.hostname) as string;

const valid_server_urls = ['green.derivws.com', 'red.derivws.com', 'blue.derivws.com'];
if (!valid_server_urls.includes(configured_server_url)) {
original_url.hostname = configured_server_url;
}
return original_url.toString() || oauth_url;
};
29 changes: 29 additions & 0 deletions src/external/bot-skeleton/scratch/accumulators-proposal-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,32 @@ export const handleProposalRequestForAccumulators = instance => {
};
window.Blockly.accumulators_request = proposal_request;
};

export const requestProposalForQS = (input_values, ws) => {
const { amount, currency, symbol, growth_rate, limit_order } = input_values;
const { take_profit } = limit_order;

const proposal_request = {
...DEFAULT_PROPOSAL_REQUEST,
amount,
currency,
symbol,
growth_rate,
subscribe: undefined,
limit_order: {
take_profit,
},
};

return ws
?.send(proposal_request)
.then(response => {
if (response.error) {
return Promise.reject(response.error);
}
return response;
})
.catch(error => {
throw error;
});
};
1 change: 1 addition & 0 deletions src/external/bot-skeleton/scratch/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const modifyBlocklyWorkSpaceContextMenu = () => {
cleanWorkspace: localize('Clean up Blocks'),
collapseWorkspace: localize('Collapse Blocks'),
expandWorkspace: localize('Expand Blocks'),
workspaceDelete: localize('Delete All Blocks'),
};

Object.keys(items_to_localize).forEach(item_id => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCurrencyDisplayCode } from '@/components/shared';
import { localize } from '@deriv-com/translations';
import { config } from '../../../../constants/config';
import { modifyContextMenu } from '../../../utils';
import { excludeOptionFromContextMenu, modifyContextMenu } from '../../../utils';

const description = localize(
'Your contract is closed automatically when your profit is more than or equals to this amount. This block can only be used with the accumulator trade type.'
Expand Down Expand Up @@ -56,6 +56,8 @@ window.Blockly.Blocks.accumulator_take_profit = {
}
},
customContextMenu(menu) {
const menu_items = [localize('Enable Block'), localize('Disable Block')];
excludeOptionFromContextMenu(menu, menu_items);
modifyContextMenu(menu);
},
restricted_parents: ['trade_definition_accumulator'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ window.Blockly.Blocks.trade_definition_tradeoptions = {
setCurrency() {
const currency_field = this.getField('CURRENCY_LIST');
const { currency } = DBotStore.instance.client;
currency_field.setText(getCurrencyDisplayCode(currency));
currency_field?.setText(getCurrencyDisplayCode(currency));
},
restricted_parents: ['trade_definition'],
getRequiredValueInputs() {
Expand Down
23 changes: 15 additions & 8 deletions src/external/bot-skeleton/scratch/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,11 @@ const all_context_menu_options = [
localize('Download Block'),
];

// Need for later
// const deleteLocaleText = localize("Delete");
// const blocksLocaleText = localize("Blocks");
// const deleteBlocksLocaleText = localize("Delete Blocks");
// const deleteBlocksLocalePattern = new RegExp(`^${deleteLocaleText} \\d+ ${blocksLocaleText}$`);
const deleteBlocksLocaleText = localize('Delete Block');
const deleteAllBlocksLocaleText = localize('Delete All Blocks');

export const modifyContextMenu = (menu, add_new_items = []) => {
console.log(menu);
const include_items = [...common_included_items, ...add_new_items];
include_items.forEach(item => {
menu.push({
Expand All @@ -671,9 +669,18 @@ export const modifyContextMenu = (menu, add_new_items = []) => {
});

for (let i = 0; i < menu.length; i++) {
const localized_text = localize(menu[i].text);
if (all_context_menu_options.includes(localized_text)) {
menu[i].text = localized_text;
const menu_text = menu[i]?.text?.toLowerCase();
if (menu_text?.includes('delete')) {
if (menu_text.includes('block') && !menu_text.includes('blocks')) {
menu[i].text = deleteBlocksLocaleText;
} else {
menu[i].text = deleteAllBlocksLocaleText;
}
} else {
const localized_text = localize(menu[i].text);
if (all_context_menu_options.includes(localized_text)) {
menu[i].text = localized_text;
}
}
}
};
Expand Down
15 changes: 13 additions & 2 deletions src/external/bot-skeleton/services/api/contracts-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,16 @@ export default class ContractsFor {
return trade_type_options;
};

async getTradeTypesForQuickStrategy(symbol) {
async getTradeTypesForQuickStrategy(symbol, trade_type = '') {
const trade_type_options = [];
const filtered_trade_type_categories = [];
if (trade_type === 'ACCU') {
trade_type_options.push({
text: 'Buy',
value: 'ACCU',
});
return trade_type_options;
}
const market = await this.getMarketBySymbol(symbol);
const submarket = await this.getSubmarketBySymbol(symbol);
const trade_type_categories = await this.getTradeTypeCategories(market, submarket, symbol);
Expand Down Expand Up @@ -618,7 +625,11 @@ export default class ContractsFor {

getContractTypes = trade_type => {
const { opposites } = config();
const categories = opposites[trade_type.toUpperCase()].map(opposite => ({
let trade_type_value = trade_type;
if (trade_type_value === 'ACCU') {
trade_type_value = 'accumulator';
}
const categories = opposites[trade_type_value.toUpperCase()].map(opposite => ({
value: Object.keys(opposite)[0],
text: Object.values(opposite)[0],
}));
Expand Down
8 changes: 4 additions & 4 deletions src/external/bot-skeleton/services/tradeEngine/trade/Sell.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default Engine =>
).then(proposal_open_contract_response => {
const { proposal_open_contract } = proposal_open_contract_response;

if (proposal_open_contract.status !== 'sold') {
if (!proposal_open_contract.is_sold) {
return Promise.reject(sell_error);
}

Expand All @@ -99,9 +99,9 @@ export default Engine =>
// Restart buy/sell on error is enabled, don't recover from sell error.
if (!this.options.timeMachineEnabled) {
// eslint-disable-next-line no-promise-executor-return
return doUntilDone(sellContractAndGetContractInfo, errors_to_ignore).then(sell_response =>
onContractSold(sell_response)
);
return doUntilDone(sellContractAndGetContractInfo, errors_to_ignore)
.then(sell_response => onContractSold(sell_response))
.catch(error => error);
}

// If above checkbox not checked, try to recover from sell error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export const shouldThrowError = (error, errors_to_ignore = []) => {
'OpenPositionLimitExceeded',
];
updateErrorMessage(error);
const is_ignorable_error = errors_to_ignore.concat(default_errors_to_ignore).includes(error?.error?.code);
const is_ignorable_error = errors_to_ignore
.concat(default_errors_to_ignore)
.includes(error?.error?.code ?? error?.name);

return !is_ignorable_error;
};
Expand All @@ -237,7 +239,7 @@ export const recoverFromError = (promiseFn, recoverFn, errors_to_ignore, delay_i
return;
}
recoverFn(
error?.error?.code,
error?.error?.code ?? error?.name,
() =>
new Promise(recoverResolve => {
const getGlobalTimeouts = () => globalObserver.getState('global_timeouts') ?? [];
Expand Down
Loading

0 comments on commit f769123

Please sign in to comment.