📸 Get Account Snapshot¶
Snapshot method: retrieves complete account state in one call. Returns AccountSnapshot object with all key metrics.
API Information:
- Sugar method:
MT5Sugar.getAccountSnapshot() - Returns:
AccountSnapshot- Object containing all account metrics - Underlying:
accountSummary(),accountInfoDouble()calls
⬆️ Output¶
Returns: AccountSnapshot object with fields:
long login- Account numberdouble balance- Account balancedouble equity- Account equitydouble margin- Used margindouble freeMargin- Free margindouble marginLevel- Margin level %double profit- Current profit/losslong leverage- Account leverageString currency- Account currencyString company- Broker name
Throws: ApiExceptionMT5 if request fails
🔗 Usage Examples¶
1) Simple snapshot¶
var snapshot = sugar.getAccountSnapshot();
System.out.printf("Account: %d%n", snapshot.login);
System.out.printf("Balance: $%.2f%n", snapshot.balance);
System.out.printf("Equity: $%.2f%n", snapshot.equity);
System.out.printf("Profit: $%.2f%n", snapshot.profit);
System.out.printf("Margin level: %.2f%%%n", snapshot.marginLevel);
2) Using toString()¶
var snapshot = sugar.getAccountSnapshot();
System.out.println(snapshot.toString());
// Output:
// Account[login=12345678, balance=10000.00, equity=10150.00, margin=500.00,
// free=9650.00, level=2030.00%, profit=150.00, leverage=100, currency=USD]
3) Risk check¶
var snapshot = sugar.getAccountSnapshot();
if (snapshot.marginLevel < 200.0) {
System.out.printf("⚠️ Low margin level: %.2f%%%n", snapshot.marginLevel);
}
📌 Important Notes¶
- One call: Fetches all account data in single operation
- Immutable: Snapshot is point-in-time data
- toString(): Built-in formatted string representation
See also¶
- Symbol snapshot:
getSymbolSnapshot() - Individual getters:
getBalance(),getEquity()