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.
- 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.
We created detailed API docs for you, they are available here: https://metaapi.cloud/docs/client/
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):
- stability fixes for initial synchronization
- ability to trade during synchronization
- added option to specify separate magic (expert id) value for each trade
- minor bugfixes and stability improvements
- async trading support