Skip to content

Read history orders by position#

About#

Returns the history of completed orders for a specific position id

For more information see Async api documentation

Request#

In order to retrieve history of closed orders by position, your application needs to emit request event with the following payload.

Name Type Required Description
type string Yes request type, must be getHistoryOrdersByPosition if you want to retrieve history of closed orders by position
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 RPC
positionId string Yes position id

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
historyOrders array Yes History orders with requested position id for a specified MetaTrader account. Response schema: Array<MetatraderOrder>
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.new-york.agiliumtrade.ai', {
    path: '/ws',
    reconnection: false,
    query: {
        'auth-token': 'token'
    }
});

const request = {
    accountId: '23ccdd23-0b8a-400d-9aba-0129de365ba9',
    type: 'getHistoryOrdersByPosition',
    requestId: '12ac1999-930e-4b3f-808b-6cbe403d2291',
    positionId: '46214692'
};

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": "12ac1999-930e-4b3f-808b-6cbe403d2291",
  "historyOrders": [
    {
      "clientId": "TE_GBPUSD_7hyINWqAlE",
      "currentPrice": 1.261,
      "currentVolume": 0,
      "doneTime": "2020-04-15T02:45:06.521Z",
      "doneBrokerTime": "2020-04-15 05:45:06.521",
      "id": "46214692",
      "magic": 1000,
      "platform": "mt5",
      "positionId": "46214692",
      "state": "ORDER_STATE_FILLED",
      "symbol": "GBPUSD",
      "time": "2020-04-15T02:45:06.260Z",
      "brokerTime": "2020-04-15 05:45:06.260",
      "type": "ORDER_TYPE_BUY",
      "volume": 0.07
    }
  ],
  "synchronizing": false,
  "accountId": "23ccdd23-0b8a-400d-9aba-0129de365ba9"
}