Provides a remote interface and high-level API for MetaTrader 4 via ZeroMQ sockets.
See API for supported operations.
- Copy metatrader4 into your MetaTrader 4 profile directory, merging the folder contents.
- Copy mql-zmq/Include/ into the
MQL4/Includesubdirectory of your MetaTrader 4 profile directory, merging the folder contents. - Copy mql-zmq/Library/MT4/ into the
MQL4/Librariessubdirectory of your MetaTrader 4 profile directory, merging the folder contents. - Launch MetaEditor, open
MQL4/Scripts/ZeroMQ_Server.mq4in your MetaTrader 4 profile directory and compile it. - Start MetaTrader 4 and add the
ZeroMQ Serverscript to any chart (chart symbol does not matter). The server begins listening for client requests and responds synchronously.
The default listening port is TCP/28282 but is configurable in the script parameters popup in the MetaTrader terminal,
along with other parameters such as socket timeouts. If Windows Defender Firewall is running, you must forward the port.
Typical client usage:
- Create a ZeroMQ context and a
REQsocket with appropriate send/receive timeouts and options. - Connect the
REQsocket to the server'sREPsocket. - Perform the following sequence any number of times:
- Construct an API request.
- Send the request to the
REQsocket. - Receive a JSON-formatted string response from the
REQsocket.
- Close the socket connection and destroy the ZeroMQ context.
It is recommended to use one of the following client libraries to abstract away these details:
The REQ-REP socket connection enforces a strict request-response cycle and may deadlock if connection is lost.
The client libraries use ZMQ_REQ_RELAXED and ZMQ_REQ_CORRELATE socket options to prevent this in most cases.
If a response is dropped, the client may want to catch the exception and check whether or not the operation was
successful.
If you want to make changes to the server implementation, it's useful to setup a local dev environment.
