Skip to content

Commit

Permalink
thisyahlen/chore: add useTradingPlatformAvailableAccounts to deriv api (
Browse files Browse the repository at this point in the history
binary-com#9810)

* chore: add useTradingPlatformAvailableAccounts to deriv api

* fix: type repetition annd fallback

* refactor: repetition

* fix: empty commit

* fix: empty commit

* fix: comment
  • Loading branch information
thisyahlen-deriv committed Aug 29, 2023
1 parent 39ce848 commit 43a4298
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/api/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export { default as useSettings } from './useSettings';
export { default as useTradingAccountsList } from './useTradingAccountsList';
export { default as useTradingPlatformAccounts } from './useTradingPlatformAccounts';
export { default as useWalletAccountsList } from './useWalletAccountsList';
export { default as useTradingPlatformAvailableAccounts } from './useTradingPlatformAvailableAccounts';
38 changes: 38 additions & 0 deletions packages/api/src/hooks/useTradingPlatformAvailableAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useMemo } from 'react';
import useFetch from '../useFetch';

/** @description This hook is used to get all the available MT5 accounts. */
const useTradingPlatformAvailableAccounts = () => {
const { data: mt5_available_accounts, ...rest } = useFetch('trading_platform_available_accounts', {
payload: { platform: 'mt5' },
});

const modified_mt5_available_accounts = useMemo(
() =>
mt5_available_accounts?.trading_platform_available_accounts?.map(account => {
return {
...account,
};
}),
[mt5_available_accounts?.trading_platform_available_accounts]
);

/** This function is used to group the available MT5 accounts by market type. */
const grouped_mt5_available_accounts = useMemo(() => {
return modified_mt5_available_accounts?.reduce((acc, account) => {
const { market_type } = account;
const marketType = market_type as keyof typeof acc;
const marketTypeArray = acc[marketType] || (acc[marketType] = []);
marketTypeArray.push(account);
return acc;
}, {} as Record<string, typeof modified_mt5_available_accounts>);
}, [modified_mt5_available_accounts]);

return {
/** The available MT5 accounts grouped by market type */
data: grouped_mt5_available_accounts,
...rest,
};
};

export default useTradingPlatformAvailableAccounts;
101 changes: 101 additions & 0 deletions packages/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,107 @@ import type {
import type { useMutation, useQuery } from '@tanstack/react-query';

type TPrivateSocketEndpoints = {
trading_platform_available_accounts: {
request: {
/**
* Must be `1`
*/
trading_platform_available_accounts: 1;
/**
* Name of trading platform.
*/
platform: 'mt5' | 'ctrader';
/**
* [Optional] Used to pass data through the websocket, which may be retrieved via the `echo_req` output field.
*/
passthrough?: {
[k: string]: unknown;
};
/**
* [Optional] Used to map request to response.
*/
req_id?: number;
};
response: {
/**
* Available Trading Accounts
*/
trading_platform_available_accounts?:
| {
/**
* A list of Deriv landing companies that can work with this account type
*/
linkable_landing_companies?: ('svg' | 'maltainvest')[];
/**
* The type of market tradable by this account
*/
market_type?: 'financial' | 'gaming' | 'all';
/**
* Landing Company legal name
*/
name?: string;
/**
* Legal requirements for the Landing Company
*/
requirements?: {
/**
* After first deposit requirements
*/
after_first_deposit?: {
/**
* Financial assessment requirements
*/
financial_assessment?: string[];
};
/**
* Compliance requirements
*/
compliance?: {
/**
* Compliance MT5 requirements
*/
mt5?: string[];
/**
* Compliance tax information requirements
*/
tax_information?: string[];
};
/**
* Sign up requirements
*/
signup?: string[];
/**
* Withdrawal requirements
*/
withdrawal?: string[];
};
/**
* Landing Company short code
*/
shortcode?: string;
/**
* Sub account type
*/
sub_account_type?: 'standard' | 'swap_free' | 'stp';
}[]
| null;
/**
* Echo of the request made.
*/
echo_req: {
[k: string]: unknown;
};
/**z
* Action name of the request made.
*/
msg_type: 'trading_platform_available_accounts';
/**
* Optional field sent in request to map to response, present only when request contains `req_id`.
*/
req_id?: number;
[k: string]: unknown;
};
};
trading_platform_accounts: {
request: {
/**
Expand Down

0 comments on commit 43a4298

Please sign in to comment.