This adapter allows for seamless integration between the Nautilus Trader and MetaTrader 5, providing capabilities for market data retrieval, order execution, and account management through the MetaTrader 5 Terminal using either IPC for Windows, RPyC for Linux, or Sockets for EA (suitable for streaming).
This extension supports two different client modes:
-
IPC Mode (Using the MetaTrader Python library) 📦
- Directly communicates with MetaTrader 5 via the official Python API which uses
IPC(Inter-Process Communication). - Best for local integration without additional network overhead but does not support real-time updates.
For Linux systems 🐧
- Uses
RPyC(Remote Python Call) to bridge between a Linux environment and MT5 running inside Wine, it usesIPCunder the hood. - Ideal for automated trading setups on non-Windows environments.
- Directly communicates with MetaTrader 5 via the official Python API which uses
-
Socket Mode (Using MetaTrader EA) 🌐
- Connects to the MetaTrader 5 Expert Advisor (EA) via a custom socket server.
- Enables external programs (Python, JavaScript, C++) to interact with MT5.
- Supports real-time updates.
To install the MetaTrader 5 Adapter, follow these steps:
-
Clone the repository:
git clone https://github.com/quantspub/nautilus_mt5.git
-
Navigate to the project directory:
cd /nautilus_mt5 -
Pull the Docker image:
docker pull docker.io/quantspub/metatrader5-terminal:latest
-
Install the required Python packages:
poetry install
To run the MetaTrader 5 Adapter, execute the following commands:
cd examplescp .env.example .envpython connect_with_dockerized_terminal.pyNOTE: Make sure to configure the .env file properly before running the script or the Docker image.
- Ensure Docker is installed and running on your machine.
- Clone the repository and navigate to the project directory.
- Pull the Docker image for MetaTrader 5 Terminal.
- Install the required Python packages using Poetry.
- Navigate to the
examplesdirectory. - Copy the
.env.examplefile to.envand configure it with your MetaTrader 5 credentials. - Run the
connect_with_dockerized_terminal.pyscript to start the adapter.
The project structure is organized as follows:
nautilus_mt5/
├── examples/
│ ├── connect_with_dockerized_terminal.py
│ ├── .env.example
│ └── ...
├── nautilus_mt5/ # Source code for the adapter
├── tests/ # Test cases
├── MQL5/ # MQL5 scripts and EA module
├── docs/ # Documentation files
├── pyproject.toml # Poetry configuration
├── poetry.lock # Dependency lock file
├── build.py # Build script
├── .gitignore # Git ignore file
├── LICENSE # License file
├── README.md # Project documentation
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes. 🐛
- Fork the repository. 🍴
- Create a new branch:
git checkout -b feature-branch
- Make your changes. ✏️
- Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature-branch
- Open a pull request. 📥
This project is licensed under the MIT License. See the LICENSE file for details.
If you encounter any issues or have questions, feel free to open an issue on the GitHub repository or contact the author via email at quantspub@gmail.com