• Overview
  • Reviews
  • Comments
  • What's new

MetaApi REST and websocket API for MT5

What is MetaApi?

MetaApi is a powerful MetaTrader API including MetaTrader REST API and MetaTrader websocket API.

Note: Demo download will not do anything useful as the EA can not be executed in the strategy tester. Please do not blame us for this miss as this is an MQL limitation.

Note: Due to MQL marketplace restrictions we can make only self-hosted MT5 version available via marketplace. For MT4 support or cloud-based version please contact me via direct message.

MetaApi provides a comprehensive set of tools via standard-based REST and Websocket APIs for interacting with the MetaTrader platform in order to create variety of classic trading applications using virtually any programming language. Primary anticipated use cases of MetaApi are creating automated trading strategies, monitoring your trading and streaming real-time quotes from MetaTrader terminal.

Features

Features supported:

  • read terminal state, such as account information, positions and open orders
  • read trading history (deals and history orders)
  • execute trades
  • read market data such as contract specifications and current prices

Note: one of the features we implemented in our API is ability to use MetaTrader terminal as market data server (e.g. for strategy backtesting). However MQL marketplace restrictions forced us to remove this feature from this EA. Please contact me directly if you want to use this feature.

The features described above are available for use using the RESTful API or socket.io WebSocket server. We choose socket.io protocol for our Websocket server because socket.io clients are available on most popular programming languages.

Although you can trade via REST API, the primary intended use of REST API is creating trade monitoring applications. For automatic trading we recommend using Websocket server since it provides lower latencies and real time synchronization with terminal state.

API documentation

We created detailed API docs for you, they are available here: https://metaapi.cloud/docs/client/

Client SDKs

The list of supported client SDKs is presented on the https://metaapi.cloud/sdks page. Feel free to contact me if you need support for other languages. Please note since the API is standard-based it should be pretty straightforward for you to implement API client in the language of your choice.

Accessing the API

In order to access API you will need to supply authorization token and MT account id. These values are both printed in the MetaTrader terminal Experts log on EA startup, so that you can copy them from there. (see attached screenshot)

REST API endpoint - https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai

Websocket API endpoint - https://mt-client-api-v1.agiliutrade.agiliumtrade.ai/ws

EA configuration parameters

EA configuration is straightforward and parameters are explained on the EA inputs screen (see attached screenshot).

When configuring the EA you need to supply the email and password you want to use in order to access the MetaApi API. Please create a MetaApi API password different from your MT password. The password must contain uppercase, lowercase letters and digits and be at least 8 characters long. 

DST setting - defines an algorithm which will be used to detect MetaTrader time timezone. Supported values are EU (which means that your broker will switch time according to EET timezone) and NY (which means that your broker will switch time according to America/New_York timezone).

Synchronization mode - automatic or user. Select automatic if you do not need to know real-time state of your MetaTrader terminal on the client side and plan to use REST or websocket request-response API only. Select user if you need it (e.g. for coding an automated strategy). See https://metaapi.cloud/docs/client/websocket/synchronizationMode/ for more information about this feature. 

Please make sure to allow WebRequests to the following URLs (see attached screenshot):

  • mt5.network.agiliumtrade.agiliumtrade.ai 
  • https://mt-provisioning-api-v1.agiliumtrade.agiliumtrade.ai
The access to the above URLs is required for providing API access and generating API access credentials correspondingly.
Recommended products
Filter:
No reviews
Version 1.7 2020.09.05
- added more fields to support latest MetaAPI updates
- stability fixes for initial synchronization
- ability to trade during synchronization
Version 1.6 2020.08.09
- improved synchronisation stability on accounts with big history
- added option to specify separate magic (expert id) value for each trade
Version 1.5 2020.08.01
- fixed a bug in async trading feature - sometimes trade request was responding with RETCODE_PLACED instead of actual response code
- minor bugfixes and stability improvements
Version 1.4 2020.07.21
- partial support for stop limit orders
- async trading support
Version 1.3 2020.06.07
Bugfixes for a stability issue when broker is disconnected
Version 1.2 2020.05.27
Added platform field to pending order model to match documentation
Version 1.1 2020.05.27
Performance improvements for accounts with big trading history (over 10K trades)