Skip to content

Read deals by time range#

About#

Returns history deals with for a specific time range

For more information see Async api documentation

Request#

In order to retrieve history deals by time range, your application needs to emit request event with the following payload.

Name Type Required Description
type string Yes request type, must be getDealsByTimeRange if you want to retrieve deals by time range
accountId string Yes MetaTrader account id. You can retrieve account id from Web application after you add your MetaTrader account to our platform. The account id can also be obtained via Provisioning API
requestId string Yes request id which your application must supply. Request id must be unique during an API connection
application string MetaApi application id. Default is MetaApi
startTime string(datetime) Yes start of time range, inclusive (ISO format)
endTime string(datetime) Yes end of time range, exclusive (ISO format)
offset number pagination offset, default: 0, min: 0
limit number pagination limit, default: 1000, min: 1, max: 1000

Response#

After executing your request the API server will emit response event with the following payload.

Name Type Required Description
type string Yes The value of this field will be response in the response to the above request
requestId string Yes request id the response relates to
accountId string Yes account id specified in the request
deals array Yes History deals with requested time range for a specified MetaTrader account. Response schema: Array<MetatraderDeal>
synchronizing boolean Yes If this field is true, this means that the data synchronization with the terminal is not yet complete and the data may not be accurate

Code example#

import ioClient from 'socket.io-client';

const socket = ioClient('https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai', {
    path: '/ws',
    reconnection: false,
    query: {
        'auth-token': 'token'
    }
});

const request = {
    accountId: '23ccdd23-0b8a-400d-9aba-0129de365ba9',
    type: 'getDealsByTimeRange',
    requestId: '6abde6ec-c38d-4989-9cdc-5ebb4f5ecb57',
    startTime: '2020-04-15T00:30:00Z',
    endTime: '2020-04-15T01:00:00Z'
};

socket.on('connect', () => {
    socket.emit('request', request);
});

socket.on('response', response => {
  console.log(response);
});

socket.on('processingError', err => {
  console.error(err);
});

Response example#

{
  "type": "response",
  "requestId": "6abde6ec-c38d-4989-9cdc-5ebb4f5ecb57",
  "deals": [
    {
      "clientId": "TE_AUDUSD_SF1IDj3D9g",
      "commission": -0.25,
      "entryType": "DEAL_ENTRY_IN",
      "id": "33221930",
      "magic": 1000,
      "platform": "mt5",
      "orderId": "46201068",
      "positionId": "46201068",
      "price": 0.64255,
      "profit": 0,
      "swap": 0,
      "symbol": "AUDUSD",
      "time": "2020-04-15T00:30:04.552Z",
      "brokerTime": "2020-04-15 03:30:04.552",
      "type": "DEAL_TYPE_BUY",
      "volume": 0.07
    }
  ],
  "synchronizing": false,
  "accountId": "23ccdd23-0b8a-400d-9aba-0129de365ba9"
}