Prices#
About#
Notifies of a change in the prices.
For more information see AsyncApi documentation
Description#
This event is emitted by MetaApi in following situations:
- upon initial synchronization
- whenever a consumer subscribes to a market data
- whenever prices changes
The message below can be received from the synchronization
event.
Name | Type | Required | Description |
---|---|---|---|
type | string | Yes | The value of this field will be prices |
synchronizationId | string | No | Id of the synchronization request |
prices | array | Prices array. Response schema: Array<MetatraderSymbolPrice> | |
candles | array | Candles array. Response schema: Array<MetatraderCandle> | |
ticks | array | Ticks array. Response schema: Array<MetatraderTick> | |
books | array | Order book array. Response schema: Array<MetatraderBook> | |
equity | number | Yes | account liquidation value |
margin | number | Yes | margin used |
freeMargin | number | Yes | free margin |
marginLevel | number | margin level calculated as % of equity/margin | |
accountId | string | Yes | account id specified in the request |
sequenceNumber | number | Yes | an ordinal number of the packet. Increases by 1 with each new packet. Starts with 0 in every new session. Can be used to check for packet loss during synchronization. |
sequenceTimestamp | number | Yes | an ordinal number of packets, but this field is increased by a random number in each new packet. Always increases regardless of the session. |
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'
};
socket.on('connect', () => {
socket.emit('request', request);
});
socket.on('synchronization', data => {
console.log(data);
});
socket.on('processingError', err => {
console.error(err);
});
An example of a synchronization payload:
{
"type": "prices",
"synchronizationId": "57bfbc9f-108d-4131-a300-5f7d9e69c11b",
"prices": [
{
"symbol": "AUDNZD",
"bid": 1.05916,
"ask": 1.05927,
"profitTickValue": 0.602,
"lossTickValue": 0.60203,
"time": "2020-04-07T03:45:23.345Z",
"brokerTime": "2020-04-07 06:45:23.345"
}
],
"equity": 7306.649913200001,
"margin": 184.1,
"freeMargin": 7120.22,
"marginLevel": 3967.58283542,
"accountId": "865d3a4d-3803-486d-bdf3-a85679d9fad2"
}