Standalone Windows Installation
Relevant source files
The following files were used as context for generating this wiki page:
The Standalone Windows Installation refers to the deployment of the mt5linux bridge server directly on a Windows environment where the MetaTrader 5 (MT5) terminal is natively installed. While the project is titled mt5linux, it functions by establishing a gRPC bridge. This specific installation path allows Windows hosts to act as the server-side provider, exposing the official MT5 Python API to Linux-based clients via a high-performance RPC framework.
This installation method is an alternative to the recommended Docker-based setup. It is particularly useful for users who already have a configured MT5 environment on Windows or are running MT5 via Wine and wish to expose its functionality to remote or local Linux clients. The standalone bridge imports the Windows-specific MetaTrader5 module and wraps its functions into gRPC services.
Sources: README.md:120-130, mt5linux/main.py:42-50
Architecture and Execution Flow
The standalone installation operates as a gRPC server. It acts as an intermediary that translates gRPC requests from a client (sync or async) into local calls to the native MetaTrader 5 Python library.
Execution Path
When the package is invoked with the --server flag, the entry point in __main__.py performs a lazy import of the bridge module. This design prevents the application from attempting to import the Windows-only MetaTrader5 library when running in client mode on Linux, which would otherwise cause an immediate ImportError.
The following diagram illustrates the initialization and request flow for a standalone Windows server:
Sources: mt5linux/main.py:53-73, mt5linux/bridge.py
Installation and Configuration
To set up the standalone server, the mt5linux package must be installed on the Windows machine hosting the MetaTrader 5 terminal.
Installation Command
pip install mt5linux
Sources: README.md:123-124
Server Launch Options
The bridge server can be started using the Python module syntax. It supports several command-line arguments to customize its behavior, such as binding to specific network interfaces or adjusting the worker thread pool size.
| Option | Description | Default |
|---|---|---|
--server, -s | Starts the gRPC bridge server mode | N/A |
--host HOST | Bind address for the server | 0.0.0.0 |
--port PORT, -p | TCP port to listen on | 50051 |
--workers N | Number of worker threads in the gRPC pool | 10 |
--debug, -d | Enables verbose debug logging | False |
Sources: mt5linux/main.py:29-37, mt5linux/settings.py:127-130
Environment Configuration
The bridge server utilizes Pydantic-based settings for configuration. While command-line arguments provide immediate overrides, the server can also be configured via environment variables prefixed with MT5_ or through a .env file.
# Example configuration defaults in mt5linux/settings.py
server_host: str = "0.0.0.0"
server_port: int = 8001 # Internal alignment, CLI defaults to 50051
thread_pool_size: int = 10
grpc_max_message_size: int = 50 * 1024 * 1024 # 50MB
Sources: mt5linux/settings.py:127-145, mt5linux/settings.py:19-25
Component Interaction
The standalone server relies on mt5linux/bridge.py to map incoming gRPC service calls (defined in mt5.proto) to the corresponding MetaTrader5 functions.
Key Infrastructure Constants
The server performance and reliability are governed by specific network constants:
- Max Message Size: 50MB (to handle large historical data sets).
- Keepalive Time: 30 seconds.
- Keepalive Timeout: 10 seconds.
Sources: mt5linux/constants.py:34-36, mt5linux/settings.py:146-148
Summary
The Standalone Windows Installation provides a flexible way to bridge the gap between Windows-only trading software and Linux-based algorithmic trading systems. By running python -m mt5linux --server on a Windows host, the system exposes a robust gRPC interface that supports both synchronous and asynchronous client interactions, enabling complex trading logic to be offloaded to modern Linux environments while maintaining a direct link to the MetaTrader 5 terminal.
Sources: README.md:5-15, mt5linux/main.py:7-14