Skip to content

Commit

Permalink
chore: add useTradingPlatformAccounts to deriv api package
Browse files Browse the repository at this point in the history
  • Loading branch information
thisyahlen-deriv committed Aug 24, 2023
1 parent f6556e7 commit ef573b0
Show file tree
Hide file tree
Showing 3 changed files with 259 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 @@ -4,3 +4,4 @@ export { default as useAuthorize } from './useAuthorize';
export { default as useBalance } from './useBalance';
export { default as useCurrencyConfig } from './useCurrencyConfig';
export { default as useWalletAccountsList } from './useWalletAccountsList';
export { default as useTradingPlatformAccounts } from './useTradingPlatformAccounts';
48 changes: 48 additions & 0 deletions packages/api/src/hooks/useTradingPlatformAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useMemo } from 'react';
import useFetch from '../useFetch';

/** A custom hook that gets the list of created other CFD accounts. */
const useTradingPlatformAccounts = () => {
const { data: derivez_accounts, ...derivez_rest } = useFetch('trading_platform_accounts', {
payload: { platform: 'derivez' },
});
const { data: dxtrade_accounts, ...dxtrade_rest } = useFetch('trading_platform_accounts', {
payload: { platform: 'dxtrade' },
});

/** Adding neccesary properties to derivez accounts */
const modified_derivez_accounts = useMemo(
() =>
derivez_accounts?.trading_platform_accounts?.map(account => ({
...account,
loginid: account.login,
})),
[derivez_accounts?.trading_platform_accounts]
);

/** Adding neccesary properties to dxtrade accounts */
const modified_dxtrade_accounts = useMemo(
() =>
dxtrade_accounts?.trading_platform_accounts?.map(account => ({
...account,
loginid: account.account_id,
})),
[dxtrade_accounts?.trading_platform_accounts]
);

const data = useMemo(
() => ({
dxtrade_accounts: modified_dxtrade_accounts || [],
derivez_accounts: modified_derivez_accounts || [],
}),
[modified_dxtrade_accounts, modified_derivez_accounts]
);

return {
/** List of all created other CFD accounts */
data,
...{ ...derivez_rest, ...dxtrade_rest },
};
};

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

type TPrivateSocketEndpoints = {
trading_platform_accounts: {
request: {
/**
* Must be `1`
*/
trading_platform_accounts: 1;
/**
* Trading platform name
*/
platform: 'dxtrade' | 'mt5' | 'derivez';
/**
* [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: {
/**
* Array containing Trading account objects.
*/
trading_platform_accounts?: {
/**
* ID of Trading account.
*/
account_id?: string;
/**
* Account type.
*/
account_type?: 'demo' | 'real';
/**
* Balance of the Trading account.
*/
balance?: null | number;
/**
* Residence of the MT5 account.
*/
country?: string;
/**
* Currency of the Trading account.
*/
currency?: string;
/**
* Account balance, formatted to appropriate decimal places.
*/
display_balance?: null | string;
/**
* Email address of the MT5 account.
*/
email?: string;
/**
* Account enabled status
*/
enabled?: number;
/**
* Error in MT5 account details.
*/
error?: {
/**
* Error code string.
*/
code?: string;
/**
* Extra information about the error.
*/
details?: {
/**
* MT5 account type.
*/
account_type?: string;
/**
* MT5 account login ID.
*/
login?: string;
/**
* Trade server name of the MT5 account.
*/
server?: string;
/**
* Trade server information.
*/
server_info?: {
/**
* The environment. E.g. Deriv-Server.
*/
environment?: 'Deriv-Demo' | 'Deriv-Server' | 'Deriv-Server-02';
/**
* Geographical location of the server.
*/
geolocation?: {
/**
* Internal server grouping.
*/
group?: string;
/**
* Sever location.
*/
location?: string;
/**
* Sever region.
*/
region?: string;
/**
* Sever sequence.
*/
sequence?: number;
};
/**
* Server id.
*/
id?: string;
};
};
/**
* Error message.
*/
message_to_client?: string;
};
/**
* Group type of the MT5 account, e.g. `demo\svg_financial`
*/
group?: string;
/**
* Landing company shortcode of the Trading account.
*/
landing_company_short?: 'bvi' | 'labuan' | 'malta' | 'maltainvest' | 'svg' | 'vanuatu' | 'seychelles';
/**
* Leverage of the MT5 account (1 to 1000).
*/
leverage?: number;
/**
* Login name used to log in into Trading platform
*/
login?: string;
/**
* Market type
*/
market_type?: 'financial' | 'synthetic' | 'all';
/**
* Name of the owner of the MT5 account.
*/
name?: string;
/**
* Name of trading platform.
*/
platform?: 'dxtrade' | 'mt5';
/**
* Trade server name of the MT5 account.
*/
server?: string;
/**
* Trade server information.
*/
server_info?: {
/**
* The environment. E.g. Deriv-Server.
*/
environment?: 'Deriv-Demo' | 'Deriv-Server' | 'Deriv-Server-02';
/**
* Geographical location of the server.
*/
geolocation?: {
/**
* Internal server grouping.
*/
group?: string;
/**
* Sever location.
*/
location?: string;
/**
* Sever region.
*/
region?: string;
/**
* Sever sequence.
*/
sequence?: number;
};
/**
* Server id.
*/
id?: string;
};
/**
* Sub account type
*/
sub_account_type?: 'financial' | 'financial_stp';
}[];
/**
* Echo of the request made.
*/
echo_req: {
[k: string]: unknown;
};
/**
* Action name of the request made.
*/
msg_type: 'trading_platform_accounts';
/**
* Optional field sent in request to map to response, present only when request contains `req_id`.
*/
req_id?: number;
[k: string]: unknown;
};
};
cashier_payments: {
request: {
/**
Expand Down

0 comments on commit ef573b0

Please sign in to comment.