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¶
-
Account_Information - Overview Account balance/equity/margin/leverage, complete snapshot or single properties.
-
Symbol_Information - Overview Quotes, symbol properties, trading rules, tick values, Market Watch management.
-
Position_Orders_Information - Overview Open positions, pending orders, historical deals, order history.
-
Trading_Operations - Overview Order execution, position management, margin calculations, trade validation.
-
Market_Depth_DOM - Overview Level II quotes, order book data, market depth subscription.
-
Additional_Methods - Overview Advanced symbol info, trading sessions, margin rates, batch operations.
-
Streaming_Methods - Overview Real-time streams: ticks, trades, profit updates, transaction log. 📖 Complete Streaming Guide - How to properly work with subscriptions (patterns, best practices, memory management)
🧭 How to pick an API¶
| If you need… | Go to… | Typical calls |
|---|---|---|
| Account snapshot | Account_Information | AccountSummaryAsync, AccountInfoDoubleAsync, AccountInfoIntegerAsync |
| Quotes & symbol properties | Symbol_Information | SymbolInfoTickAsync, SymbolInfoDoubleAsync, SymbolsTotalAsync |
| Current positions & orders | Position_Orders_Information | PositionsTotalAsync, OpenedOrdersAsync, OpenedOrdersTicketsAsync |
| Historical trades | Position_Orders_Information | OrderHistoryAsync, PositionsHistoryAsync |
| Level II / Order book | Market_Depth_DOM | MarketBookAddAsync, MarketBookGetAsync, MarketBookReleaseAsync |
| Trading operations | Trading_Operations | OrderSendAsync, OrderModifyAsync, OrderCloseAsync |
| Pre-trade calculations | Trading_Operations | OrderCalcMarginAsync, OrderCheckAsync |
| Real-time updates | Streaming_Methods | OnSymbolTickAsync, OnTradeAsync, OnPositionProfitAsync |
🔌 Usage pattern (gRPC protocol)¶
Every method is available in two versions: Async (recommended) and Sync (rare scenarios).
Async Version (Recommended - 99% of cases)¶
var summary = await account.AccountSummaryAsync();
var tick = await account.SymbolInfoTickAsync("EURUSD");
Sync Version (Legacy/specific scenarios only)¶
📖 Read: Sync vs Async - When to Use What - Detailed guide with use cases and performance comparisons.
Every method follows the same shape:
- Proto Service/Method:
Service.Method(Request) → Reply - C# wrapper:
await mt5Account.MethodAsync(...)ormt5Account.Method() - Reply structure:
Reply.Datapayload (proto-generated objects) - Return codes:
10009= success; other codes = check error message
Timestamps = UTC (google.protobuf.Timestamp). For streaming subscriptions, use IAsyncEnumerable<T> with await foreach pattern.
📚 Full Index · All Method Specs¶
📄 Account Information¶
- Overview: Account_Information.Overview.md
Complete Snapshot¶
- AccountSummary.md - All account info at once (balance, equity, margin, etc.)
Individual Properties¶
- AccountInfoDouble.md - Single double value (balance, equity, margin, profit, etc.)
- AccountInfoInteger.md - Single integer value (login, leverage, limit orders, etc.)
- AccountInfoString.md - Single string value (name, server, currency, company)
📊 Symbol Information¶
- Overview: Symbol_Information.Overview.md
Current Quotes¶
- SymbolInfoTick.md - Current quote for symbol (bid, ask, last, volume, time)
Symbol Inventory & Management¶
- SymbolsTotal.md - Count of available symbols
- SymbolName.md - Get symbol name by index
- SymbolSelect.md - Enable/disable symbol in Market Watch
- SymbolExist.md - Check if symbol exists
- SymbolIsSynchronized.md - Check symbol data sync status
Symbol Properties¶
- SymbolInfoDouble.md - Single double property (bid, ask, point, volume min/max, etc.)
- SymbolInfoInteger.md - Single integer property (digits, spread, stops level, etc.)
- SymbolInfoString.md - Single string property (description, currency, path)
📦 Positions & Orders¶
- Overview: Position_Orders_Information.Overview.md
Current State¶
- PositionsTotal.md - Count of open positions
- OpenedOrders.md - Full details of all open positions and pending orders
- OpenedOrdersTickets.md - Ticket numbers only (lightweight)
Historical Data¶
- OrderHistory.md - Historical orders within time range (with pagination)
- PositionsHistory.md - Closed positions within time range (with pagination)
🛠 Trading Actions¶
- Overview: Trading_Operations.Overview.md
Order Execution & Management¶
- OrderSend.md - Place market or pending orders
- OrderModify.md - Modify SL/TP or order parameters
- OrderClose.md - Close positions (full or partial)
Pre-Trade Calculations¶
- OrderCalcMargin.md - Calculate margin required for trade
- OrderCheck.md - Validate trade request before execution
📈 Market Depth (DOM)¶
- Overview: Market_Depth_DOM.Overview.md
Level II Quotes¶
- MarketBookAdd.md - Subscribe to Market Depth for symbol
- MarketBookGet.md - Get current order book data
- MarketBookRelease.md - Unsubscribe from Market Depth
🔧 Additional Methods¶
- Overview: Additional_Methods.Overview.md
Advanced Symbol Information¶
- SymbolInfoMarginRate.md - Margin rates for symbol and order type
- SymbolInfoSessionQuote.md - Quote session times
- SymbolInfoSessionTrade.md - Trade session times
- SymbolParamsMany.md - Detailed parameters for multiple symbols (112 fields!)
Trading Calculations¶
- TickValueWithSize.md - Batch tick values for multiple symbols
📡 Subscriptions (Streaming)¶
- Overview: Streaming_Methods.Overview.md
Real-Time Price Updates¶
- SubscribeToTicks.md - Real-time tick stream for symbols
Trading Events¶
- OnTrade.md - Position/order changes (opened, closed, modified)
- SubscribeToTradeTransaction.md - Detailed transaction log (complete audit trail)
Position Monitoring¶
- SubscribeToPositionProfit.md - Periodic profit/loss updates
- OnPositionsAndPendingOrdersTickets.md - Periodic ticket lists (lightweight)
🎯 Quick Navigation by Use Case¶
| I want to... | Use this method |
|---|---|
| ACCOUNT INFORMATION | |
| Get complete account snapshot | AccountSummaryAsync |
| Get account balance | AccountInfoDoubleAsync (BALANCE) |
| Get account equity | AccountInfoDoubleAsync (EQUITY) |
| Get account leverage | AccountInfoIntegerAsync (LEVERAGE) |
| Get account currency | AccountInfoStringAsync (CURRENCY) |
| SYMBOL INFORMATION | |
| Get current price for symbol | SymbolInfoTickAsync |
| List all available symbols | SymbolsTotalAsync + SymbolNameAsync |
| Add symbol to Market Watch | SymbolSelectAsync (true) |
| Get symbol digits (decimal places) | SymbolInfoIntegerAsync (DIGITS) |
| Get point size for symbol | SymbolInfoDoubleAsync (POINT) |
| Get symbol volume limits | SymbolInfoDoubleAsync (VOLUME_MIN/MAX/STEP) |
| Get tick values for symbols | TickValueWithSizeAsync |
| POSITIONS & ORDERS | |
| Count open positions | PositionsTotalAsync |
| Get all open positions (full details) | OpenedOrdersAsync |
| Get position ticket numbers only | OpenedOrdersTicketsAsync |
| Get historical orders | OrderHistoryAsync |
| Get historical deals/trades | PositionsHistoryAsync |
| MARKET DEPTH | |
| Subscribe to Level II quotes | MarketBookAddAsync |
| Get order book data | MarketBookGetAsync |
| Unsubscribe from Level II | MarketBookReleaseAsync |
| TRADING OPERATIONS | |
| Open market BUY position | OrderSendAsync (type=BUY) |
| Open market SELL position | OrderSendAsync (type=SELL) |
| Place BUY LIMIT order | OrderSendAsync (type=BUY_LIMIT) |
| Place SELL LIMIT order | OrderSendAsync (type=SELL_LIMIT) |
| Place BUY STOP order | OrderSendAsync (type=BUY_STOP) |
| Place SELL STOP order | OrderSendAsync (type=SELL_STOP) |
| Modify SL/TP of position | OrderModifyAsync |
| Close a position | OrderCloseAsync |
| Calculate margin before trade | OrderCalcMarginAsync |
| Validate trade before execution | OrderCheckAsync |
| REAL-TIME SUBSCRIPTIONS | |
| Stream live prices | OnSymbolTickAsync |
| Monitor trade events | OnTradeAsync |
| Track profit changes | OnPositionProfitAsync |
| Monitor ticket changes | OnPositionsAndPendingOrdersTicketsAsync |
| Detailed transaction log | OnTradeTransactionAsync |
🏗️ API Architecture¶
Layer 1: MT5Account (Low-Level)¶
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: package/Helpers/MT5Account.cs (NuGet package source)
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 → C# primitives) - No proto objects in return values - No auto-normalization
Location: MT5Service.cs
Documentation: MT5Service.Overview.md
Layer 3: MT5Sugar¶
What: High-level convenience API with ~50 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: MT5Sugar.cs
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)¶
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 → C# primitives)
4. Practice: Simplified method calls without proto objects
Goal: Learn to build clean API wrappers on top of complex protocols.
Documentation: MT5Service.Overview.md
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 (~50 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.
Complete Reference: ReturnCodes_Reference_EN.md
C# Async Patterns¶
Request/Reply methods:
Streaming methods:
await foreach (var data in account.OnMethodAsync(parameters, cancellationToken))
{
// Process streaming data
}
Detailed Guide: Sync_vs_Async.md - When to use async vs sync, performance comparisons, best practices
⚠️ Important Notes¶
- Demo account first: Always test on demo before live trading.
- Check return codes: Every trading operation returns status code.
- Validate parameters: Use
OrderCheckAsync()beforeOrderSendAsync(). - Handle errors: Network/protocol errors can occur.
- Thread safety: Streams execute on background threads.
- Resource cleanup: Unsubscribe from streams when done (use CancellationToken).
- UTC timestamps: All times are in UTC, not local time.
- Broker limitations: Not all brokers support all features (DOM, hedging, etc.).
- Async/await: Always use
awaitwith async methods. - CancellationToken: Always provide cancellation tokens for long-running operations.
📋 Best Practices¶
Error Handling¶
try
{
var result = await account.OrderSendAsync(request);
if (result.ReturnedCode == 10009)
{
Console.WriteLine("✅ Success");
}
else
{
Console.WriteLine($"❌ Error: {result.Comment}");
}
}
catch (RpcException ex)
{
Console.WriteLine($"gRPC Error: {ex.Status}");
}
Streaming with Cancellation¶
var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
try
{
await foreach (var tick in account.OnSymbolTickAsync(symbols, cts.Token))
{
// Process tick
}
}
catch (OperationCanceledException)
{
Console.WriteLine("Stream stopped");
}
"Trade safe, code clean, and may your async operations always complete successfully."