Skip to content

Read order book#

About#

Retrieves current order boook for a symbol. MT4 accounts do not support this API

For more information see Async api documentation

Request#

In order to retrieve latest order book, your application needs to emit request event with the following payload.

Name Type Required Description
type string Yes request type, must be getBook if you want to retrieve a current order book
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
symbol string Yes symbol (e.g. currency pair or an index)
keepSubscription boolean if set to true, the account will get a long-term subscription to symbol market data. Long-term subscription means that on subsequent calls you will get updated value faster. If set to false or not set, the subscription will be set to expire in 12 minutes.

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
book object Yes latest order book. Order book schema: MetatraderBook

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: '865d3a4d-3803-486d-bdf3-a85679d9fad2',
    type: 'getBook',
    requestId: '60440b68-f098-4f9e-b9d0-ec7149979ec9',
    symbol: 'AUDNZD'
};

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": "60440b68-f098-4f9e-b9d0-ec7149979ec9",
  "accountId": "865d3a4d-3803-486d-bdf3-a85679d9fad2",
  "book": {
    "symbol": "AUDNZD",
    "time": "2020-04-07T03:45:00.000Z",
    "brokerTime": "2020-04-07 06:45:00.000",
    "book": [
      {
        "type": "BOOK_TYPE_SELL",
        "price": 1.05309,
        "volume": 5.67
      },
      {
        "type": "BOOK_TYPE_BUY",
        "price": 1.05297,
        "volume": 3.45
      }
    ]
  }
}