p## Exchange Clients
Exchange clients are references to clients which may be used on a number of platforms in order to allow the user to be able to interface with the relevant trading platform (a.k.a. exchange)
Exchange clients contain a URL which is used to obtain access to the actual client. These clients are made available for
a number of platforms
(e.g. iOS, Mac, Windows, etc...)
Fetching Exchange Clients
Exchange clients may be fetched using the get()
method on the admin.exchangeClient
namespace in the SDK, for example:
import { ExchangeClient } from '@tradrapi/trading-sdk';
const exchangeClient: ExchangeClient = await tradrApi.admin.exchangeClient.get(201);
The get()
method takes a single parameter which is the ID of the exchange client to fetch. The returned value is an
ExchangeClient
object as follows:
interface ExchangeClient {
/** The TradrAPI ID of the entity */
id: number;
/**
* The date the entity was created
* @format date-time
*/
createdAt: string;
/**
* The date the entity was last updated
* @format date-time
*/
updatedAt: string;
/** The links associated with this client */
links?: ExchangeClientLink[];
/** The server associated with this client */
server?: Server;
/** The server id associated with this client */
serverId?: number;
/** The brand associated with this client */
brand?: Brand;
/** The brand id associated with this client */
brandId?: number;
}
Each link in the links
array is an ExchangeClientLink
object as follows:
enum ExchangeClientPlatform {
Windows = 'windows',
Linux = 'linux',
Macos = 'macos',
Ios = 'ios',
Android = 'android',
Web = 'web',
}
interface ExchangeClientLink {
/** The TradrAPI ID of the entity */
id: number;
/**
* The date the entity was created
* @format date-time
*/
createdAt: string;
/**
* The date the entity was last updated
* @format date-time
*/
updatedAt: string;
/** The platform for which the link is valid */
platform: ExchangeClientPlatform;
/** The url to fetch the client itself */
value: string;
}
All exchange clients for a particular project may be fetched at once using the list()
method on
the admin.exchangeClient
namespace:
import { PaginatedResponse, ExchangeClient } from '@tradrapi/trading-sdk';
const exchangeClients: PaginatedResponse<ExchangeClient> =
await tradrApi.admin.exchangeClient.list();
The list()
method optionally accepts a single parameter which is an object containing the following properties:
interface ListExchangeDto {
/**
* The current page being returned.
* @default 1
*/
page?: number;
/**
* Number of records per page.
* @default 10
*/
limit?: number;
/**
* The sort direction of the records being returned
* @default "DESC"
*/
sortDir?: SortDir;
}
With Manager
level authentication it is possible to list all exchange clients across all projects. This is done by
making use of the listAll()
method:
import { PaginatedResponse, ExchangeClient } from '@tradrapi/trading-sdk';
const exchangeClients: PaginatedResponse<ExchangeClient> =
await tradrApi.admin.exchangeClient.listAll();
The listAll()
method optionally accepts a single parameter in the format of the above-mentioned ListExchangeDto
.
Creating An Exchange Client
In order to create a new exchange client, the create()
method on the admin.exchangeClient
namespace may be used:
import { ExchangeClient } from '@tradrapi/trading-sdk';
const result: ExchangeClient = await tradrApi.admin.exchangeClient.create({
serverId: 1,
brandId: 1,
links: [
{
value: 'https://example.com/client/ios/v2/download',
platform: ExchangeClientPlatform.Ios,
},
],
});
This method accepts a CreateExchangeClientDto
as a parameter:
interface CreateExchangeClientDto {
/** The brand ID with which to associate the exchange client */
brandId?: number;
/** The list of links to add to the exchange client */
links?: ExchangeClientLink[];
/** The server ID to which this exchange client belongs */
serverId: number;
}
Updating An Existing Exchange Client
Existing exchange clients can be updated using the update()
method on the admin.exchangeClient
namespace:
import { ExchangeClientPlatform } from '@tradrapi/trading-sdk';
const result: boolean = await tradrApi.admin.exchangeClient.update(201, {
serverId: 3,
linksToAdd: [
{
value: 'https://example.com/client/ios/v2/download',
platform: ExchangeClientPlatform.Ios,
},
],
});
An UpdateExchangeClientDto
is used as the second parameter:
interface UpdateExchangeClientDto {
/** The list of links to add to the exchange client */
linksToAdd?: ExchangeClientLink[];
/** The IDs of the links to remove from the exchange client */
linksToRemove?: number[];
/** The server ID which the exchange client belongs to */
serverId: number;
}
To update only the links of an exchange client, the updateLink()
method may be used:
const result: boolean = await tradrApi.admin.exchangeClient.updateLink(1531, {
value: 'https://example.com/client/ios/v2/download',
platform: ExchangeClientPlatform.Ios,
});
An UpdateExchangeClientLinkDto
is used as the second parameter:
interface UpdateExchangeClientLinkDto {
/** The url to fetch the client itself */
value?: string;
/** The platform for which the link is valid */
platform?: ExchangeClientPlatform;
}
Deleting An Existing Exchange Client
Existing exchange clients can be deleted using the delete()
method on the admin.exchangeClient
namespace:
const result: boolean = await tradrApi.admin.exchangeClient.delete(201);