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:
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:
- Maven downloads precompiled JAR from JitPack (com.github.MetaRPC:JavaMT5)
- JAR contains compiled Java classes generated from proto files
- Classes cached in
~/.m2/repository/com/github/MetaRPC/JavaMT5/ - 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 methodsmethodName.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)ΒΆ
π 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:
- Low-level (MT5Account): Full control, proto/gRPC
- Wrapper (MT5Service): Simplified method calls
- 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.