PyMT5 Project MapΒΆ
Complete architecture guide. Shows the three-tier system, component interactions, and file organization.
πΊοΈ Project Architecture OverviewΒΆ
PyMT5 is structured into three clean, decoupled layers designed to satisfy both low-level quantitative control and high-level strategy convenience:
PyMT5/
βββ π¦ Layer 1: MT5Account (Low-level gRPC)
βββ π§ Layer 2: MT5Service (Typed wrapper methods)
βββ β Layer 3: MT5Sugar (High-level convenience API)
π Component Interaction DiagramΒΆ
YOUR CODE (User-facing)
ββ Orchestrators (strategy implementations)
ββ Presets (multi-strategy combinations)
ββ Examples (learning materials)
β
β uses
β
MT5Sugar (Layer 3 - Convenience)
ββ Auto-normalization (volumes, prices)
ββ Risk management (CalculateVolume, BuyByRisk)
ββ Points-based methods (BuyLimitPoints, etc.)
ββ Batch operations (CloseAll, CancelAll)
β
β uses
β
MT5Service (Layer 2 - Wrappers)
ββ Direct data returns
ββ Type conversions (proto β native primitives)
ββ Simplified signatures (no raw proto required)
β
β uses
β
MT5Account (Layer 1 - Low-level)
ββ Proto Request/Response handling
ββ gRPC communication & channel management
ββ Auto-reconnection on transient faults
ββ Real-time streaming subscriptions
β
β gRPC
β
MT5 Gateway (mt5term) or MT5 Terminal
ββ MetaTrader 5 with gRPC server
π Layer BreakdownΒΆ
Layer 1: MT5Account (Low-Level gRPC)ΒΆ
- Direct gRPC stubs communicating with the terminal.
- Handles protobuf message serialization/deserialization.
- Responsible for connection recovery, channel state monitoring, and raw streaming calls.
- Ideal when you need complete control over protobuf payload fields.
Layer 2: MT5Service (Wrappers)ΒΆ
- Translates protobuf messages into native Python primitives and data models.
- Removes boilerplate request/response wrapper instantiation.
- Simplifies method signatures for common terminal actions (Positions, Orders, and Deals).
Layer 3: MT5Sugar (Convenience Layer)ΒΆ
- Automates lot size calculation and margin checks based on risk percentages.
- Automatically normalizes prices and volumes to broker specifications (step size, digits, minimum lot).
- Provides one-line batch operations: close all profitable positions, cancel pending orders.
- Point-offset helpers (
BuyLimitPoints,SellStopPoints).
π― Which Layer Should You Use?ΒΆ
- 90% of trading applications: Start with
MT5Sugar. It protects you from off-quote rejections and invalid volume errors. - Custom algorithmic execution: Use
MT5Servicewhen you manage your own volume normalization logic. - Protocol engineering: Drop to
MT5Accountwhen you need raw protobuf structures.