Skip to content

GoMT5 Project MapΒΆ

Complete reference to project structure. Shows what is located where, what is user-facing vs internal, and how components are connected.


πŸ—ΊοΈ Project OverviewΒΆ

GoMT5/
β”œβ”€β”€ πŸ“¦ package/ - Independent module (portable)
β”‚   β”œβ”€β”€ Helpers/MT5Account.go (Layer 1 - Foundation)
β”‚   β”œβ”€β”€ Helpers/errors.go (Error handling & trade return codes)
β”‚   β”œβ”€β”€ Proto definitions (*.pb.go)
β”‚   └── gRPC stubs (*_grpc.pb.go)
β”‚
β”œβ”€β”€ πŸ“¦ examples/mt5/ - High-level API layers
β”‚   β”œβ”€β”€ MT5Service.go (Layer 2 - Wrappers)
β”‚   └── MT5Sugar.go (Layer 3 - Convenience)
β”‚
β”œβ”€β”€ 🎯 User Code (Orchestrators, Presets, Examples)
β”œβ”€β”€ πŸ“š Documentation
└── βš™οΈ Configuration and build

External dependencies:
└── πŸ”Œ gRPC & Proto (Go modules)

πŸ“¦ Core API (Three-layer architecture)ΒΆ

What: Three-tier architecture for MT5 trading automation.

User interaction: Import and use, but typically don't modify.

package/Helpers/
β”œβ”€β”€ MT5Account.go              ← LAYER 1: Low-level gRPC ⭐ FOUNDATION
β”‚   └── Direct gRPC calls to MT5 terminal
β”‚   └── Connection management with retry logic
β”‚   └── Proto Request/Response handling
β”‚   └── Built-in connection resilience
β”‚   └── Independent Go module (portable)
β”‚
└── errors.go                  ← Error handling & trade result codes
    └── ErrNotConnected sentinel error
    └── ApiError wrapper (3-level: API/MQL/Trade)
    └── Trade return code constants & helpers
    └── Centralized error inspection methods

examples/mt5/
β”œβ”€β”€ MT5Service.go              ← LAYER 2: Wrapper methods
β”‚   └── Simplified signatures (no proto objects)
β”‚   └── Type conversion (proto β†’ Go primitives)
β”‚   └── Direct data return
β”‚   └── Extension methods for convenience
β”‚
└── MT5Sugar.go                ← LAYER 3: Convenience layer ⭐
    └── Auto-normalization (volumes, prices)
    └── Risk management (CalculateVolume, BuyByRisk)
    └── Points-based methods (BuyLimitPoints, etc.)
    └── Batch operations (CloseAll, CancelAll)
    └── Snapshots (GetAccountSnapshot, GetSymbolSnapshot)
    └── Smart helpers (conversions, limits)

go.mod / go.sum                ← Module dependencies

Architecture flow:

MT5Sugar β†’ uses β†’ MT5Service β†’ uses β†’ MT5Account β†’ gRPC β†’ MT5 Terminal
       ↓                ↓                    ↓
examples/mt5/    examples/mt5/      package/Helpers/

πŸ’‘ Creating Your Own Project:

For your own standalone project using GoMT5, you only need to import the package module:

import pb "github.com/MetaRPC/GoMT5/package"

The package module contains everything you need to start:

  • βœ… All protobuf definitions (proto-generated code)
  • βœ… gRPC stubs and service contracts
  • βœ… MT5Account (Layer 1 - Foundation)
  • βœ… Independent Go module (can be used without examples/)

This makes the package portable and easy to integrate into any Go project!

User decision:

  • Building your own app: Import package and use MT5Account directly
  • Learning/Examples: Use the full GoMT5 repo with all 3 layers
  • 95% of demo cases: Start with MT5Sugar (highest level, easiest)
  • Need wrappers: Move to MT5Service (without auto-normalization)
  • Need raw proto: Move to MT5Account (full control)

Documentation:


🎯 User Code (Your Trading Strategies)¢

Orchestrators (examples/demos/orchestrators/)ΒΆ

What: Ready-made trading strategy implementations.

examples/demos/orchestrators/
β”œβ”€β”€ 13_grid_trader.go             ← Grid trading (sideways markets)
β”œβ”€β”€ 11_trailing_stop.go           ← Trailing stop (price following)
β”œβ”€β”€ 12_position_scaler.go         ← Position scaling
β”œβ”€β”€ 14_risk_manager.go            ← Risk manager
β”œβ”€β”€ 15_portfolio_rebalancer.go    ← Portfolio rebalancing
└── orchestrators.go              ← Base interface/functionality

Purpose: Educational examples showing complete strategy workflows:

  • Entry logic (risk-based volume where applicable)
  • Position monitoring with progress bars
  • Exit management and cleanup
  • Performance tracking (balance, equity, P/L)
  • Configurable parameters via properties

How to use:

  1. Study existing orchestrators
  2. Copy one as a template
  3. Modify for your strategy
  4. Test on demo account

How to run:

go run examples/demos/main.go grid         # Grid Trader
go run examples/demos/main.go trailing     # Trailing Stop
go run examples/demos/main.go scaler       # Position Scaler
go run examples/demos/main.go risk         # Risk Manager
go run examples/demos/main.go portfolio    # Portfolio Rebalancer

Documentation: - Grid Trader - Trailing Stop - Position Scaler - Risk Manager - Portfolio Rebalancer


Presets (examples/demos/presets/)ΒΆ

What: Combinations of multiple orchestrators with adaptive logic based on market analysis.

User interaction: βœ… Advanced usage - combine multiple strategies.

examples/demos/presets/
└── 16_AdaptiveOrchestratorPreset.go    ← Intelligent multi-strategy

Purpose: Demonstrate how to:

  • Combine multiple orchestrators
  • Adaptive decision making (volatility β†’ strategy)
  • Market condition analysis (simplified demo)
  • Multi-phase trading sessions
  • Performance tracking by phases

How to run:

go run examples/demos/main.go preset       # Adaptive Market Preset
go run examples/demos/main.go adaptive     # Same thing


Examples (examples/demos/)ΒΆ

What: Runnable examples demonstrating API usage at different layers.

User interaction: βœ… Learning materials - run to understand the API.

examples/demos/
β”œβ”€β”€ lowlevel/                          ← MT5Account examples (proto level) ⭐ FOUNDATION
β”‚   β”œβ”€β”€ 01_general_operations.go       ← General operations (connection, account, symbols)
β”‚   β”œβ”€β”€ 02_trading_operations.go       ← Trading operations (orders, positions)
β”‚   └── 03_streaming_methods.go        ← Streaming methods (real-time subscriptions)
β”‚
β”œβ”€β”€ service/                           ← MT5Service examples (wrapper level)
β”‚   β”œβ”€β”€ 04_service_demo.go             ← Service API demonstration
β”‚   └── 05_service_streaming.go        ← Service streaming methods
β”‚
β”œβ”€β”€ sugar/                             ← MT5Sugar examples (convenience level)
β”‚   β”œβ”€β”€ 06_sugar_basics.go             ← Sugar API basics (balance, prices)
β”‚   β”œβ”€β”€ 07_sugar_trading.go            ← Trading (market/limit orders)
β”‚   β”œβ”€β”€ 08_sugar_positions.go          ← Position management
β”‚   β”œβ”€β”€ 09_sugar_history.go            ← History and statistics
β”‚   └── 10_sugar_advanced.go           ← Advanced Sugar capabilities
β”‚
└── usercode/                          ← User code sandbox
    └── 18_usercode.go                 ← Your custom strategies

How to run:

# Low-level examples (MT5Account - FOUNDATION OF EVERYTHING)
go run examples/demos/main.go lowlevel01   # General operations
go run examples/demos/main.go lowlevel02   # Trading operations
go run examples/demos/main.go lowlevel03   # Streaming methods

# Service examples (MT5Service - wrappers)
go run examples/demos/main.go service04    # Service API demo
go run examples/demos/main.go service05    # Service streaming methods

# Sugar examples (MT5Sugar - convenience API)
go run examples/demos/main.go sugar06      # Sugar basics
go run examples/demos/main.go sugar07      # Sugar trading
go run examples/demos/main.go sugar08      # Sugar positions
go run examples/demos/main.go sugar09      # Sugar history
go run examples/demos/main.go sugar10      # Advanced Sugar

# UserCode (your code)
go run examples/demos/main.go usercode     # Custom strategies


main.go (examples/demos/)ΒΆ

What: Main entry point that routes go run commands to corresponding examples/orchestrators/presets.

User interaction: πŸ“‹ Runner + Documentation - launches everything.

main.go
β”œβ”€β”€ main()                              ← Entry point, parses arguments
β”œβ”€β”€ RouteCommand()                      ← Maps aliases to runners
β”œβ”€β”€ RunOrchestrator()                   ← Launches orchestrators
β”œβ”€β”€ RunPreset()                         ← Launches presets
β”œβ”€β”€ RunExample()                        ← Launches examples
└── Documentation in header             ← Full command reference

How it works:

go run examples/demos/main.go grid
    ↓
main(args)  // args[0] = "grid"
    ↓
RouteCommand("grid")
    ↓
RunOrchestrator("grid")
    ↓
GridTrader.Run()

Purpose:

  • Single entry point for all runnable code
  • Command routing with aliases (grid, trailing, preset, etc.)
  • Helpful error messages for unknown commands
  • Ctrl+C handling for graceful shutdown

Available commands: See header comment in main.go for full list.


Helpers (examples/demos/helpers/)ΒΆ

What: Utilities for examples and orchestrators.

examples/demos/helpers/
β”œβ”€β”€ connection.go                 ← MT5 connection setup
β”œβ”€β”€ error_helper.go               ← Error handling and return codes
β”œβ”€β”€ progress_bar.go               ← Visual progress bars
└── 17_protobuf_inspector.go      ← Protobuf structure inspector (runnable)

ConnectionHelper:

// Create and connect to MT5
account, err := connection.CreateAndConnect(host, port, user, password)
service := mt5.NewMT5Service(account)
sugar := mt5.NewMT5Sugar(service)

ProgressBarHelper:

// Visual countdown during orchestrator operation
helpers.ShowProgressBar(
    durationSeconds: 60,
    message: "Monitoring positions",
    ctx: ctx,
)

ErrorHelper:

// Check return codes and handle errors
if !helpers.IsSuccess(returnCode) {
    helpers.PrintError(returnCode, "Order placement failed")
}

ProtobufInspector:

// Inspect protobuf structures for debugging
inspector.InspectMessage(response)


πŸ“š Documentation (docs/)ΒΆ

What: Complete API and strategy documentation.

User interaction: πŸ“– Read first! Comprehensive reference.

docs/
β”œβ”€β”€ index.md                           ← Home page - project introduction
β”‚
β”œβ”€β”€ mkdocs.yml                         ← MkDocs configuration
β”œβ”€β”€ styles/custom.css                  ← Custom theme (ocean aurora)
β”œβ”€β”€ javascripts/ux.js                  ← Interactive features
β”‚
β”œβ”€β”€ All_Guides/                        ← Guides
β”‚   β”œβ”€β”€ MT5_For_Beginners.md           ← Demo account registration
β”‚   β”œβ”€β”€ GETTING_STARTED.md             ← ⭐ Start here! Setup and first steps
β”‚   β”œβ”€β”€ Your_First_Project.md          ← Your first project
β”‚   β”œβ”€β”€ GLOSSARY.md                    ← ⭐ Terms and definitions
β”‚   β”œβ”€β”€ GRPC_STREAM_MANAGEMENT.md      ← Managing streaming subscriptions
β”‚   β”œβ”€β”€ RETURN_CODES_REFERENCE.md      ← Proto return code reference
β”‚   β”œβ”€β”€ PROTOBUF_INSPECTOR_GUIDE.md    ← Protobuf inspector tool
β”‚   └── USERCODE_SANDBOX_GUIDE.md      ← How to write custom strategies
β”‚
β”œβ”€β”€ PROJECT_MAP.md                     ← ⭐ This file - complete structure
β”‚
β”œβ”€β”€ API_Reference/                     ← Concise API documentation
β”‚   β”‚                                     (slightly enhanced for better navigation)
β”‚   β”œβ”€β”€ MT5Account.md                  ← ⭐ Layer 1 API (foundation of everything) β†’ from package/Helpers/MT5Account.go
β”‚   β”œβ”€β”€ MT5Service.md                  ← Layer 2 API β†’ from examples/mt5/MT5Service.go
β”‚   └── MT5Sugar.md                    ← Layer 3 API β†’ from examples/mt5/MT5Sugar.go
β”‚
β”œβ”€β”€ MT5Account/                        ← ⭐ FOUNDATION OF EVERYTHING - Detailed Layer 1 documentation
β”‚   β”œβ”€β”€ MT5Account.Master.Overview.md  ← ⭐ Complete API reference
β”‚   β”‚
β”‚   β”œβ”€β”€ 1. Account_information/        ← Account methods (~4 files)
β”‚   β”‚   β”œβ”€β”€ AccountInfoDouble.md       ← Get account double parameters
β”‚   β”‚   β”œβ”€β”€ AccountSummary.md          ← Complete account summary
β”‚   β”‚   └── ...                        ← And other account methods
β”‚   β”‚   └── πŸ’‘ Each example linked with examples/demos/lowlevel
β”‚   β”‚
β”‚   β”œβ”€β”€ 2. Symbol_information/         ← Symbol/market data methods (~9 files)
β”‚   β”‚   β”œβ”€β”€ SymbolInfoTick.md          ← Current symbol tick
β”‚   β”‚   β”œβ”€β”€ SymbolInfoDouble.md        ← Symbol double parameters
β”‚   β”‚   β”œβ”€β”€ SymbolsTotal.md            ← Total symbols count
β”‚   β”‚   └── ...                        ← And other symbol methods
β”‚   β”‚   └── πŸ’‘ Examples in examples/demos/lowlevel
β”‚   β”‚
β”‚   β”œβ”€β”€ 3. Position_Orders_Information/ ← Position/order methods (~6 files)
β”‚   β”‚   β”œβ”€β”€ OpenedOrders.md            ← List of open orders
β”‚   β”‚   β”œβ”€β”€ PositionsTotal.md          ← Total positions count
β”‚   β”‚   └── ...                        ← And other position methods
β”‚   β”‚   └── πŸ’‘ Examples in examples/demos/lowlevel
β”‚   β”‚
β”‚   β”œβ”€β”€ 4. Trading_Operations/         ← Trading operation methods (~7 files)
β”‚   β”‚   β”œβ”€β”€ OrderSend.md               ← Send order (main method)
β”‚   β”‚   β”œβ”€β”€ OrderCheck.md              ← Check order before sending
β”‚   β”‚   β”œβ”€β”€ OrderCalcMargin.md         ← Calculate margin
β”‚   β”‚   β”œβ”€β”€ OrderCalcProfit.md         ← Calculate profit
β”‚   β”‚   └── ...                        ← And other trading methods
β”‚   β”‚   └── πŸ’‘ Examples in examples/demos/lowlevel/02_trading_operations.go
β”‚   β”‚
β”‚   β”œβ”€β”€ 5. Market_Depth(DOM)/          ← Market depth methods (~4 files)
β”‚   β”‚   β”œβ”€β”€ MarketBookAdd.md           ← Subscribe to market depth
β”‚   β”‚   β”œβ”€β”€ MarketBookGet.md           ← Get market depth data
β”‚   β”‚   └── ...                        ← And other DOM methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 6. Additional_Methods/         ← Additional methods (~5 files)
β”‚   β”‚   β”œβ”€β”€ SymbolInfoMarginRate.md    ← Symbol margin rates
β”‚   β”‚   β”œβ”€β”€ SymbolInfoSessionQuote.md  ← Quote trading sessions
β”‚   β”‚   └── ...                        ← And other auxiliary methods
β”‚   β”‚
β”‚   └── 7. Streaming_Methods/          ← Real-time subscription methods
β”‚       β”œβ”€β”€ OnSymbolTick.md            ← Subscribe to symbol ticks
β”‚       β”œβ”€β”€ OnTrade.md                 ← Subscribe to trade events
β”‚       β”œβ”€β”€ OnPositionProfit.md        ← Subscribe to profit changes
β”‚       └── ...                        ← And other streaming methods
β”‚       └── πŸ’‘ Stream management examples in All_Guides/GRPC_STREAM_MANAGEMENT
β”‚
β”œβ”€β”€ MT5Service/                        ← Service level method documentation
β”‚   β”œβ”€β”€ MT5Service.Overview.md          ← ⭐ Complete Service API reference
β”‚   β”œβ”€β”€ 1. Account_Methods.md          ← Account helper methods
β”‚   β”œβ”€β”€ 2. Symbol_Methods.md           ← Symbol helper methods
β”‚   β”œβ”€β”€ 3. Position_Orders_Methods.md  ← Position/order helper methods
β”‚   β”œβ”€β”€ 4. Trading_Methods.md          ← Trading helper methods
β”‚   β”œβ”€β”€ 5. MarketDepth_Methods.md      ← Market depth helper methods
β”‚   └── 6. Streaming_Methods.md        ← Streaming helper methods
β”‚
β”œβ”€β”€ MT5Sugar/                          ← Sugar level method documentation
β”‚   β”œβ”€β”€ MT5Sugar.API_Overview.md        ← ⭐ Complete Sugar API reference
β”‚   β”‚
β”‚   β”œβ”€β”€ 1. Connection/                  ← Connection methods (~3 files)
β”‚   β”‚   β”œβ”€β”€ QuickConnect.md            ← Quick connection
β”‚   β”‚   β”œβ”€β”€ IsConnected.md             ← Check connection
β”‚   β”‚   └── Ping.md                    ← Connection test
β”‚   β”‚
β”‚   β”œβ”€β”€ 2. Balance_Margin/              ← Balance and margin (~6 files)
β”‚   β”‚   β”œβ”€β”€ GetBalance.md              ← Get balance
β”‚   β”‚   β”œβ”€β”€ GetEquity.md               ← Get equity
β”‚   β”‚   β”œβ”€β”€ GetFreeMargin.md           ← Free margin
β”‚   β”‚   └── ...                        ← And other balance methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 3. Prices_Quotes/               ← Prices and quotes (~5 files)
β”‚   β”‚   β”œβ”€β”€ GetBid.md                  ← Get Bid
β”‚   β”‚   β”œβ”€β”€ GetAsk.md                  ← Get Ask
β”‚   β”‚   β”œβ”€β”€ GetSpread.md               ← Get spread
β”‚   β”‚   └── ...                        ← And other price methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 4. Simple_Trading/              ← Simple trading (~6 files)
β”‚   β”‚   β”œβ”€β”€ BuyMarket.md               ← Buy at market
β”‚   β”‚   β”œβ”€β”€ SellMarket.md              ← Sell at market
β”‚   β”‚   β”œβ”€β”€ BuyLimit.md                ← Buy Limit order
β”‚   β”‚   └── ...                        ← And other simple orders
β”‚   β”‚
β”‚   β”œβ”€β”€ 5. Trading_SLTP/                ← Trading with SL/TP (~4 files)
β”‚   β”‚   β”œβ”€β”€ BuyMarketWithSLTP.md       ← Buy with SL/TP
β”‚   β”‚   β”œβ”€β”€ SellMarketWithSLTP.md      ← Sell with SL/TP
β”‚   β”‚   └── ...                        ← And other orders with SL/TP
β”‚   β”‚
β”‚   β”œβ”€β”€ 6. Position_Management/         ← Position management (~7 files)
β”‚   β”‚   β”œβ”€β”€ ClosePosition.md           ← Close position
β”‚   β”‚   β”œβ”€β”€ CloseAllPositions.md       ← Close all positions
β”‚   β”‚   β”œβ”€β”€ ModifyPositionSLTP.md      ← Modify SL/TP
β”‚   β”‚   └── ...                        ← And other management methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 7. Position_Information/        ← Position information (~7 files)
β”‚   β”‚   β”œβ”€β”€ HasOpenPosition.md         ← Has open position
β”‚   β”‚   β”œβ”€β”€ CountOpenPositions.md      ← Count positions
β”‚   β”‚   β”œβ”€β”€ GetPositionTickets.md      ← Get position tickets
β”‚   β”‚   └── ...                        ← And other information methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 8. History_Statistics/          ← History and statistics (~10 files)
β”‚   β”‚   β”œβ”€β”€ GetDealsToday.md           ← Deals today
β”‚   β”‚   β”œβ”€β”€ GetProfitThisWeek.md       ← Profit this week
β”‚   β”‚   β”œβ”€β”€ GetDealsDateRange.md       ← Deals for period
β”‚   β”‚   └── ...                        ← And other history methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 9. Symbol_Information/          ← Symbol information (~6 files)
β”‚   β”‚   β”œβ”€β”€ GetSymbolInfo.md           ← Complete symbol information
β”‚   β”‚   β”œβ”€β”€ GetAllSymbols.md           ← All available symbols
β”‚   β”‚   └── ...                        ← And other symbol methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 10. Risk_Management/            ← Risk management (~4 files)
β”‚   β”‚   β”œβ”€β”€ CalculatePositionSize.md   ← Calculate position size
β”‚   β”‚   β”œβ”€β”€ CanOpenPosition.md         ← Can open position
β”‚   β”‚   └── ...                        ← And other risk methods
β”‚   β”‚
β”‚   β”œβ”€β”€ 11. Trading_Helpers/            ← Trading helpers (~3 files)
β”‚   β”‚   β”œβ”€β”€ BuyMarketWithPips.md       ← Buy with SL/TP in pips
β”‚   β”‚   β”œβ”€β”€ CalculateSLTP.md           ← Calculate SL/TP
β”‚   β”‚   └── ...                        ← And other helpers
β”‚   β”‚
β”‚   └── 12. Account_Information/        ← Account information (~4 files)
β”‚       β”œβ”€β”€ AccountInfo.md             ← Account information
β”‚       β”œβ”€β”€ GetDailyStats.md           ← Daily statistics
β”‚       └── ...                        ← And other account methods
β”‚
└── Orchestrators/                     ← Strategy documentation
    β”œβ”€β”€ 13_Grid_trader.md              ← Grid trading
    β”œβ”€β”€ 11_Trailing_stop.md            ← Trailing stop
    β”œβ”€β”€ 12_Position_scaler.md          ← Position scaling
    β”œβ”€β”€ 14_Risk_manager.md             ← Risk manager
    β”œβ”€β”€ 15_Portfolio_rebalancer.md     ← Portfolio rebalancing
    β”œβ”€β”€ 16_AdaptiveOrchestratorPreset.md ← Adaptive preset
    └── Strategies.Master.Overview.md  ← Complete strategy overview

Structure:

  • Each method has its own .md file with examples
  • Overview files (*.Master.Overview.md) provide navigation
  • HOW_IT_WORKS.md files explain algorithms step by step
  • Links between related methods
  • Usage examples in each file

⭐ Important about MT5Account: - FOUNDATION OF EVERYTHING - all methods here are the foundation - Each documentation example is linked with real code in examples/demos/lowlevel/ - Understanding MT5Account is critical for effective use of MT5Service and MT5Sugar


πŸ”Œ gRPC & Proto (Go modules)ΒΆ

What: Protocol Buffer and gRPC libraries for communication with MT5 terminal.

User interaction: πŸ“‹ Reference only - managed via Go modules.

Key dependencies:

  • google.golang.org/grpc - gRPC client
  • google.golang.org/protobuf - Protocol Buffers runtime
  • github.com/MetaRPC/GoMT5/package - MT5 Proto definitions (independent module)

Package structure:

package/
β”œβ”€β”€ Helpers/
β”‚   └── MT5Account.go          ← Layer 1 implementation
β”œβ”€β”€ *.pb.go                    ← Generated protobuf code
β”œβ”€β”€ *_grpc.pb.go               ← Generated gRPC stubs
β”œβ”€β”€ go.mod                     ← Independent module
└── go.sum                     ← Module dependencies

How it works:

  1. package/ is an independent Go module
  2. Contains both proto-generated code and MT5Account implementation
  3. Can be imported separately: github.com/MetaRPC/GoMT5/package
  4. MT5Service and MT5Sugar import from package module
  5. All layers use proto-generated types from package

Proto-generated types:

  • mt5_term_api.* - Trading API types
  • Request/Response message types
  • Enum definitions
  • Service contracts

Purpose:

  • Define gRPC service contracts
  • Type-safe communication with MT5 terminal
  • Used by MT5Account layer
  • Hidden by MT5Service and MT5Sugar layers

πŸ“Š Component Interaction DiagramΒΆ

YOUR CODE (User)
  β”œβ”€ Orchestrators (strategy implementations)
  β”œβ”€ Presets (multi-strategies)
  └─ Examples (learning materials)
                  β”‚
                  β”‚ uses
                  ↓
MT5Sugar (Layer 3 - Convenience)
  β”œβ”€ Auto-normalization
  β”œβ”€ Risk management
  β”œβ”€ Points-based methods
  └─ Batch operations
                  β”‚
                  β”‚ uses
                  ↓
MT5Service (Layer 2 - Wrappers)
  β”œβ”€ Direct data return
  β”œβ”€ Type conversion
  └─ Simplified signatures
                  β”‚
                  β”‚ uses
                  ↓
MT5Account (Layer 1 - Low level) ⭐ FOUNDATION
  πŸ“ Location: package/Helpers/MT5Account.go
  β”œβ”€ Proto Request/Response
  β”œβ”€ gRPC communication
  β”œβ”€ Connection management
  β”œβ”€ Auto-reconnection
  └─ Independent Go module (portable)
                  β”‚
                  β”‚ gRPC
                  ↓
MT5 Gateway (mt5term) or MT5 Terminal
  └─ MetaTrader 5 with gRPC server

πŸ” File Naming ConventionsΒΆ

Core API (Multi-location)ΒΆ

Layer 1 (Foundation): - package/Helpers/MT5Account.go - Low-level gRPC (independent module)

Layers 2-3 (High-level wrappers): - examples/mt5/MT5Service.go - Wrapper methods - examples/mt5/MT5Sugar.go - Convenience API - go.mod / go.sum - Dependencies

User Code (examples/demos/)ΒΆ

  • *_orchestrator.go / NN_name.go - Single strategy implementations
  • *_preset.go - Multi-strategies
  • main.go - Entry point and command router
  • *_helper.go - Utilities (connection, error, progress_bar)

Documentation (docs/)ΒΆ

  • *.Master.Overview.md - Complete category overviews
  • *.Overview.md - Section overviews
  • MethodName.md - Individual method documentation
  • *_HOW.md - Algorithm explanations

πŸ“‚ What to Modify vs What to Leave AloneΒΆ

βœ… MODIFY (User Code)ΒΆ

Recommended starting point:

examples/demos/usercode/18_usercode.go  ← ⭐ SANDBOX - start writing your code here!
                                           All 3 API levels already initialized and ready.
                                           Run: go run main.go 18

Other files for modification:

examples/demos/orchestrators/  ← Copy and customize for your strategies
examples/demos/presets/        ← Create your multi-strategies
examples/demos/lowlevel/       ← Add your low-level examples
examples/demos/service/        ← Add your service examples
examples/demos/sugar/          ← Add your sugar examples
examples/demos/usercode/       ← Create your custom files alongside 18_usercode.go
examples/demos/config/         ← Configure for your MT5 terminal/gateway
examples/demos/main.go         ← Add new command routing if needed
README.md                      ← Update with your changes

πŸ“– READ (Core API)ΒΆ

package/Helpers/MT5Account.go  ← Use but don't modify (import and call) ⭐ FOUNDATION
examples/mt5/MT5Service.go     ← Use but don't modify
examples/mt5/MT5Sugar.go       ← Use but don't modify
docs/                          ← Reference documentation

πŸ”’ LEAVE ALONE (Generated/Build)ΒΆ

.vscode/                       ← VS Code settings
go.work.sum                    ← Go workspace (auto-generated)
docs/site/                     ← Built documentation (auto-generated by MkDocs)
docs/styles/                   ← Documentation theme (don't change without understanding)
docs/javascripts/              ← Documentation scripts (don't change without understanding)

🎯 Project Philosophy¢

Goal: Make MT5 trading automation accessible through progressive complexity.

Three-tier design:

  1. Low level (MT5Account): Full control, proto/gRPC ⭐ FOUNDATION OF EVERYTHING
  2. Wrappers (MT5Service): Simplified method calls
  3. Convenience (MT5Sugar): Auto-everything, batteries included

User code:

  • Orchestrators: Ready-made strategy templates
  • Presets: Adaptive multi-strategies
  • Examples: Learning materials at all levels

πŸ› οΈ TroubleshootingΒΆ

Build IssuesΒΆ

# Clean and rebuild
go clean
go build ./...

# Restore modules
go mod tidy
go mod download

# Check Go version
go version   # Should be 1.21 or higher

Runtime IssuesΒΆ

1. Always test on demo account first
2. Check return codes (10009 = success, 10031 = connection error)
3. Monitor console output for errors
4. Use retry logic for intermittent issues
5. Verify broker allows your strategy type (hedging, etc.)

πŸ“ˆ Performance ConsiderationsΒΆ

Connection ManagementΒΆ

  • Single gRPC connection shared across operations
  • Built-in auto-reconnection handles temporary failures
  • Retry logic with exponential backoff (1s β†’ 2s β†’ 4s)

Rate LimitingΒΆ

  • 3-second delays between order placements (demo examples)
  • Gateway may enforce additional rate limits
  • Adjust delays based on broker requirements

Resource UsageΒΆ

  • Async/await everywhere for non-blocking I/O
  • Context for graceful shutdown
  • Proper cleanup in defer blocks

πŸ“ Best PracticesΒΆ

Code OrganizationΒΆ

βœ… DO: Separate concerns (analysis, execution, monitoring)
βœ… DO: Use context for lifecycle management
βœ… DO: Add comprehensive error handling
βœ… DO: Document your strategy logic clearly
βœ… DO: Use ProgressBarHelper for long operations

❌ DON'T: Mix strategy logic with API calls
❌ DON'T: Use time.Sleep (use time.After with context)
❌ DON'T: Ignore return codes
❌ DON'T: Test on live accounts without extensive demo testing

Strategy DevelopmentΒΆ

βœ… DO: Start with existing orchestrator as template
βœ… DO: Test each component separately
βœ… DO: Log all trading decisions and outcomes
βœ… DO: Use demo accounts for development
βœ… DO: Implement proper risk management

❌ DON'T: Over-optimize on limited data
❌ DON'T: Ignore edge cases and failures
❌ DON'T: Use fixed lots without risk calculation
❌ DON'T: Deploy without backtesting and forward testing

πŸ’‘ Remember: This is an educational project. All orchestrators and presets are demonstration examples, not production-ready trading systems. Always test on demo accounts, thoroughly understand the code, and implement proper risk management before considering live trading.


"Trade safely, code cleanly, and may your gRPC connections always be stable."