Skip to content

Synchronize#

About#

Requests the terminal to start synchronization process.

For more information see AsyncApi documentation

Request#

In order to start synchronization process, your application needs to emit request event with the following payload somewhere after receiving synchronization event of the authenticated type.

Name Type Required Description
type string Yes request type, must be synchronize if you want to start synchronization process
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
startingDealTime string(datetime) from what date to start deal synchronization from. If not specified, then all history deals will be downloaded. Datetime in ISO format
startingHistoryOrderTime string(datetime) from what date to start synchronizing history orders from. If not specified, the entire order history will be downloaded. Datetime in ISO format
specificationsMd5 string specifications data md5 hash value in a hexadecimal string format
positionsMd5 string positions data md5 hash value in a hexadecimal string format
ordersMd5 string orders data md5 hash value in a hexadecimal string format
version number synchronization protocol version number. Should be either 1 or 2.
specificationsHashes array specifications hashes known by client
positionsHashes array positions hashes known by client
ordersHashes array orders hashes known by client

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

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: '865d3a4d-3803-486d-bdf3-a85679d9fad2',
  type: 'synchronize',
  requestId: '57bfbc9f-108d-4131-a300-5f7d9e69c11b',
  startingDealTime: '2019-01-13T10:29:26.000Z',
  startingHistoryOrderTime: '2019-01-13T10:29:26.000Z'
};

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

socket.on('synchronization', data => {
  console.log(data);
  if (data.type === 'authenticated') {
    request.requestId = uuid.v4();
    socket.emit('request', request);
  }
});

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

Response example#

{
  "type":"response",
  "requestId":"04cc8b8f-f509-4d78-8154-ccaa148d3b62",
  "accountId":"23ccdd23-0b8a-400d-9aba-0129de365ba9"
}