GoMT4 Project MapΒΆ
Complete architecture guide. Shows the three-tier system, component interactions, and file organization.
πΊοΈ Project Architecture OverviewΒΆ
GoMT4 is structured into three clean, decoupled layers designed to satisfy both low-level quantitative control and high-level strategy convenience:
GoMT4/
βββ π¦ Layer 1: MT4Account (Low-level gRPC)
βββ π§ Layer 2: MT4Service (Typed wrapper methods)
βββ β Layer 3: MT4Sugar (High-level convenience API)
π Component Interaction DiagramΒΆ
YOUR CODE (User-facing)
ββ Orchestrators (strategy implementations)
ββ Presets (multi-strategy combinations)
ββ Examples (learning materials)
β
β uses
β
MT4Sugar (Layer 3 - Convenience)
ββ Auto-normalization (lots, slippage)
ββ Risk management (LotSizeFromRisk)
ββ Order helper methods (BuyByPips, etc.)
ββ Batch operations (CloseAllOrders, DeletePending)
β
β uses
β
MT4Service (Layer 2 - Wrappers)
ββ Direct data returns
ββ Type conversions (proto β native primitives)
ββ Simplified signatures (no raw proto required)
β
β uses
β
MT4Account (Layer 1 - Low-level)
ββ Proto Request/Response handling
ββ gRPC communication & channel management
ββ Auto-reconnection on transient faults
ββ Real-time streaming subscriptions
β
β gRPC
β
MT4 Gateway (mt4term) or MT4 Terminal
ββ MetaTrader 4 with gRPC server
π Layer BreakdownΒΆ
Layer 1: MT4Account (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: MT4Service (Wrappers)ΒΆ
- Translates protobuf messages into native Go primitives and data models.
- Removes boilerplate request/response wrapper instantiation.
- Simplifies method signatures for common terminal actions (Orders, Tickets, and History).
Layer 3: MT4Sugar (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
MT4Sugar. It protects you from off-quote rejections and invalid volume errors. - Custom algorithmic execution: Use
MT4Servicewhen you manage your own volume normalization logic. - Protocol engineering: Drop to
MT4Accountwhen you need raw protobuf structures.