Migrating Existing Accounts to TradrAPI
A current limitation with TradrAPI is that in order for trading platform accounts to be usable via the TradrAPI, these accounts must have been created in TradrAPI to begin with.
There are scenarios where there are existing MT4/MT5/TradeLocker accounts need to be usable via the TradrAPI.
In order to solve for this problem, TradrAPI has a feature that allows for linking of MT4/MT5/TradeLocker accounts to TradrAPI accounts seamlessly via API.
TradrAPI can be setup to ingest account/trade data from certain remote MetaTrader or TradeLocker servers into its own database.
The data will be lacking the brandUserId
field which is required for TradrAPI to be able to use the data.
In order for the imported accounts to be usable via TradrAPI, the brandUserId
field for each account must be populated.
This can be done by using the claimAccount
method in the SDK under the admin.account
namespace.
Claiming Imported Accounts
A collection of accounts can be claimed in a single request. At a bare minimum the brandUserId
and exchangeAccountId
must be passed for each account to be successfully claimed.
The claimAccount
method takes in an array of objects with the following structure:
[
{
"brandUserId": "25d71ad0-988f-4da9-bba7-b6f7de5cfdef",
"exchangeAccountId": "345667",
"password": "P@ssword!",
"readonlyPassword": "P@ssword!22",
"phonePassword": "AnotherP@ssword!"
},
{
"brandUserId": "675a71a6-4320-11ee-be56-0242ac120002",
"exchangeAccountId": "345669",
}
]
It should be noted that although the password
, readonlyPassword
, and phonePassword
fields are optional,
TradrAPI will not be able to provide any password information for the account if these fields are not provided.
An example of the claimAccount
method in use:
import { AccountLinkResult } from '@tradr/tradr-api-sdk';
const result: AccountLinkResult[] = await tradrApi.admin.account.claimAccount([
{
"brandUserId": "25d71ad0-988f-4da9-bba7-b6f7de5cfdef",
"exchangeAccountId": "345667",
"password": "P@ssword!",
"readonlyPassword": "P@ssword!22",
"phonePassword": "AnotherP@ssword!"
},
{
"brandUserId": "675a71a6-4320-11ee-be56-0242ac120002",
"exchangeAccountId": "345669",
}
]);
The response from this method will be in the form of an array of AccountLinkResult
objects:
interface AccountLinkResult {
/** The tradrAPI account id */
accountId: number;
/** The ID of the account on the relevant trading platform */
exchangeAccountId: string;
/** The brand user id */
brandUserId: string;
/** Whether the account link was completed successfully */
completed: boolean;
}
Some Caveats
- The
exchangeAccountId
field must be unique for each account in the collection. If there are multiple accounts with the same exchangeAccountId, the first will succeed and the rest for that collection entry will fail. - Only accounts belonging to your project can be linked. If you attempt to link an account that does not belong to your project, the request for that account will fail.
- If an account already contains a
brandUserId
value, it cannot be re-claimed or that brandUserId overwritten - The passwords will only be set if the account does not already have a password set. If the account already has a password set, the password will not be overwritten.