Skip to content

MT5Account - Master Overview

One page to orient fast: what lives where, how to choose the right API, and jump links to every overview and method spec in this docs set.


🚦 Start here - Section Overviews


🧭 How to pick an API

If you need… Go to… Typical calls
Account snapshot Account_Information AccountSummary, AccountInfoDouble, AccountInfoInteger
Quotes & symbol properties Symbol_Information SymbolInfoTick, SymbolInfoDouble, SymbolsTotal
Current positions & orders Position_Orders_Information PositionsTotal, OpenedOrders, OpenedOrdersTickets
Historical trades Position_Orders_Information OrderHistory, PositionsHistory
Level II / Order book Market_Depth_DOM MarketBookAdd, MarketBookGet, MarketBookRelease
Trading operations Trading_Operations OrderSend, OrderModify, OrderClose
Pre-trade calculations Trading_Operations OrderCalcMargin, OrderCheck
Advanced symbol data Additional_Methods SymbolParamsMany, SymbolInfoSessionTrade
Real-time updates Streaming_Methods OnSymbolTick, OnTrade, OnPositionProfit

🔌 Usage pattern (gRPC protocol)

Every method follows gRPC client-server pattern:

// Create client connection
conn, err := grpc.Dial("localhost:8002", grpc.WithInsecure())
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

// Create MT5Account client
client := pb.NewAccountHelperClient(conn)

// Make request with context
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Call method
result, err := client.AccountSummary(ctx, &pb.AccountSummaryRequest{})
if err != nil {
    log.Fatalf("Failed: %v", err)
}

// Use result
fmt.Printf("Balance: $%.2f\n", result.AccountBalance)

Every method follows the same shape:

  • Proto Service/Method: Service.Method(Request) → Reply
  • Go client: client.Method(ctx, &Request{...})
  • Reply structure: Contains either Data payload or Error
  • Return codes: Trading operations return status codes (10009 = success)

Timestamps: Use google.protobuf.Timestamp (convert with timestamppb.New(time) and .AsTime()).

Streaming methods: Return stream object, use stream.Recv() in loop to receive updates.


📚 Full Index · All Method Specs


📄 Account Information

Complete Snapshot

Individual Properties


📊 Symbol Information

Current Quotes

Symbol Inventory & Management

Symbol Properties


📦 Positions & Orders

Current State

Historical Data


🛠 Trading Actions

Order Execution & Management

Pre-Trade Calculations


📈 Market Depth (DOM)

Level II Quotes


🔧 Additional Methods

Advanced Symbol Information


📡 Subscriptions (Streaming)

Real-Time Price Updates

Trading Events

Position Monitoring


🎯 Quick Navigation by Use Case

I want to... Use this method
ACCOUNT INFORMATION
Get complete account snapshot AccountSummary
Get account balance AccountInfoDouble (BALANCE)
Get account equity AccountInfoDouble (EQUITY)
Get account leverage AccountInfoInteger (LEVERAGE)
Get account currency AccountInfoString (CURRENCY)
SYMBOL INFORMATION
Get current price for symbol SymbolInfoTick
List all available symbols SymbolsTotal + SymbolName
Add symbol to Market Watch SymbolSelect (true)
Get symbol digits (decimal places) SymbolInfoInteger (DIGITS)
Get point size for symbol SymbolInfoDouble (POINT)
Get complete symbol data (batch) SymbolParamsMany
Get tick value for P&L calculations TickValueWithSize
POSITIONS & ORDERS
Count open positions PositionsTotal
Get all open positions (full details) OpenedOrders
Get position ticket numbers only OpenedOrdersTickets
Get historical orders OrderHistory
Get historical deals/trades PositionsHistory
MARKET DEPTH
Subscribe to Level II quotes MarketBookAdd
Get order book data MarketBookGet
Unsubscribe from Level II MarketBookRelease
TRADING OPERATIONS
Open market BUY position OrderSend (type=BUY)
Open market SELL position OrderSend (type=SELL)
Place BUY LIMIT order OrderSend (type=BUY_LIMIT)
Place SELL LIMIT order OrderSend (type=SELL_LIMIT)
Place BUY STOP order OrderSend (type=BUY_STOP)
Place SELL STOP order OrderSend (type=SELL_STOP)
Modify SL/TP of position OrderModify
Close a position OrderClose
Calculate margin before trade OrderCalcMargin
Calculate potential profit OrderCalcProfit
Validate trade before execution OrderCheck
REAL-TIME SUBSCRIPTIONS
Stream live prices OnSymbolTick
Monitor trade events OnTrade
Track profit changes OnPositionProfit
Monitor ticket changes OnPositionsAndPendingOrdersTickets
Detailed transaction log OnTradeTransaction

🏗️ API Architecture

Layer 1: MT5Account (Low-Level) - You are here!

What: Direct proto/gRPC communication with MT5 terminal.

When to use: - Need full control over protocol - Building custom wrappers - Proto-level integration required

Characteristics: - Works with proto Request/Response objects - Raw gRPC method calls - Complete access to all MT5 functions - Highest complexity

Location: Core gRPC client (generated from proto files)

Documentation: This folder (you are here!)


Layer 2: MT5Service

What: Simplified wrapper methods without proto complexity.

When to use: - Want simplified API but not auto-normalization - Building custom convenience layers - Need direct data returns

Characteristics: - Simple method signatures - Type conversions (proto → Go primitives) - No proto objects in return values - No auto-normalization

Location: examples/mt5/MT5Service.go

Documentation: MT5Service.Overview.md (if exists)


Layer 3: MT5Sugar

What: High-level convenience API with ~60 smart methods.

When to use: - Most trading scenarios (95% of cases) - Want auto-normalization - Need risk management helpers - Building strategies quickly

Characteristics: - Auto-normalization of volumes/prices - Risk-based position sizing - Batch operations - Smart helpers

Location: examples/mt5/MT5Sugar.go

Documentation: MT5Sugar.API_Overview.md


🎓 Learning Path

Recommended sequence: Start from foundation (MT5Account) → Build up to convenience layers (MT5Service → MT5Sugar)

Step 1: Master the Foundation (MT5Account) - You are here!

Why first: MT5Account is the foundation - everything else is built on top of it. Understanding the protocol level gives you complete control.

1. Read: This documentation folder (docs/MT5Account/)
2. Study: Proto definitions and gRPC communication
3. Understand: Request/Response patterns
4. Learn: Return codes and error handling
5. Practice: Low-level method calls

Goal: Deep understanding of MT5 protocol and terminal communication.

Documentation: MT5Account.Master.Overview.md (you are here!)


Step 2: Understand Wrappers (MT5Service)

Why second: Once you know the foundation, see how MT5Service simplifies it by wrapping proto objects.

1. Study: How MT5Service wraps MT5Account methods
2. Compare: Wrapper vs low-level implementations
3. Learn: Type conversions (proto → Go primitives)
4. Practice: Simplified method calls without proto objects

Goal: Learn to build clean API wrappers on top of complex protocols.


Step 3: Use Convenience Layer (MT5Sugar)

Why last: With foundation + wrappers understood, appreciate how MT5Sugar adds auto-normalization and smart helpers.

1. Study: MT5Sugar convenience methods (~60 methods)
2. Learn: Auto-normalization, risk management, batch operations
3. Use: High-level methods for rapid strategy development
4. Build: Trading strategies using Sugar API

Goal: Rapid strategy development with production-ready convenience methods.

Documentation: MT5Sugar.API_Overview.md


Summary: MT5Account (foundation) → MT5Service (wrappers) → MT5Sugar (convenience)


💡 Key Concepts

Proto Return Codes

  • 10009 = Success / DONE
  • 10004 = Requote
  • 10006 = Request rejected
  • 10013 = Invalid request
  • 10014 = Invalid volume
  • 10015 = Invalid price
  • 10016 = Invalid stops
  • 10018 = Market closed
  • 10019 = Not enough money
  • 10031 = No connection with trade server

Always check ReturnedCode field in trading operations.


⚠️ Important Notes

  • Demo account first: Always test on demo before live trading.
  • Check return codes: Every trading operation returns status code (10009 = success).
  • Validate parameters: Use OrderCheck() before OrderSend().
  • Handle errors: Network/protocol errors can occur.
  • Context management: Always use context with timeout for requests.
  • Stream cleanup: Cancel context to stop streams properly.
  • UTC timestamps: All times are in UTC, not local time.
  • Broker limitations: Not all brokers support all features (DOM, hedging, etc.).

"Trade safe, code clean, and may your gRPC streams always flow smoothly."