π€ Get Account Info (GetAccountInfo)ΒΆ
Sugar method: Gets ALL account information in one call - balance, equity, margin, leverage, and more!
API Information:
- Method:
sugar.GetAccountInfo() - Package:
mt5(MT5Sugar) - Underlying calls:
service.GetAccountSummary(),GetMargin(),GetFreeMargin(),GetMarginLevel(),GetProfit() - Timeout: 5 seconds
- Returns: Complete AccountInfo structure
π Method SignatureΒΆ
π½ InputΒΆ
No parameters required
β¬οΈ OutputΒΆ
| Return | Type | Description |
|---|---|---|
accountInfo |
*AccountInfo |
Structure with all account data |
error |
error |
Error if query fails |
AccountInfo StructureΒΆ
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 percentage
Profit float64 // Total floating profit/loss
Currency string // Account currency (e.g., "USD", "EUR")
Leverage int64 // Account leverage (e.g., 100 for 1:100)
Company string // Broker company name
}
π¬ Just the EssentialsΒΆ
- What it is: Gets complete account snapshot in one method call.
- Why you need it: Perfect for dashboards, reports, and monitoring.
- Sanity check: One call instead of 10+ separate method calls.
π― When to UseΒΆ
β Account dashboards - Display complete account status
β Risk monitoring - Check margin level and exposure
β Daily reports - Generate account summary
β Trading bots - Get account state before trading
π Usage ExamplesΒΆ
1) Basic usage - display account infoΒΆ
info, err := sugar.GetAccountInfo()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("βββββββββββββββββββββββββββββββββββββββ\n")
fmt.Printf(" ACCOUNT INFORMATION\n")
fmt.Printf("βββββββββββββββββββββββββββββββββββββββ\n")
fmt.Printf("Login: %d\n", info.Login)
fmt.Printf("Company: %s\n", info.Company)
fmt.Printf("Currency: %s\n", info.Currency)
fmt.Printf("Leverage: 1:%d\n\n", 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 Margin: $%.2f\n", info.FreeMargin)
fmt.Printf("Margin Level: %.2f%%\n", info.MarginLevel)
fmt.Printf("βββββββββββββββββββββββββββββββββββββββ\n")
// Output example:
// βββββββββββββββββββββββββββββββββββββββ
// ACCOUNT INFORMATION
// βββββββββββββββββββββββββββββββββββββββ
// Login: 12345678
// Company: MetaQuotes Software Corp.
// Currency: USD
// Leverage: 1:100
//
// Balance: $10,000.00
// Equity: $10,250.00
// Profit: $250.00
//
// Margin: $1,100.00
// Free Margin: $9,150.00
// Margin Level: 931.82%
// βββββββββββββββββββββββββββββββββββββββ
2) Check account healthΒΆ
info, err := sugar.GetAccountInfo()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println("Account Health Check:")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
// Check 1: Margin level
if info.MarginLevel < 100 {
fmt.Println("π΄ CRITICAL: Margin level below 100%!")
fmt.Printf(" Current: %.2f%%\n", info.MarginLevel)
} else if info.MarginLevel < 200 {
fmt.Println("π WARNING: Margin level below 200%")
fmt.Printf(" Current: %.2f%%\n", info.MarginLevel)
} else {
fmt.Println("β
Margin level healthy")
fmt.Printf(" Current: %.2f%%\n", info.MarginLevel)
}
// Check 2: Drawdown
drawdown := ((info.Equity - info.Balance) / info.Balance) * 100
if drawdown < -10 {
fmt.Printf("\nπ΄ High drawdown: %.2f%%\n", drawdown)
} else if drawdown < -5 {
fmt.Printf("\nπ Moderate drawdown: %.2f%%\n", drawdown)
} else {
fmt.Printf("\nβ
Drawdown acceptable: %.2f%%\n", drawdown)
}
// Check 3: Free margin
marginUsage := (info.Margin / info.Equity) * 100
fmt.Printf("\nMargin usage: %.1f%%\n", marginUsage)
if marginUsage > 80 {
fmt.Println("π΄ Very high margin usage!")
} else if marginUsage > 50 {
fmt.Println("π High margin usage")
} else {
fmt.Println("β
Safe margin usage")
}
3) Real-time account monitorΒΆ
func MonitorAccount(sugar *mt5.MT5Sugar, intervalSeconds int) {
ticker := time.NewTicker(time.Duration(intervalSeconds) * time.Second)
defer ticker.Stop()
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β ACCOUNT MONITOR (Press Ctrl+C to stop) β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
for range ticker.C {
info, err := sugar.GetAccountInfo()
if err != nil {
fmt.Printf("Error: %v\n", err)
continue
}
timestamp := time.Now().Format("15:04:05")
fmt.Printf("\n[%s] Balance: $%.2f | Equity: $%.2f | P/L: $%.2f | Margin: %.1f%%\n",
timestamp,
info.Balance,
info.Equity,
info.Profit,
info.MarginLevel,
)
// Alert if margin level drops
if info.MarginLevel < 150 {
fmt.Printf("β οΈ WARNING: Low margin level! (%.2f%%)\n", info.MarginLevel)
}
// Alert if large loss
if info.Profit < -info.Balance*0.05 { // -5% of balance
fmt.Printf("π΄ ALERT: Large floating loss! ($%.2f)\n", info.Profit)
}
}
}
// Usage:
MonitorAccount(sugar, 5) // Update every 5 seconds
4) Daily account reportΒΆ
func GenerateDailyReport(sugar *mt5.MT5Sugar) {
info, err := sugar.GetAccountInfo()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Get today's deals
dealsToday, _ := sugar.GetDealsToday()
profitToday, _ := sugar.GetProfitToday()
dailyStats, _ := sugar.GetDailyStats()
// Get positions
openPositions, _ := sugar.GetOpenPositions()
date := time.Now().Format("2006-01-02")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("β DAILY ACCOUNT REPORT - %s β\n", date)
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("\nπ ACCOUNT STATUS")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Account: #%d (%s)\n", info.Login, info.Company)
fmt.Printf("Currency: %s\n", info.Currency)
fmt.Printf("Leverage: 1:%d\n\n", info.Leverage)
fmt.Printf("Balance: $%10.2f\n", info.Balance)
fmt.Printf("Equity: $%10.2f\n", info.Equity)
fmt.Printf("Margin: $%10.2f\n", info.Margin)
fmt.Printf("Free: $%10.2f\n", info.FreeMargin)
fmt.Printf("Margin Level: %9.2f%%\n", info.MarginLevel)
fmt.Println("\nπ TODAY'S TRADING")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Closed deals: %d\n", len(dealsToday))
if dailyStats != nil {
fmt.Printf("Win rate: %.1f%%\n", dailyStats.WinRate)
fmt.Printf("Best deal: $%.2f\n", dailyStats.BestDeal)
fmt.Printf("Worst deal: $%.2f\n", dailyStats.WorstDeal)
}
fmt.Printf("Total profit: $%.2f\n", profitToday)
fmt.Println("\nπΌ OPEN POSITIONS")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Count: %d\n", len(openPositions))
fmt.Printf("Floating P/L: $%.2f\n", info.Profit)
// Calculate daily performance
dailyReturn := (profitToday / info.Balance) * 100
fmt.Println("\nπ PERFORMANCE")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Daily return: %.2f%%\n", dailyReturn)
if info.Profit >= 0 {
fmt.Printf("Total exposure: +$%.2f\n", info.Profit+profitToday)
} else {
fmt.Printf("Total exposure: -$%.2f\n", math.Abs(info.Profit+profitToday))
}
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
}
// Usage:
GenerateDailyReport(sugar)
5) Pre-trade risk checkΒΆ
func CheckAccountBeforeTrade(sugar *mt5.MT5Sugar, requiredMargin float64) (bool, string) {
info, err := sugar.GetAccountInfo()
if err != nil {
return false, fmt.Sprintf("error getting account info: %v", err)
}
fmt.Println("Pre-Trade Risk Check:")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
// Check 1: Margin level
if info.MarginLevel < 300 {
return false, fmt.Sprintf(
"margin level too low (%.2f%%, need >300%%)",
info.MarginLevel,
)
}
fmt.Printf("β
Margin level: %.2f%%\n", info.MarginLevel)
// Check 2: Free margin
if requiredMargin > info.FreeMargin {
return false, fmt.Sprintf(
"insufficient free margin (need $%.2f, have $%.2f)",
requiredMargin, info.FreeMargin,
)
}
fmt.Printf("β
Free margin: $%.2f (need $%.2f)\n",
info.FreeMargin, requiredMargin)
// Check 3: Current drawdown
drawdown := ((info.Equity - info.Balance) / info.Balance) * 100
if drawdown < -10 {
return false, fmt.Sprintf(
"high drawdown (%.2f%%, max -10%%)",
drawdown,
)
}
fmt.Printf("β
Drawdown: %.2f%%\n", drawdown)
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β
All checks passed - safe to trade")
return true, ""
}
// Usage before trading:
requiredMargin := 500.0
canTrade, reason := CheckAccountBeforeTrade(sugar, requiredMargin)
if !canTrade {
fmt.Printf("β Cannot trade: %s\n", reason)
return
}
// Proceed with trade...
ticket, _ := sugar.BuyMarketWithPips("EURUSD", 0.1, 50, 100)
fmt.Printf("Trade opened: #%d\n", ticket)
6) Compare account snapshotsΒΆ
type AccountSnapshot struct {
Timestamp time.Time
Info *mt5.AccountInfo
}
func TakeSnapshot(sugar *mt5.MT5Sugar) (*AccountSnapshot, error) {
info, err := sugar.GetAccountInfo()
if err != nil {
return nil, err
}
return &AccountSnapshot{
Timestamp: time.Now(),
Info: info,
}, nil
}
func CompareSnapshots(before, after *AccountSnapshot) {
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β ACCOUNT COMPARISON β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
duration := after.Timestamp.Sub(before.Timestamp)
fmt.Printf("Time period: %s\n\n", duration.Round(time.Second))
// Balance change
balanceChange := after.Info.Balance - before.Info.Balance
balanceChangePercent := (balanceChange / before.Info.Balance) * 100
fmt.Println("BALANCE:")
fmt.Printf(" Before: $%.2f\n", before.Info.Balance)
fmt.Printf(" After: $%.2f\n", after.Info.Balance)
if balanceChange >= 0 {
fmt.Printf(" Change: +$%.2f (+%.2f%%)\n", balanceChange, balanceChangePercent)
} else {
fmt.Printf(" Change: -$%.2f (%.2f%%)\n", math.Abs(balanceChange), balanceChangePercent)
}
// Equity change
equityChange := after.Info.Equity - before.Info.Equity
equityChangePercent := (equityChange / before.Info.Equity) * 100
fmt.Println("\nEQUITY:")
fmt.Printf(" Before: $%.2f\n", before.Info.Equity)
fmt.Printf(" After: $%.2f\n", after.Info.Equity)
if equityChange >= 0 {
fmt.Printf(" Change: +$%.2f (+%.2f%%)\n", equityChange, equityChangePercent)
} else {
fmt.Printf(" Change: -$%.2f (%.2f%%)\n", math.Abs(equityChange), equityChangePercent)
}
// Margin level
fmt.Println("\nMARGIN LEVEL:")
fmt.Printf(" Before: %.2f%%\n", before.Info.MarginLevel)
fmt.Printf(" After: %.2f%%\n", after.Info.MarginLevel)
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
}
// Usage:
// Take snapshot before trading
snapshot1, _ := TakeSnapshot(sugar)
// ... do some trading ...
time.Sleep(1 * time.Hour)
// Take snapshot after trading
snapshot2, _ := TakeSnapshot(sugar)
// Compare
CompareSnapshots(snapshot1, snapshot2)
7) Account status widgetΒΆ
func ShowAccountWidget(sugar *mt5.MT5Sugar) {
info, err := sugar.GetAccountInfo()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Determine account health status
var healthStatus string
var healthColor string
if info.MarginLevel < 100 {
healthStatus = "CRITICAL"
healthColor = "π΄"
} else if info.MarginLevel < 200 {
healthStatus = "WARNING"
healthColor = "π "
} else if info.MarginLevel < 500 {
healthStatus = "MODERATE"
healthColor = "π‘"
} else {
healthStatus = "HEALTHY"
healthColor = "π’"
}
// Calculate metrics
marginUsage := (info.Margin / info.Equity) * 100
drawdown := ((info.Equity - info.Balance) / info.Balance) * 100
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("β Account #%d%-23sβ\n", info.Login, "")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββ€")
fmt.Printf("β Balance: $%-28.2fβ\n", info.Balance)
fmt.Printf("β Equity: $%-28.2fβ\n", info.Equity)
fmt.Printf("β P/L: $%-28.2fβ\n", info.Profit)
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββ€")
fmt.Printf("β Margin: %-29.1f%%β\n", marginUsage)
fmt.Printf("β Drawdown: %-29.2f%%β\n", drawdown)
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββ€")
fmt.Printf("β Status: %s %-26sβ\n", healthColor, healthStatus)
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββ")
}
// Usage:
ShowAccountWidget(sugar)
// Output:
// ββββββββββββββββββββββββββββββββββββββββ
// β Account #12345678
// ββββββββββββββββββββββββββββββββββββββββ
// β Balance: $10,000.00
// β Equity: $10,250.00
// β P/L: $250.00
// ββββββββββββββββββββββββββββββββββββββββ
// β Margin: 10.7%
// β Drawdown: 2.50%
// ββββββββββββββββββββββββββββββββββββββββ
// β Status: π’ HEALTHY
// ββββββββββββββββββββββββββββββββββββββββ
8) Export account data to JSONΒΆ
import "encoding/json"
func ExportAccountToJSON(sugar *mt5.MT5Sugar, filename string) error {
info, err := sugar.GetAccountInfo()
if err != nil {
return err
}
// Create export structure with timestamp
export := struct {
Timestamp string `json:"timestamp"`
AccountInfo *mt5.AccountInfo `json:"account_info"`
}{
Timestamp: time.Now().Format(time.RFC3339),
AccountInfo: info,
}
// Marshal to JSON
data, err := json.MarshalIndent(export, "", " ")
if err != nil {
return err
}
// Write to file
err = os.WriteFile(filename, data, 0644)
if err != nil {
return err
}
fmt.Printf("β
Account data exported to %s\n", filename)
return nil
}
// Usage:
err := ExportAccountToJSON(sugar, "account_snapshot.json")
if err != nil {
fmt.Printf("Export failed: %v\n", err)
}
// Result: account_snapshot.json
// {
// "timestamp": "2024-01-15T14:30:00Z",
// "account_info": {
// "Login": 12345678,
// "Balance": 10000.00,
// "Equity": 10250.00,
// "Margin": 1100.00,
// "FreeMargin": 9150.00,
// "MarginLevel": 931.82,
// "Profit": 250.00,
// "Currency": "USD",
// "Leverage": 100,
// "Company": "MetaQuotes Software Corp."
// }
// }
9) Multi-account managerΒΆ
type AccountManager struct {
accounts map[string]*mt5.MT5Sugar
}
func NewAccountManager() *AccountManager {
return &AccountManager{
accounts: make(map[string]*mt5.MT5Sugar),
}
}
func (am *AccountManager) AddAccount(name string, sugar *mt5.MT5Sugar) {
am.accounts[name] = sugar
}
func (am *AccountManager) ShowAllAccounts() {
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β MULTI-ACCOUNT OVERVIEW β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
totalBalance := 0.0
totalEquity := 0.0
totalProfit := 0.0
for name, sugar := range am.accounts {
info, err := sugar.GetAccountInfo()
if err != nil {
fmt.Printf("\n%s: β Error - %v\n", name, err)
continue
}
totalBalance += info.Balance
totalEquity += info.Equity
totalProfit += info.Profit
fmt.Printf("\n%s:\n", name)
fmt.Printf(" Balance: $%10.2f\n", info.Balance)
fmt.Printf(" Equity: $%10.2f\n", info.Equity)
fmt.Printf(" P/L: $%10.2f\n", info.Profit)
fmt.Printf(" Margin: %9.2f%%\n", info.MarginLevel)
}
fmt.Println("\nβββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("TOTAL ACROSS ALL ACCOUNTS:\n")
fmt.Printf(" Balance: $%10.2f\n", totalBalance)
fmt.Printf(" Equity: $%10.2f\n", totalEquity)
fmt.Printf(" P/L: $%10.2f\n", totalProfit)
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
}
// Usage:
manager := NewAccountManager()
manager.AddAccount("Main", sugar1)
manager.AddAccount("Backup", sugar2)
manager.AddAccount("Testing", sugar3)
manager.ShowAllAccounts()
10) Advanced account dashboardΒΆ
type AccountDashboard struct {
sugar *mt5.MT5Sugar
}
func NewAccountDashboard(sugar *mt5.MT5Sugar) *AccountDashboard {
return &AccountDashboard{sugar: sugar}
}
func (ad *AccountDashboard) Render() error {
// Get account info
info, err := ad.sugar.GetAccountInfo()
if err != nil {
return err
}
// Get additional data
positions, _ := ad.sugar.GetOpenPositions()
dealsToday, _ := ad.sugar.GetDealsToday()
dailyStats, _ := ad.sugar.GetDailyStats()
// Calculate metrics
marginUsage := (info.Margin / info.Equity) * 100
drawdown := ((info.Equity - info.Balance) / info.Balance) * 100
dailyReturn := 0.0
if dailyStats != nil && len(dealsToday) > 0 {
dailyProfit, _ := ad.sugar.GetProfitToday()
dailyReturn = (dailyProfit / info.Balance) * 100
}
// Render dashboard
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β TRADING DASHBOARD β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
// Account section
fmt.Println("\nπ ACCOUNT OVERVIEW")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Account: #%d\n", info.Login)
fmt.Printf("Broker: %s\n", info.Company)
fmt.Printf("Currency: %s\n", info.Currency)
fmt.Printf("Leverage: 1:%d\n", info.Leverage)
// Balance section
fmt.Println("\nπ° BALANCE & EQUITY")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Balance: $%10.2f\n", info.Balance)
fmt.Printf("Equity: $%10.2f\n", info.Equity)
fmt.Printf("Floating P/L: $%9.2f", info.Profit)
if info.Profit >= 0 {
fmt.Printf(" π’\n")
} else {
fmt.Printf(" π΄\n")
}
fmt.Printf("Drawdown: %10.2f%%\n", drawdown)
// Margin section
fmt.Println("\nπ MARGIN USAGE")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Used: $%10.2f\n", info.Margin)
fmt.Printf("Free: $%10.2f\n", info.FreeMargin)
fmt.Printf("Level: %10.2f%%", info.MarginLevel)
if info.MarginLevel < 100 {
fmt.Printf(" π΄\n")
} else if info.MarginLevel < 200 {
fmt.Printf(" π \n")
} else {
fmt.Printf(" π’\n")
}
fmt.Printf("Usage: %10.1f%%\n", marginUsage)
// Positions section
fmt.Println("\nπΌ OPEN POSITIONS")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Count: %d\n", len(positions))
if len(positions) > 0 {
buyCount := 0
sellCount := 0
for _, pos := range positions {
if pos.Type == 0 {
buyCount++
} else {
sellCount++
}
}
fmt.Printf("BUY: %d\n", buyCount)
fmt.Printf("SELL: %d\n", sellCount)
}
// Today's trading
if dailyStats != nil {
fmt.Println("\nπ TODAY'S PERFORMANCE")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Trades: %d\n", dailyStats.TotalDeals)
fmt.Printf("Win rate: %.1f%%\n", dailyStats.WinRate)
fmt.Printf("Profit: $%.2f", dailyStats.TotalProfit)
if dailyStats.TotalProfit >= 0 {
fmt.Printf(" π’\n")
} else {
fmt.Printf(" π΄\n")
}
fmt.Printf("Return: %.2f%%\n", dailyReturn)
}
fmt.Println("βββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
return nil
}
// Usage:
dashboard := NewAccountDashboard(sugar)
// Update dashboard every 10 seconds
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
for range ticker.C {
// Clear screen (optional)
fmt.Print("\033[H\033[2J")
// Render dashboard
if err := dashboard.Render(); err != nil {
fmt.Printf("Error: %v\n", err)
}
}
π Related MethodsΒΆ
π¦ Methods used internally:
service.GetAccountSummary()- Get core account dataGetMargin()- Get used marginGetFreeMargin()- Get free marginGetMarginLevel()- Get margin levelGetProfit()- Get floating P/L
π¬ Complementary sugar methods:
GetDailyStats()- Get today's trading stats βGetDealsToday()- Get today's closed positionsGetOpenPositions()- Get currently open positionsGetBalance()- Get balance onlyGetEquity()- Get equity only
Use cases:
// Complete account snapshot
info, _ := sugar.GetAccountInfo()
// Just need balance
balance, _ := sugar.GetBalance()
// Full dashboard
info, _ := sugar.GetAccountInfo()
stats, _ := sugar.GetDailyStats()
positions, _ := sugar.GetOpenPositions()
β οΈ Common PitfallsΒΆ
1) Confusing balance and equityΒΆ
info, _ := sugar.GetAccountInfo()
// β WRONG - using balance to check if can trade
if info.Balance > 1000 {
// Balance doesn't include floating P/L!
}
// β
CORRECT - use equity (includes floating P/L)
if info.Equity > 1000 {
// Equity = Balance + Floating P/L
}
2) Not checking margin levelΒΆ
// β WRONG - ignoring margin level
info, _ := sugar.GetAccountInfo()
sugar.BuyMarket("EURUSD", 10.0) // Might cause margin call!
// β
CORRECT - check margin level first
info, _ := sugar.GetAccountInfo()
if info.MarginLevel < 300 {
fmt.Println("Margin level too low!")
return
}
3) Using stale dataΒΆ
// β WRONG - using old account info
info, _ := sugar.GetAccountInfo()
time.Sleep(10 * time.Minute)
// info is now stale!
if info.FreeMargin > 1000 {
sugar.BuyMarket("EURUSD", 1.0)
}
// β
CORRECT - get fresh data before trading
info, _ := sugar.GetAccountInfo()
if info.FreeMargin > 1000 {
sugar.BuyMarket("EURUSD", 1.0)
}
4) Not handling errorsΒΆ
// β WRONG - ignoring errors
info, _ := sugar.GetAccountInfo()
fmt.Printf("Balance: $%.2f\n", info.Balance) // Might panic!
// β
CORRECT - check errors
info, err := sugar.GetAccountInfo()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Balance: $%.2f\n", info.Balance)
5) Misunderstanding margin levelΒΆ
// β WRONG - thinking higher margin is good
info, _ := sugar.GetAccountInfo()
if info.Margin > 5000 {
fmt.Println("High margin is good!") // NO!
}
// β
CORRECT - higher margin LEVEL % is good
if info.MarginLevel > 500 {
fmt.Println("Healthy margin level")
}
// Margin = how much you're using (lower is better)
// Margin Level = (Equity/Margin)*100 (higher is better)
π Pro TipsΒΆ
-
One call, all data - More efficient than separate calls
-
Check margin level - Below 100% = margin call risk
-
Monitor equity, not balance - Equity includes floating P/L
-
Refresh frequently - Account info changes constantly
-
Use for dashboards - Perfect for real-time monitoring
-
Margin Level formula - (Equity / Margin) Γ 100
-
Margin usage - (Margin / Equity) Γ 100 = % of equity used
π Account Metrics ExplainedΒΆ
Balance:
- Your account balance (realized P/L only)
- Doesn't change until you close positions
Equity:
- Balance + Floating P/L
- Changes in real-time with price movements
- Equity = Balance + Profit
Margin:
- How much margin you're using
- Lower is better (less risk)
Free Margin:
- Equity - Margin
- How much you can still use for new positions
Margin Level:
- (Equity / Margin) Γ 100
- Higher is better
- Below 100% = margin call
- Above 200% = safe
- Above 500% = very safe
Margin Usage:
- (Margin / Equity) Γ 100
- Lower is better
- Above 80% = very risky
- Below 30% = conservative
See also: GetDailyStats.md