This document is a high-level specification for the Devexperts DXtrade XT Amazon SQS API. The API complements the "DX Notification API" with reliable message delivery via Amazon Simple Queue Service.
The API is aimed to support a "B2B" integration when all the updates about events happening with accounts in the platform are streamed over a reliable channel without explicit subscription.
Every type of messages is sent to a separate pre-configured Amazon SQS queue. The following types of messages are supported:
A list of pre-configured Amazon SQS queues for the required message types will be provided by DXtrade XT when setting up the system. It is possible to configure multiple Amazon SQS queues for a single message type. In this case, all messages will be sent to each queue.
The DXtrade XT Amazon SQS API encodes its messages in JSON (application/json).
Please, see SQS Developer Guide
Amazon provides AWS SDK for many popular programming languages.
AWS SDK requires the following properties:
| Name | Description |
|---|---|
| Endpoint | The endpoint with which the SDK should communicate |
| Region | The region with which the SDK should communicate |
| Access Key ID | The AWS access key, used to identify the user interacting with services |
| Secret Access Key | The AWS secret access key, used to authenticate the user interacting with services |
| Account ID | The AWS account id associated with this credentials identity |
These properties will be provided by DXtrade when setting up the system.
Example
String endpoint = ...;
String region = ...;
String accessKeyId = ...;
String secretAccessKey = ...;
String accountId = ...;
SqsClient sqsClient = SqsClient.builder()
.endpointOverride(URI.create(endpoint))
.region(Region.of(region))
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.builder()
.accessKeyId(accessKeyId)
.secretAccessKey(secretAccessKey)
.accountId(accountId)
.build()
)
).build();
String queueName = ...;
String queueUrl = sqsClient.getQueueUrl(
GetQueueUrlRequest.builder()
.queueName(queueName)
.build()
).queueUrl();
List<Message> messages = sqsClient.receiveMessage(
ReceiveMessageRequest.builder()
.queueUrl(queueUrl)
.maxNumberOfMessages(10)
.build()
).messages();
// Process messages here
// ...
List<DeleteMessageBatchRequestEntry> entries = messages.stream()
.map(message -> DeleteMessageBatchRequestEntry.builder()
.id(message.messageId())
.receiptHandle(message.receiptHandle())
.build()
).toList();
sqsClient.deleteMessageBatch(
DeleteMessageBatchRequest.builder()
.queueUrl(queueUrl)
.entries(entries)
.build()
);
Amazon charges for SQS API requests. DXtrade XT Amazon SQS API uses FIFO queues. Please, see Amazon SQS pricing for details.
The DXtrade XT Amazon SQS API attempts to maintain backward compatibility with the clients provided the following:
For example, when dealing with JSON representation, clients should avoid coupling their logic with the current JSON structure. This way, adding new fields won't disrupt their application's functionality, allowing adding new data into resources without breaking client systems.
| Change | New Version Released? |
|---|---|
| Addition of a new data field to data representation | |
| Changing the logical meaning of a field | ✔️ |
| Removing a field | ✔️ |
| Changing the default representation, currency units etc. | ✔️ |
| Addition of new independent requests | |
| New business rules and/or application flow | ✔️ |
| New default values for optional request parameters or fields | ✔️ |
The DXtrade XT Amazon SQS API supports the notion of entity versions. Each business entity, like an account, is assigned a version number that increases monotonically with any changes. By comparing these versions, one can determine the sequence of updates: the entity with the most recent changes will have the highest version number.
The Amazon SQS API is based around asynchronous JSON-encoded messages sent from the DXtrade XT system to the Amazon SQS. Each message contains the following fields:
| Field | Value | Type |
|---|---|---|
| type | Type of the message that indicates its purpose (e.g. subscription or account update notifications) | String, required |
| timestamp | Timestamp in UTC when the message has been sent. This timestamp may differ from the business timestamp of the message payload | Timestamp, required |
| payload | Field representing the message payload specific for message type as a separate object. | Object, required |
Also, for account metrics compact format is supported, where fields names are present in a short form and zero fields are not present.
Example
{
"type": "SomeMessageType",
"timestamp": "2024-08-06T08:30:05.469Z",
"payload": {
...
}
}
The API allows to retrieve updates of account portfolio for all accounts. A portfolio contains information about open positions and working orders on an account.
This API allows to retrieve only updated fields of Account Portfolio instead of the whole chunk of data with each message. It makes the messages significantly smaller which improves performance and allows not to lose data on accounts with large amount of orders and executions.
Account Portfolio Incremental Updates are fired whenever following changes are made with the account:
The API sends only updated orders, positions and executions whenever any change on account is made. It means, that you will see every update only once, including non-closed orders and positions, and those updates should be applied in the order of account version. All the other fields like balances or account code are always sent on any update, same as for Account Portfolio queue. Client may use account version in the portfolio message to track the order of updates.
The system sends an initial snapshot of all account portfolios and then starts streaming updates as soon anything changes on the account.
The following message is used to send account portfolio incremental updates:
| Field | Value | Type |
|---|---|---|
| type | AccountPortfolioIncrementalUpdates | String, required |
| timestamp | Timestamp in UTC when the message has been sent | Timestamp, required |
| payload | List of accounts portfolio incremental updates | Portfolio list |
{
"type": "AccountPortfolioIncrementalUpdates",
"timestamp": "2022-07-27T14:50:30.238Z",
"payload": {
"portfolios": [...]
}
}
This API allows to retrieve instrument updates. Updates are sent sequentially whenever new instruments are created, existing instruments are deleted, or any instrument fields are updated.
The system sends an initial snapshot of the data for all instruments and then starts sending updates.
The following message is used to send instruments:
| Field | Value | Type |
|---|---|---|
| type | Instruments | String, required |
| timestamp | Timestamp in UTC when the message has been sent | Timestamp, required |
| payload | List of instrument data | Instrument list, required |
{
"type": "Instruments",
"timestamp": "2022-07-27T14:50:30.238Z",
"payload": {
"instruments": [...]
}
}
The API allows to retrieve updates of account metrics (such as PnL and margin) for all accounts. Updates are sent periodically (with server-configured frequency).
For accounts without trading activity, metrics updates are sent less frequently (this frequency is also configured on the server).
For account metrics 'compact' message format is supported, where fields names are present in a short form and zero fields are not present. It will be enabled by default in one of the upcoming releases.
The following message is used to send account metrics:
| Field | Value | Type |
|---|---|---|
| type | AccountMetrics | String, required |
| timestamp | Timestamp in UTC when the message has been sent | Timestamp, required |
| payload | Account metrics | Account metrics list , required |
The following message is used to send account metrics:
| Field | Value | Type |
|---|---|---|
| t | AM | String, required |
| ts | Timestamp in UTC when the message has been sent | Timestamp, required |
| p | Account metrics | Compact account metrics list, required |
{
"type": "AccountMetrics",
"timestamp": "2022-07-27T14:50:30.238Z",
"payload": {
"metrics": [...]
},
"type":"AccountMetrics",
"timestamp":"2026-04-28T15:14:15.007Z",
"payload": {
"metrics":[
{
"account":"default:dma1acc3_demo",
"version":126,
"equity":9999686.18,
"balance":9998138.52,
"openPL":75.485,
"initialMargin":1412.08,
"maintenanceMargin":1392.89,
"availableFunds":9998274.10,
"availableBalanceForWithdrawal":9998293.29,
"maintenanceExcess":9998293.29,
"dayClosedPl":0.0,
"netLiquidation":9999686.18,
"openPositionsCount":2,
"openOrdersCount":0,
"maxDrawdown":"NaN",
"autoLiquidationPeak":"NaN",
"drawdownMode":"REAL_TIME_TRAILING",
"trailingDrawdownDelta":2000.0,
"staticMaxDrawdown":0.0,
"positions":[
{
"version":126,
"symbol":"MSFT",
"markPrice":425.5,
"dayClosedPl":0.0,
"avgOpenPrice":405.4717,
"openPl":60.085,
"initialMargin":1276.5,
"maintenanceMargin":1148.85,
"quantity":3.0
},
{
"version":126,
"symbol":"AAPL",
"markPrice":271.16,
"dayClosedPl":0.0,
"avgOpenPrice":255.76,
"openPl":15.4,
"initialMargin":135.58,
"maintenanceMargin":244.04,
"quantity":1.0
}
]
}
]
}
}
The API allows to retrieve various 'events' regarding the account, such as liquidations or margin calls. Events are sent sequentially whenever any of these changes happen with the account:
The following message is used to send account events:
| Field | Value | Type |
|---|---|---|
| type | AccountEvents | String, required |
| timestamp | Timestamp in UTC when the message has been sent | Timestamp, required |
| payload | Account events | Account events list, required |
{
"type": "AccountEvents",
"timestamp": "2022-07-27T14:50:30.238Z",
"payload": {
"accountEvents": [...]
}
}
The API allows to retrieve cash transfers (such as deposits, withdrawals and PnL settlement) on all accounts.
The following message is used to send cash transfers:
| Field | Value | Type |
|---|---|---|
| type | CashTransfers | String, required |
| timestamp | Timestamp in UTC when the message has been sent | Timestamp, required |
| payload | Cash transfers | Cash transfers list, required |
{
"type": "CashTransfers",
"timestamp": "2022-07-27T14:50:30.238Z",
"payload": {
"cashTransfers": [...]
}
}