Skip to content

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 MT4Service when you manage your own volume normalization logic.
  • Protocol engineering: Drop to MT4Account when you need raw protobuf structures.