Skip to content

JavaMT5 Project MapΒΆ

Complete project structure guide. Shows what's where, what's user-facing vs internal, and how components connect.


πŸ—ΊοΈ Project OverviewΒΆ

JavaMT5/
β”œβ”€β”€ πŸ“¦ Core API (Internal - 3 layers)
β”œβ”€β”€ 🎯 User Code (Orchestrators, Presets, Examples)
β”œβ”€β”€ πŸ“š Documentation
└── βš™οΈ Configuration & Build

External Dependencies:
└── πŸ”Œ Proto Definitions (from JitPack JAR)

πŸ“¦ Core API (Internal - src/main/java/io/metarpc/mt5/)ΒΆ

What: Three-tier architecture for MT5 trading automation.

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

src/main/java/io/metarpc/mt5/
β”œβ”€β”€ MT5Account.java         ← LAYER 1: Low-level proto/gRPC
β”‚   └── Direct proto Request/Response objects
β”‚   └── Connection management
β”‚   └── Raw gRPC calls
β”‚
β”œβ”€β”€ MT5Service.java         ← LAYER 2: Wrapper methods
β”‚   └── Direct data returns (no proto wrapping)
β”‚   └── Type conversions
β”‚   └── Simplified method signatures
β”‚
└── MT5Sugar.java           ← LAYER 3: Convenience layer
    └── Auto-normalization (volumes, prices)
    └── Risk management (calculateVolume, buyByRisk)
    └── Batch operations (closeAll, cancelAll)
    └── Smart helpers (snapshots, conversions)

exceptions/
└── ApiExceptionMT5.java    ← Exception wrapper with MT5 error codes

Architecture flow:

MT5Sugar β†’ uses β†’ MT5Service β†’ uses β†’ MT5Account β†’ gRPC β†’ MT5 Terminal

User decision: - 95% of cases: Start with MT5Sugar (highest level, easiest) - Need wrappers: Drop to MT5Service (no auto-normalization) - Need raw proto: Drop to MT5Account (full control)

Documentation: MT5Sugar.Overview.md


🎯 User Code (Your Trading Strategies)¢

Orchestrators (src/main/java/orchestrators/)ΒΆ

What: Pre-built trading strategy implementations.

User interaction: βœ… Start here! Copy, modify, customize for your strategies.

orchestrators/
β”œβ”€β”€ TrendFollowingOrchestrator.java    ← Trend following + trailing stops
β”œβ”€β”€ ScalpingOrchestrator.java          ← Quick in/out, tight SL/TP
β”œβ”€β”€ HedgingOrchestrator.java           ← Defensive hedging strategy
β”œβ”€β”€ BreakoutOrchestrator.java          ← Bi-directional pending orders
└── MartingaleOrchestrator.java        ← Volume doubling ⚠️ HIGH RISK

Purpose: Educational examples showing complete strategy workflows: - Entry logic (risk-based volume) - Position monitoring - Exit management - Performance tracking

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

Documentation: Orchestrators.Overview.md


Presets (src/main/java/presets/)ΒΆ

What: Multi-orchestrator combinations with adaptive logic.

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

presets/
β”œβ”€β”€ AggressiveGrowthPreset.java    ← 3-4 orchestrators, adaptive
└── DefensivePreset.java           ← Conservative, protection-first

Purpose: Show how to: - Chain multiple strategies - Adaptive decision-making (if profit > X then...) - Multi-phase trading sessions - Performance tracking across phases

Documentation: Orchestrators.Overview.md


Examples (src/main/java/examples/)ΒΆ

What: Runnable examples demonstrating API usage.

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

examples/
β”œβ”€β”€ lowlevel/                          ← MT5Account examples (proto level)
β”‚   β”œβ”€β”€ MarketDataExample.java         ← run.bat 1
β”‚   β”œβ”€β”€ TradingCalculationsExample.java ← run.bat 2
β”‚   └── StreamingExample.java          ← run.bat 3
β”‚
β”œβ”€β”€ services/                          ← MT5Service examples (wrapper level)
β”‚   β”œβ”€β”€ MarketDataServiceExample.java  ← run.bat 4
β”‚   β”œβ”€β”€ TradingServiceExample.java     ← run.bat 5
β”‚   └── StreamingServiceExample.java   ← run.bat 6
β”‚
└── sugar/                             ← MT5Sugar examples (convenience level)
    β”œβ”€β”€ SimpleTradingScenario.java     ← run.bat 7
    β”œβ”€β”€ RiskManagementScenario.java    ← run.bat 8
    └── GridTradingScenario.java       ← run.bat 9

Program.java (src/main/java/Program.java)ΒΆ

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

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

Program.java
β”œβ”€β”€ main()                              ← Entry point, parses arguments
β”œβ”€β”€ runDemo()                           ← Launches examples 1-9 via reflection
β”œβ”€β”€ runOrchestrator()                   ← Menu + runs orchestrators (10)
β”œβ”€β”€ runPreset()                         ← Menu + runs presets (11)
└── Header documentation                ← Complete guide to all commands

How it works:

run.bat 7
    ↓
Program.java main(args)  // args[0] = "7"
    ↓
runDemo(7)
    ↓
Reflection finds: examples.sugar.SimpleTradingScenario
    ↓
Calls: SimpleTradingScenario.main()

Purpose: - Single entry point for all examples (1-11) - Automatic class discovery via reflection - Interactive menus for orchestrators/presets - Complete command reference in file header - Resource cleanup for orchestrators/presets

How to run:

run.bat 1-9    # Examples (low-level, service, sugar)
run.bat 10     # Orchestrator menu
run.bat 10 1-5 # Specific orchestrator
run.bat 11     # Preset menu
run.bat 11 1-2 # Specific preset

Purpose: - Learn API usage patterns - See working code examples - Copy-paste starting points - Understand orchestrator/preset architecture


πŸ“š Documentation (docs/)ΒΆ

What: Complete API and strategy documentation.

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

docs/
β”œβ”€β”€ RUNNING_EXAMPLES.md                ← ⭐ How to run examples + troubleshooting
β”‚   └── Commands, troubleshooting, build process
β”‚
β”œβ”€β”€ PROJECT_MAP.md                     ← ⭐ This file - complete project structure
β”‚
β”œβ”€β”€ GETTING_STARTED.md                 ← Initial setup guide
β”‚
β”œβ”€β”€ GLOSSARY.md                        ← Terms and definitions
β”‚
β”œβ”€β”€ MT5Sugar/                          ← 50+ convenience methods
β”‚   β”œβ”€β”€ MT5Sugar.Overview.md           ← ⭐ START HERE
β”‚   β”œβ”€β”€ 1. Symbol_helpers/             ← 12 methods (getPoint, getBid, etc.)
β”‚   β”œβ”€β”€ 2. Market_orders/              ← 2 methods (buyMarket, sellMarket)
β”‚   β”œβ”€β”€ 3. Pending_orders/             ← 4 methods (buyLimit, sellLimit, etc.)
β”‚   β”œβ”€β”€ 4. Pending_orders_points/      ← 4 methods (offset-based)
β”‚   β”œβ”€β”€ 5. Position_management/        ← 5 methods (close, modify, etc.)
β”‚   β”œβ”€β”€ 6. Advanced_batch_operations/  ← 3 methods (batch close/cancel)
β”‚   β”œβ”€β”€ 7. Risk_management/            ← 3 methods (calculateVolume, etc.)
β”‚   β”œβ”€β”€ 8. Advanced_helpers/           ← 4 methods (limits, conversions)
β”‚   β”œβ”€β”€ 9. Account_and_position_helpers/ ← 10 methods (balance, equity, etc.)
β”‚   β”œβ”€β”€ 10. Snapshot_helpers/          ← 2 methods (full snapshots)
β”‚   └── 11. History_helpers/           ← 2 methods (history queries)
β”‚
β”œβ”€β”€ MT5Account/                        ← Low-level proto documentation
β”‚   β”œβ”€β”€ 1. Account_information/
β”‚   β”œβ”€β”€ 2. Symbol_information/
β”‚   β”œβ”€β”€ 3. Positions_and_orders/
β”‚   β”œβ”€β”€ 4. Market_depth_DOM/
β”‚   β”œβ”€β”€ 5. Trading/
β”‚   └── 6. Subscriptions/
β”‚
└── Orchestrators.Overview.md          ← ⭐ Strategies guide
    └── Includes: 5 orchestrators + 2 presets

Structure: - Each method has its own .md file with examples - Overview files provide quick navigation - Links between related methods - Usage examples in every file


βš™οΈ Configuration & BuildΒΆ

What: Project configuration and build tools.

User interaction: βš™οΈ Configure once - mostly read-only after setup.

./
β”œβ”€β”€ pom.xml                    ← Maven build configuration
β”‚   └── Dependencies, plugins, build settings
β”‚   └── Proto compilation setup
β”‚   └── Maven Daemon (mvnd) integration
β”‚
β”œβ”€β”€ appsettings.json           ← MT5 connection settings ⭐ EDIT THIS
β”‚   └── Host, port, login, password
β”‚   └── Symbol, SSL, timeout
β”‚   └── Use for all examples
β”‚
β”œβ”€β”€ run.bat                    ← Quick launcher for examples
β”‚   └── run.bat <number>       ← Launch specific example
β”‚   └── Handles Maven Daemon
β”‚
β”œβ”€β”€ .vscode/                   ← VS Code settings
β”‚   └── settings.json
β”‚
└── .gitignore                 ← Git ignore rules

Key file - appsettings.json:

{
  "MT5": {
    "Host": "localhost",
    "Port": 5555,
    "Login": 12345678,
    "Password": "yourpassword",
    "Symbol": "EURUSD",
    "UseSSL": true,
    "TimeoutSeconds": 30
  }
}


πŸ”Œ Proto Definitions (External Dependency)ΒΆ

What: Protocol Buffer definitions for MT5 terminal communication.

User interaction: πŸ“‹ Reference only - not in this repository.

Location: Downloaded automatically as part of MetaRPC library from JitPack.

How it works:

  1. Maven downloads precompiled JAR from JitPack (com.github.MetaRPC:JavaMT5)
  2. JAR contains compiled Java classes generated from proto files
  3. Classes cached in ~/.m2/repository/com/github/MetaRPC/JavaMT5/
  4. Your code imports these classes (e.g., mt5_term_api.*)

Proto files included in JAR: - mt5-term-api-account-helper.proto β†’ Account helpers - mt5-term-api-account-information.proto β†’ Account info - mt5-term-api-charts.proto β†’ Chart data - mt5-term-api-connection.proto β†’ Connection management - mt5-term-api-market-info.proto β†’ Market information - mt5-term-api-subscriptions.proto β†’ Real-time subscriptions - mt5-term-api-trade-functions.proto β†’ Trading operations - mt5-term-api-trading-helper.proto β†’ Trading helpers - mrpc-mt5-error.proto β†’ Error definitions

Purpose: - Define gRPC service contracts - Pre-compiled into Java classes by MetaRPC - Used by MT5Account layer - No local proto compilation needed


🎯 Quick Start Paths¢

Path 1: Learn the API (Beginner)ΒΆ

1. Read: docs/RUNNING_EXAMPLES.md
2. Read: docs/MT5Sugar/MT5Sugar.Overview.md
3. Configure: appsettings.json
4. Run: run.bat 7 (SimpleTradingScenario)
5. Study: src/main/java/examples/sugar/
6. Try: Modify SimpleTradingScenario.java

Path 2: Build a Strategy (Intermediate)ΒΆ

1. Read: docs/Orchestrators.Overview.md
2. Run: run.bat 10 (Interactive orchestrator menu)
3. Run: run.bat 10 1 (Scalping strategy)
4. Study: src/main/java/orchestrators/ScalpingOrchestrator.java
5. Copy: Create MyOrchestrator.java based on Scalping
6. Customize: Add your entry/exit logic
7. Test: On demo account

Path 3: Multi-Strategy System (Advanced)ΒΆ

1. Study: All single orchestrators first (run.bat 10 1-5)
2. Read: docs/Orchestrators.Overview.md (Presets section)
3. Run: run.bat 11 (Interactive preset menu)
4. Run: run.bat 11 2 (Defensive preset)
5. Study: src/main/java/presets/DefensivePreset.java
6. Design: Your multi-phase strategy
7. Build: Combine orchestrators with logic
8. Test: Extensively on demo

Path 4: Low-Level Integration (Expert)ΒΆ

1. Read: docs/MT5Account/ documentation
2. Study: MetaRPC proto classes (from JitPack JAR in ~/.m2/repository/)
3. Run: run.bat 1-3 (Low-level examples)
4. Study: src/main/java/io/metarpc/mt5/MT5Account.java
5. Explore: Proto-generated classes (mt5_term_api.* packages)
6. Use: When MT5Sugar/MT5Service don't fit your needs
7. Build: Custom low-level gRPC integrations

πŸ“Š Component Interaction DiagramΒΆ

YOUR CODE (User-facing)
  β”œβ”€ Orchestrators (strategy implementations)
  β”œβ”€ Presets (multi-strategy combinations)
  └─ Examples (learning materials)
                  β”‚
                  β”‚ uses
                  ↓
MT5Sugar (Layer 3 - Convenience)
  β”œβ”€ Auto-normalization
  β”œβ”€ Risk management
  └─ Batch operations
                  β”‚
                  β”‚ uses
                  ↓
MT5Service (Layer 2 - Wrappers)
  β”œβ”€ Direct data returns
  β”œβ”€ Type conversions
  └─ Simplified signatures
                  β”‚
                  β”‚ uses
                  ↓
MT5Account (Layer 1 - Low-level)
  β”œβ”€ Proto Request/Response
  β”œβ”€ gRPC communication
  └─ Connection management
                  β”‚
                  β”‚ gRPC
                  ↓
MT5 Terminal (External)
  └─ MetaTrader 5 with gRPC server

πŸ” File Naming ConventionsΒΆ

Core APIΒΆ

  • MT5*.java - Core API classes (Account, Service, Sugar)
  • *Exception.java - Exception types

User CodeΒΆ

  • *Orchestrator.java - Single-strategy implementations
  • *Preset.java - Multi-strategy combinations
  • *Example.java / *Demo.java - Runnable examples
  • *Scenario.java - Complex usage scenarios

DocumentationΒΆ

  • *.Overview.md - Category overview with all methods
  • methodName.md - Individual method documentation

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

βœ… MODIFY (User Code)ΒΆ

orchestrators/           ← Copy and customize for your strategies
presets/                 ← Create your own multi-strategy systems
examples/                ← Add your own examples
appsettings.json         ← Configure for your MT5 terminal

πŸ“– READ (Core API)ΒΆ

io/metarpc/mt5/         ← Use but don't modify (import and call)
docs/                   ← Reference documentation

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

target/                 ← Compiled classes (auto-generated)
.git/                   ← Git internals
~/.m2/repository/       ← Maven dependencies cache (proto classes here)

🎯 Project Philosophy¢

Goal: Make MT5 trading automation accessible through progressive complexity.

Three-tier design:

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

User code:

  • Orchestrators: Pre-built strategy templates
  • Presets: Multi-strategy combinations
  • Examples: Learning materials

Start high (MT5Sugar), drop down only when needed.

πŸ’‘ Remember: This is an educational project. All orchestrators and presets are examples, not production-ready systems. Always test on demo accounts and understand the code before using real money.