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/Include
subdirectory of your MetaTrader 4 profile directory, merging the folder contents. - Copy mql-zmq/Library/MT4/ into the
MQL4/Libraries
subdirectory of your MetaTrader 4 profile directory, merging the folder contents. - Launch MetaEditor, open
MQL4/Scripts/ZeroMQ_Server.mq4
in your MetaTrader 4 profile directory and compile it. - Start MetaTrader 4 and add the
ZeroMQ Server
script 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
REQ
socket with appropriate send/receive timeouts and options. - Connect the
REQ
socket to the server'sREP
socket. - Perform the following sequence any number of times:
- Construct an API request.
- Send the request to the
REQ
socket. - Receive a JSON-formatted string response from the
REQ
socket.
- 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.