Read orders#
About#
Returns open orders for a specified MetaTrader account
For more information see Async api documentation
Request#
In order to retrieve open orders, your application needs to emit request
event with the following payload.
Name | Type | Required | Description |
---|---|---|---|
type | string | Yes | request type, must be getOrders if you want to retrieve open orders |
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 |
application | string | MetaApi application id. Default is RPC | |
requestId | string | Yes | request id which your application must supply. Request id must be unique during an API connection |
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 |
orders | array | Yes | Open orders for a specified MetaTrader account. Response schema: Array<MetatraderOrder> |
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.new-york.agiliumtrade.ai', {
path: '/ws',
reconnection: false,
query: {
'auth-token': 'token'
}
});
const request = {
accountId: '865d3a4d-3803-486d-bdf3-a85679d9fad2',
type: 'getOrders',
requestId: 'dbeba74d-da8b-4b7f-88e5-5731b367af12'
};
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": "dbeba74d-da8b-4b7f-88e5-5731b367af12",
"orders": [
{
"id": "46871284",
"type": "ORDER_TYPE_BUY_LIMIT",
"state": "ORDER_STATE_PLACED",
"symbol": "AUDNZD",
"magic": 123456,
"platform": "mt5",
"time": "2020-04-20T08:38:58.270Z",
"brokerTime": "2020-04-20 11:38:58.270",
"openPrice": 1.03,
"currentPrice": 1.05206,
"volume": 0.01,
"currentVolume": 0.01,
"comment": "COMMENT2"
}
],
"accountId": "865d3a4d-3803-486d-bdf3-a85679d9fad2"
}