MT5Service - Symbol Convenience MethodsΒΆ
7 convenient methods for quick access to symbol properties + 1 smart combination method
π― Why These Methods ExistΒΆ
Problem: Getting symbol properties in MT5Account requires enum parameters and .Value unwrapping:
var bidData = await account.SymbolInfoDoubleAsync("EURUSD", SymbolInfoDoubleProperty.SymbolBid);
double bid = bidData.Value; // β unwrapping!
Solution: MT5Service provides direct methods with clear names:
Benefits:
- β
Readable names (
GetBidvsSymbolInfoDouble(SymbolBid)) - β No enum parameters needed
- β
No
.Valueunwrapping - β Smart combinations (availability check = Exist + Synchronized)
π All 7 Methods + 1 Smart MethodΒΆ
| Method | Returns | Low-Level Equivalent |
|---|---|---|
GetBidAsync(symbol) |
Current bid price | SymbolInfoDoubleAsync(symbol, SymbolBid) |
GetAskAsync(symbol) |
Current ask price | SymbolInfoDoubleAsync(symbol, SymbolAsk) |
GetSpreadAsync(symbol) |
Current spread in points | SymbolInfoIntegerAsync(symbol, SymbolSpread) |
GetVolumeMinAsync(symbol) |
Minimum lot size | SymbolInfoDoubleAsync(symbol, SymbolVolumeMin) |
GetVolumeMaxAsync(symbol) |
Maximum lot size | SymbolInfoDoubleAsync(symbol, SymbolVolumeMax) |
GetVolumeStepAsync(symbol) |
Volume step increment | SymbolInfoDoubleAsync(symbol, SymbolVolumeStep) |
IsTradingAllowedAsync() |
Trading permission check | AccountInfoIntegerAsync(AccountTradeAllowed) |
IsSymbolAvailableAsync(symbol) |
Smart: Exist + Synchronized | 2 calls combined! |
π‘ Usage ExamplesΒΆ
Example 1: Getting Current Quote (Bid/Ask)ΒΆ
// β BEFORE (MT5Account) - 4 lines:
var bidData = await account.SymbolInfoDoubleAsync("EURUSD", SymbolInfoDoubleProperty.SymbolBid);
double bid = bidData.Value;
var askData = await account.SymbolInfoDoubleAsync("EURUSD", SymbolInfoDoubleProperty.SymbolAsk);
double ask = askData.Value;
// β
AFTER (MT5Service) - 2 lines:
double bid = await service.GetBidAsync("EURUSD");
double ask = await service.GetAskAsync("EURUSD");
Console.WriteLine($"EURUSD: Bid={bid:F5}, Ask={ask:F5}");
Code reduction: 50% (4 lines β 2 lines)
Example 2: Calculating SpreadΒΆ
// β BEFORE (MT5Account):
var spreadData = await account.SymbolInfoIntegerAsync("GBPUSD", SymbolInfoIntegerProperty.SymbolSpread);
long spread = spreadData.Value;
Console.WriteLine($"Spread: {spread} points");
// β
AFTER (MT5Service):
long spread = await service.GetSpreadAsync("GBPUSD");
Console.WriteLine($"Spread: {spread} points");
// Or calculate spread in price:
double bid = await service.GetBidAsync("GBPUSD");
double ask = await service.GetAskAsync("GBPUSD");
double spreadPrice = ask - bid;
Console.WriteLine($"Spread: {spreadPrice:F5} ({spread} points)");
Example 3: Validating Volume Before OrderΒΆ
// β BEFORE (MT5Account) - 6 lines:
var minData = await account.SymbolInfoDoubleAsync("XAUUSD", SymbolInfoDoubleProperty.SymbolVolumeMin);
double minVol = minData.Value;
var maxData = await account.SymbolInfoDoubleAsync("XAUUSD", SymbolInfoDoubleProperty.SymbolVolumeMax);
double maxVol = maxData.Value;
var stepData = await account.SymbolInfoDoubleAsync("XAUUSD", SymbolInfoDoubleProperty.SymbolVolumeStep);
double step = stepData.Value;
double requestedVolume = 0.15;
if (requestedVolume < minVol)
{
Console.WriteLine($"β Volume too small! Min: {minVol}");
}
else if (requestedVolume > maxVol)
{
Console.WriteLine($"β Volume too large! Max: {maxVol}");
}
else if ((requestedVolume % step) != 0)
{
Console.WriteLine($"β Invalid volume step! Step: {step}");
}
// β
AFTER (MT5Service) - 3 lines:
double minVol = await service.GetVolumeMinAsync("XAUUSD");
double maxVol = await service.GetVolumeMaxAsync("XAUUSD");
double step = await service.GetVolumeStepAsync("XAUUSD");
double requestedVolume = 0.15;
if (requestedVolume < minVol)
{
Console.WriteLine($"β Volume too small! Min: {minVol}");
}
else if (requestedVolume > maxVol)
{
Console.WriteLine($"β Volume too large! Max: {maxVol}");
}
else if ((requestedVolume % step) != 0)
{
Console.WriteLine($"β Invalid volume step! Step: {step}");
}
Code reduction: 50% (6 lines β 3 lines for data retrieval)
Example 4: Smart Symbol Availability Check βΒΆ
// β BEFORE (MT5Account) - 2 separate calls + unwrapping:
var existsData = await account.SymbolExistAsync("BTCUSD");
if (!existsData.Exists)
{
Console.WriteLine("β Symbol doesn't exist!");
return;
}
var syncData = await account.SymbolIsSynchronizedAsync("BTCUSD");
if (!syncData.Synchronized)
{
Console.WriteLine("β Symbol not synchronized!");
return;
}
Console.WriteLine("β
Symbol ready to trade!");
// β
AFTER (MT5Service) - 1 smart call:
bool available = await service.IsSymbolAvailableAsync("BTCUSD");
if (!available)
{
Console.WriteLine("β Symbol not available (doesn't exist or not synchronized)!");
return;
}
Console.WriteLine("β
Symbol ready to trade!");
Smart combination: 2 server calls β 1 method call!
Example 5: Pre-Trade Validation (Full Example)ΒΆ
// Complete validation before placing order
string symbol = "EURUSD";
double requestedVolume = 0.05;
// Check trading is allowed
bool tradingAllowed = await service.IsTradingAllowedAsync();
if (!tradingAllowed)
{
Console.WriteLine("β Trading not allowed on this account!");
return;
}
// Check symbol availability (smart check!)
bool symbolAvailable = await service.IsSymbolAvailableAsync(symbol);
if (!symbolAvailable)
{
Console.WriteLine($"β Symbol {symbol} not available!");
return;
}
// Check volume constraints
double minVol = await service.GetVolumeMinAsync(symbol);
double maxVol = await service.GetVolumeMaxAsync(symbol);
double step = await service.GetVolumeStepAsync(symbol);
if (requestedVolume < minVol || requestedVolume > maxVol)
{
Console.WriteLine($"β Volume {requestedVolume} out of range [{minVol}, {maxVol}]");
return;
}
if ((requestedVolume % step) != 0)
{
Console.WriteLine($"β Volume must be multiple of {step}");
return;
}
// All checks passed!
Console.WriteLine("β
All validations passed, ready to trade!");
// Place order...
var result = await service.BuyMarketAsync(symbol, requestedVolume);
Example 6: Monitoring Multiple SymbolsΒΆ
// Monitor quotes for multiple symbols
string[] symbols = { "EURUSD", "GBPUSD", "USDJPY", "XAUUSD" };
foreach (var symbol in symbols)
{
// Check availability first
if (!await service.IsSymbolAvailableAsync(symbol))
{
Console.WriteLine($"β οΈ {symbol} not available, skipping...");
continue;
}
// Get quote
double bid = await service.GetBidAsync(symbol);
double ask = await service.GetAskAsync(symbol);
long spread = await service.GetSpreadAsync(symbol);
Console.WriteLine($"{symbol}: Bid={bid:F5}, Ask={ask:F5}, Spread={spread}pts");
}
Example 7: Parallel Quote RetrievalΒΆ
// Get bid/ask for multiple symbols in parallel
var tasks = new[]
{
service.GetBidAsync("EURUSD"),
service.GetBidAsync("GBPUSD"),
service.GetBidAsync("USDJPY")
};
await Task.WhenAll(tasks);
Console.WriteLine($"EURUSD Bid: {tasks[0].Result:F5}");
Console.WriteLine($"GBPUSD Bid: {tasks[1].Result:F5}");
Console.WriteLine($"USDJPY Bid: {tasks[2].Result:F5}");
Performance: All requests execute concurrently!
π Key BenefitsΒΆ
| Aspect | MT5Account (Low-Level) | MT5Service (Convenience) |
|---|---|---|
| Code | 2 lines per value | 1 line per value |
| Enums | Always required | β Not needed |
| Unwrapping | Always .Value |
β Not needed |
| Availability Check | 2 separate calls | β 1 smart method |
| Readability | SymbolInfoDouble(SymbolBid) |
GetBid() |
| Error-prone | Can forget .Value |
β Impossible |
β Special: IsSymbolAvailableAsync()ΒΆ
This is a smart combination method that does more than just unwrap values!
// What it does internally:
public async Task<bool> IsSymbolAvailableAsync(string symbol)
{
// 1. Check if symbol exists
var exists = await SymbolExistAsync(symbol);
if (!exists) return false;
// 2. Check if symbol is synchronized with server
return await SymbolIsSynchronizedAsync(symbol);
}
Benefits:
- β 2 server calls β 1 method call
- β Clear intent: "Can I trade this symbol?"
- β Prevents common mistake (checking Exist but forgetting Synchronized)
- β Less code, fewer errors
π Code Reduction StatisticsΒΆ
| Task | Lines (MT5Account) | Lines (MT5Service) | Reduction |
|---|---|---|---|
| Get 1 value | 2 | 1 | 50% |
| Get Bid+Ask | 4 | 2 | 50% |
| Get volume constraints | 6 | 3 | 50% |
| Check availability | 8 | 1 | 87.5% |
Average reduction: 60%+ for symbol operations!
π When to UseΒΆ
β Use MT5Service when:ΒΆ
- Need quick access to common symbol properties (bid, ask, spread)
- Validating volumes before placing orders
- Checking symbol availability
- Writing trading strategies
- Want clean, readable code
β οΈ Use MT5Account when:ΒΆ
- Need exotic symbol properties (no convenience method)
- Building custom wrappers
- Require low-level control
π See AlsoΒΆ
- MT5Service Overview - Complete MT5Service improvements
- Account Convenience Methods - Account shortcuts
- Trading Convenience Methods - Trading shortcuts
- MT5Account Symbol Methods - Low-level reference
π‘ SummaryΒΆ
7 convenience methods + 1 smart combination make symbol operations cleaner and safer:
// Quick quote check:
double bid = await service.GetBidAsync("EURUSD");
double ask = await service.GetAskAsync("EURUSD");
// Smart availability check:
if (await service.IsSymbolAvailableAsync("EURUSD"))
{
// Ready to trade!
}
// Volume validation:
double min = await service.GetVolumeMinAsync("EURUSD");
double max = await service.GetVolumeMaxAsync("EURUSD");
double step = await service.GetVolumeStepAsync("EURUSD");
Simple, safe, fast! π