MT5Sugar Β· AccountInfo StructureΒΆ
Complete account information structure returned by GetAccountInfo(). Contains all essential account metrics in one convenient package.
π Structure DefinitionΒΆ
type AccountInfo struct {
Login int64 // Account login number
Balance float64 // Account balance
Equity float64 // Current equity (balance + floating P/L)
Margin float64 // Used margin
FreeMargin float64 // Free margin available
MarginLevel float64 // Margin level % ((Equity/Margin)*100)
Profit float64 // Total floating profit/loss
Currency string // Account currency (USD, EUR, etc.)
Leverage int64 // Account leverage (100 = 1:100)
Company string // Broker company name
}
π Field DetailsΒΆ
Login (int64)ΒΆ
- What: MT5 account number
- Example:
591129415 - Use: Account identification, logging, reports
Balance (float64)ΒΆ
- What: Realized balance (closed positions only)
- Formula: Initial deposit + realized profits - realized losses
- Example:
10000.00 - Important: Does NOT include floating P/L from open positions
Equity (float64)ΒΆ
- What: Real-time account value
- Formula: Balance + Profit (floating P/L)
- Example:
10250.75 - Important: Changes with every price tick if you have open positions
Margin (float64)ΒΆ
- What: Total margin used by open positions
- Formula: Sum of all position margins
- Example:
500.00 - Important: Higher margin = less available for new trades
FreeMargin (float64)ΒΆ
- What: Margin available for new positions
- Formula: Equity - Margin
- Example:
9750.75 - Important: New positions reduce this value
MarginLevel (float64)ΒΆ
- What: Margin safety indicator (percentage)
- Formula: (Equity / Margin) Γ 100
- Example:
2050.15(means 2050.15%) - Critical levels:
- Below 100% = Margin call risk
- Below 50% = Stop out (broker closes positions)
- Above 1000% = Very safe
Profit (float64)ΒΆ
- What: Total floating profit/loss from ALL open positions
- Formula: Sum of all open position P/L
- Example:
250.75(positive = profit, negative = loss) - Important: Changes in real-time with price movements
Currency (string)ΒΆ
- What: Account base currency
- Example:
"USD","EUR","GBP" - Use: Profit calculations, reporting
Leverage (int64)ΒΆ
- What: Account leverage multiplier
- Example:
100(means 1:100 leverage) - Common values: 50, 100, 200, 500
- Impact: Higher leverage = less margin needed
Company (string)ΒΆ
- What: Broker/company name
- Example:
"FxPro Financial Services Ltd" - Use: Identification, multi-account management
π― Common CalculationsΒΆ
Drawdown (%)ΒΆ
drawdown := ((info.Equity - info.Balance) / info.Balance) * 100
// Negative = losing, Positive = winning
Margin Usage (%)ΒΆ
Available CapacityΒΆ
capacity := info.FreeMargin / info.Margin
// How many times current position size you can still open
Daily Return (%)ΒΆ
// Requires yesterday's balance
dailyReturn := ((info.Balance - yesterdayBalance) / yesterdayBalance) * 100
π’ Usage ExamplesΒΆ
Example 1: Basic account displayΒΆ
info, _ := sugar.GetAccountInfo()
fmt.Printf("Account: #%d (%s)\n", info.Login, info.Company)
fmt.Printf("Currency: %s, Leverage: 1:%d\n\n", info.Currency, info.Leverage)
fmt.Printf("Balance: $%.2f\n", info.Balance)
fmt.Printf("Equity: $%.2f\n", info.Equity)
fmt.Printf("Profit: $%.2f\n\n", info.Profit)
fmt.Printf("Margin: $%.2f\n", info.Margin)
fmt.Printf("Free: $%.2f\n", info.FreeMargin)
fmt.Printf("Level: %.2f%%\n", info.MarginLevel)
Example 2: Risk assessmentΒΆ
info, _ := sugar.GetAccountInfo()
// Check margin level
if info.MarginLevel < 100 {
fmt.Println("π΄ CRITICAL: Margin call risk!")
} else if info.MarginLevel < 200 {
fmt.Println("π WARNING: Low margin level")
} else if info.MarginLevel < 500 {
fmt.Println("π‘ CAUTION: Moderate margin level")
} else {
fmt.Println("β
Healthy margin level")
}
// Check margin usage
marginUsage := (info.Margin / info.Equity) * 100
fmt.Printf("Margin usage: %.1f%%\n", marginUsage)
if marginUsage > 50 {
fmt.Println("β οΈ High margin usage - reduce exposure")
}
Example 3: Drawdown monitoringΒΆ
info, _ := sugar.GetAccountInfo()
drawdown := ((info.Equity - info.Balance) / info.Balance) * 100
fmt.Printf("Current drawdown: %.2f%%\n", drawdown)
if drawdown < -10 {
fmt.Println("π΄ ALERT: Drawdown exceeds 10%!")
} else if drawdown < -5 {
fmt.Println("β οΈ WARNING: Significant drawdown")
} else if drawdown > 0 {
fmt.Printf("β
In profit: +%.2f%%\n", drawdown)
}
Example 4: Position sizing calculatorΒΆ
info, _ := sugar.GetAccountInfo()
// Use 1% risk per trade
riskPercent := 1.0
riskAmount := info.Balance * (riskPercent / 100)
fmt.Printf("Account balance: $%.2f\n", info.Balance)
fmt.Printf("Risk per trade (1%%): $%.2f\n", riskAmount)
// Check available margin
availableRisk := info.FreeMargin * 0.2 // Use only 20% of free margin
fmt.Printf("Max safe risk: $%.2f\n", availableRisk)
if riskAmount > availableRisk {
fmt.Println("β οΈ Reduce position size - insufficient margin")
}
Example 5: Multi-account comparisonΒΆ
accounts := []*mt5.AccountInfo{account1, account2, account3}
fmt.Println("ACCOUNT COMPARISON")
fmt.Println("==================")
for i, info := range accounts {
fmt.Printf("\nAccount %d: #%d\n", i+1, info.Login)
fmt.Printf(" Balance: $%.2f\n", info.Balance)
fmt.Printf(" Equity: $%.2f\n", info.Equity)
fmt.Printf(" Profit: $%.2f\n", info.Profit)
fmt.Printf(" Margin: %.2f%%\n", info.MarginLevel)
}
Example 6: JSON exportΒΆ
info, _ := sugar.GetAccountInfo()
// Convert to JSON
jsonData, _ := json.MarshalIndent(info, "", " ")
fmt.Println(string(jsonData))
// Output:
// {
// "Login": 591129415,
// "Balance": 10000.00,
// "Equity": 10250.75,
// "Margin": 500.00,
// ...
// }
Example 7: Database recordΒΆ
type AccountSnapshot struct {
Timestamp time.Time
Account *mt5.AccountInfo
}
func saveSnapshot(info *mt5.AccountInfo) {
snapshot := AccountSnapshot{
Timestamp: time.Now(),
Account: info,
}
// Save to database
db.Insert("snapshots", snapshot)
fmt.Printf("Snapshot saved: %s\n", snapshot.Timestamp)
}
Example 8: Alert systemΒΆ
func checkAccountHealth(info *mt5.AccountInfo) []string {
var alerts []string
// Margin level check
if info.MarginLevel < 100 {
alerts = append(alerts, "CRITICAL: Margin level below 100%")
}
// Drawdown check
drawdown := ((info.Equity - info.Balance) / info.Balance) * 100
if drawdown < -15 {
alerts = append(alerts, fmt.Sprintf("CRITICAL: Drawdown %.1f%%", drawdown))
}
// Large position check
marginUsage := (info.Margin / info.Equity) * 100
if marginUsage > 70 {
alerts = append(alerts, "WARNING: High margin usage")
}
// Floating loss check
if info.Profit < -1000 {
alerts = append(alerts, fmt.Sprintf("WARNING: Large floating loss $%.2f", info.Profit))
}
return alerts
}
// Usage
info, _ := sugar.GetAccountInfo()
alerts := checkAccountHealth(info)
if len(alerts) > 0 {
fmt.Println("π¨ ALERTS:")
for _, alert := range alerts {
fmt.Printf(" - %s\n", alert)
}
} else {
fmt.Println("β
All systems normal")
}
Example 9: Daily reportΒΆ
func generateDailyReport(info *mt5.AccountInfo, stats *mt5.DailyStats) {
fmt.Println("ββββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β DAILY TRADING REPORT β")
fmt.Println("ββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("\nπ ACCOUNT: #%d (%s)\n", info.Login, info.Company)
fmt.Printf("Currency: %s, Leverage: 1:%d\n\n", info.Currency, info.Leverage)
fmt.Println("π° BALANCE SHEET")
fmt.Printf("Balance: $%.2f\n", info.Balance)
fmt.Printf("Equity: $%.2f\n", info.Equity)
fmt.Printf("Floating P/L: $%.2f\n", info.Profit)
fmt.Println("\nπ MARGIN STATUS")
fmt.Printf("Used margin: $%.2f\n", info.Margin)
fmt.Printf("Free margin: $%.2f\n", info.FreeMargin)
fmt.Printf("Margin level: %.2f%%\n", info.MarginLevel)
fmt.Println("\nπ TODAY'S STATS")
fmt.Printf("Trades: %d\n", stats.TotalDeals)
fmt.Printf("Win rate: %.1f%%\n", stats.WinRate)
fmt.Printf("Total profit: $%.2f\n", stats.TotalProfit)
}
Example 10: Risk calculatorΒΆ
func calculateMaxPosition(info *mt5.AccountInfo, symbol string, riskPercent float64) {
// Risk amount
riskAmount := info.Balance * (riskPercent / 100)
// Available margin check
usableMargin := info.FreeMargin * 0.5 // Use only 50%
fmt.Printf("Account Balance: $%.2f\n", info.Balance)
fmt.Printf("Risk Amount (%%.1f%%): $%.2f\n", riskPercent, riskAmount)
fmt.Printf("Usable Margin: $%.2f\n", usableMargin)
// Calculate position size
lotSize, _ := sugar.CalculatePositionSize(symbol, riskPercent, 50)
// Check if affordable
requiredMargin, _ := sugar.CalculateRequiredMargin(symbol, lotSize)
if requiredMargin > usableMargin {
fmt.Println("β Position size exceeds available margin")
lotSize = lotSize * (usableMargin / requiredMargin)
fmt.Printf("Adjusted lot size: %.2f\n", lotSize)
} else {
fmt.Printf("β
Safe lot size: %.2f\n", lotSize)
}
}
π RelatedΒΆ
- GetAccountInfo - method that returns this structure
- DailyStats - trading statistics structure
β οΈ Important NotesΒΆ
-
Balance vs Equity - Balance = realized only, Equity = real-time value
-
Margin Level - Below 100% is danger zone!
-
Floating Profit - Changes every tick if positions are open
-
Free Margin - Required for opening new positions
-
Currency - All monetary values in this currency
π‘ Quick ReferenceΒΆ
| Field | Meaning | When to use |
|---|---|---|
Balance |
Realized money | Performance tracking |
Equity |
Real-time value | Current account worth |
Margin |
Used margin | Risk monitoring |
FreeMargin |
Available margin | Position sizing |
MarginLevel |
Safety % | Risk alerts |
Profit |
Floating P/L | Real-time monitoring |
Summary: AccountInfo structure provides complete account snapshot. Use Balance for historical tracking, Equity for current value, and MarginLevel for risk monitoring. Essential for risk management and account monitoring.