Command Line Interface
Relevant source files
The following files were used as context for generating this wiki page:
The Command Line Interface (CLI) of mt5linux serves as the primary entry point for managing the MetaTrader5 gRPC bridge. It facilitates two main operational modes: providing package information/documentation and launching the gRPC bridge server. The server mode is specifically designed to run on Windows environments (or via Wine) where the native MetaTrader5 terminal is accessible, while the information mode is available across all supported platforms.
Sources: mt5linux/__main__.py:7-21, README.md:100-110
CLI Architecture and Execution Flow
The CLI is implemented using the python -m mt5linux pattern. Upon execution, the main() function in the package's entry point parses incoming arguments to determine whether to display help information or delegate execution to the bridge server component.
The diagram shows the logic flow from initial command execution to either help display or server initialization.
Sources: mt5linux/__main__.py:58-80, tests/unit/test_main_unit.py:99-122
Lazy Loading Implementation
A critical architectural detail is the use of lazy loading for the bridge server. Because the server component requires the Windows-specific MetaTrader5 module, it is only imported inside _bridge_main when the --server flag is explicitly provided. This prevents import errors when the package is used in client-only mode on Linux systems.
Sources: mt5linux/__main__.py:46-56
Command Reference
The CLI supports a specific set of flags and parameters to configure the bridge server's behavior at runtime.
| Flag | Long Form | Description | Default |
|---|---|---|---|
-s | --server | Starts the gRPC bridge server | N/A |
| N/A | --host | Bind address for the server | 0.0.0.0 |
-p | --port | Listening port for gRPC connections | 50051 |
| N/A | --workers | Number of worker threads | 10 |
-d | --debug | Enables verbose debug logging | Off |
-h | --help | Displays help and usage information | N/A |
Sources: mt5linux/__main__.py:26-40, README.md:112-118
Server Management via Docker
While the Python CLI handles standalone execution, the project extensively uses docker compose as a secondary CLI wrapper for automated deployment and testing. This environment supports parametrization via environment variables to manage isolated test scenarios.
This diagram illustrates the relationship between host environment variables, the Docker CLI, and the underlying mt5linux server process.
Sources: DOCKER_COMPOSE_USAGE.md:14-38, DOCKER_COMPOSE_USAGE.md:83-93
Technical Configuration and Constants
The CLI and underlying server utilize a centralized constants system for network and infrastructure defaults. These values are used when CLI flags are omitted.
| Namespace | Constant | Value | Description |
|---|---|---|---|
Network | GRPC_PORT | 8001 | Internal container gRPC port |
Network | DOCKER_GRPC_PORT | 38812 | Default host mapped gRPC port |
Network | BIND_ALL | 0.0.0.0 | Default listening interface |
Queue | MAX_CONCURRENT | 10 | Default simultaneous operations |
Sources: mt5linux/constants.py:23-34, mt5linux/constants.py:462-466
Conclusion
The mt5linux Command Line Interface provides a lightweight but robust gateway to the gRPC bridge. By separating the client usage information from the Windows-only server logic through lazy imports, it ensures cross-platform compatibility while maintaining a simple, thread-safe interface for launching high-performance trading servers.
Sources: mt5linux/__main__.py:46-56, README.md:10-20