Subscribe to market data#
About#
Subscribes on market data of specified symbol
For more information see Async api documentation
Request#
In order to subscribe on market data, your application needs to emit request
event with the following payload.
Name | Type | Required | Description |
---|---|---|---|
type | string | Yes | request type, must be subscribeToMarketData if you want subscribe to market data |
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 | |
symbol | string | Yes | symbol (e.g. currency pair or an index) |
subscriptions | Array |
list of market data subscriptions to create or update |
MarketDataSubscription fields#
Name | Type | Required | Description |
---|---|---|---|
type | string | Yes | subscription type, one of quotes, candles, ticks, or marketDepth |
timeframe | string | when subscription type is candles, defines the timeframe according to which the candles must be generated. Allowed values for MT5 are 1m, 2m, 3m, 4m, 5m, 6m, 10m, 12m, 15m, 20m, 30m, 1h, 2h, 3h, 4h, 6h, 8h, 12h, 1d, 1w, 1mn. Allowed values for MT4 are 1m, 5m, 15m 30m, 1h, 4h, 1d, 1w, 1mn | |
intervalInMilliseconds | integer | defines how frequently the terminal will stream data to client. If not set, then the value configured in account will be used |
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 |
After response, synchronization events symbols
and prices
will come.
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: 'subscribeToMarketData',
requestId: '60440b68-f098-4f9e-b9d0-ec7149979ec9',
symbol: 'EURUSD'
};
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"
}