Skip to content

πŸ“…πŸ’Ό Get Deals Today (GetDealsToday)ΒΆ

Sugar method: Returns all closed positions (deals) from today (00:00 to now).

API Information:

  • Method: sugar.GetDealsToday()
  • Timeout: 5 seconds
  • Returns: Slice of position history info

πŸ“‹ Method SignatureΒΆ

func (s *MT5Sugar) GetDealsToday() ([]*pb.PositionHistoryInfo, error)

πŸ”½ Input / ⬆️ OutputΒΆ

Input Type Description
None - No parameters (auto-calculates today's range)
Output Type Description
[]*pb.PositionHistoryInfo slice All closed positions from today
error error Error if retrieval failed

πŸ’¬ Just the EssentialsΒΆ

  • What it is: Get all closed trades from today (00:00 to current time).
  • Why you need it: Daily performance tracking, today's profit/loss analysis, trade review.
  • Sanity check: Returns empty slice if no deals today. Automatically calculates today's time range.

🎯 When to Use¢

βœ… Daily reports - Generate today's trading summary

βœ… Performance tracking - Monitor today's profit/loss

βœ… Trade journal - Review today's completed trades

βœ… Real-time updates - Check latest closed positions


πŸ”— Usage ExamplesΒΆ

1) Basic usage - show today's dealsΒΆ

deals, err := sugar.GetDealsToday()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}

if len(deals) == 0 {
    fmt.Println("No deals today")
    return
}

fmt.Printf("Today's deals: %d\n\n", len(deals))

for i, deal := range deals {
    fmt.Printf("%d. Ticket #%d: %s %.2f lots\n",
        i+1, deal.Ticket, deal.Symbol, deal.Volume)
    fmt.Printf("   Profit: $%.2f\n", deal.Profit)
}

2) Calculate today's profitΒΆ

deals, _ := sugar.GetDealsToday()

if len(deals) == 0 {
    fmt.Println("No trades today")
    return
}

totalProfit := 0.0
winCount := 0
lossCount := 0

for _, deal := range deals {
    totalProfit += deal.Profit

    if deal.Profit > 0 {
        winCount++
    } else if deal.Profit < 0 {
        lossCount++
    }
}

fmt.Println("╔═══════════════════════════════════════╗")
fmt.Println("β•‘      TODAY'S PERFORMANCE              β•‘")
fmt.Println("β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•")
fmt.Printf("Total trades: %d\n", len(deals))
fmt.Printf("Winners:      %d (%.1f%%)\n", winCount,
    float64(winCount)/float64(len(deals))*100)
fmt.Printf("Losers:       %d (%.1f%%)\n", lossCount,
    float64(lossCount)/float64(len(deals))*100)
fmt.Printf("Total P/L:    $%.2f\n", totalProfit)

if totalProfit > 0 {
    fmt.Println("βœ… Profitable day")
} else {
    fmt.Println("❌ Losing day")
}

3) Today's trading summary by symbolΒΆ

deals, _ := sugar.GetDealsToday()

if len(deals) == 0 {
    fmt.Println("No deals today")
    return
}

// Group by symbol
symbolStats := make(map[string]struct {
    Count  int
    Profit float64
})

for _, deal := range deals {
    stats := symbolStats[deal.Symbol]
    stats.Count++
    stats.Profit += deal.Profit
    symbolStats[deal.Symbol] = stats
}

fmt.Println("Today's Performance by Symbol:")
fmt.Println("─────────────────────────────────────────")

for symbol, stats := range symbolStats {
    fmt.Printf("%-8s: %d trades, $%.2f\n",
        symbol, stats.Count, stats.Profit)
}

4) Find largest win/loss todayΒΆ

deals, _ := sugar.GetDealsToday()

if len(deals) == 0 {
    fmt.Println("No deals today")
    return
}

var largestWin *pb.PositionHistoryInfo
var largestLoss *pb.PositionHistoryInfo

for _, deal := range deals {
    if largestWin == nil || deal.Profit > largestWin.Profit {
        largestWin = deal
    }

    if largestLoss == nil || deal.Profit < largestLoss.Profit {
        largestLoss = deal
    }
}

fmt.Println("Today's Extremes:")
fmt.Println("─────────────────────────────────────────")

if largestWin != nil {
    fmt.Printf("πŸ† Largest win:\n")
    fmt.Printf("   #%d %s %.2f lots: $%.2f\n",
        largestWin.Ticket, largestWin.Symbol,
        largestWin.Volume, largestWin.Profit)
}

if largestLoss != nil && largestLoss.Profit < 0 {
    fmt.Printf("\nπŸ’” Largest loss:\n")
    fmt.Printf("   #%d %s %.2f lots: $%.2f\n",
        largestLoss.Ticket, largestLoss.Symbol,
        largestLoss.Volume, largestLoss.Profit)
}

5) Track hourly trading activityΒΆ

deals, _ := sugar.GetDealsToday()

if len(deals) == 0 {
    fmt.Println("No deals today")
    return
}

// Group by hour
hourlyActivity := make(map[int]int)

for _, deal := range deals {
    hour := deal.TimeClose.Hour()
    hourlyActivity[hour]++
}

fmt.Println("Hourly Trading Activity:")
fmt.Println("─────────────────────────────────────────")

for hour := 0; hour < 24; hour++ {
    count := hourlyActivity[hour]
    if count > 0 {
        fmt.Printf("%02d:00 - %02d:59: %d trades\n",
            hour, hour, count)
    }
}

6) Check if breakeven or profitable todayΒΆ

deals, _ := sugar.GetDealsToday()

if len(deals) == 0 {
    fmt.Println("No trades today - day just started?")
    return
}

totalProfit := 0.0
for _, deal := range deals {
    totalProfit += deal.Profit
}

fmt.Printf("Today: %d trades, $%.2f\n", len(deals), totalProfit)

switch {
case totalProfit > 100:
    fmt.Println("πŸŽ‰ Great day! Target exceeded")
case totalProfit > 0:
    fmt.Println("βœ… Profitable day")
case totalProfit == 0:
    fmt.Println("➑️  Breakeven")
case totalProfit > -100:
    fmt.Println("⚠️  Small loss - recoverable")
default:
    fmt.Println("πŸ›‘ Significant loss - stop trading")
}

7) Real-time deal monitorΒΆ

func MonitorTodaysDeals(sugar *mt5.MT5Sugar, interval time.Duration) {
    ticker := time.NewTicker(interval)
    defer ticker.Stop()

    previousCount := 0

    for range ticker.C {
        deals, _ := sugar.GetDealsToday()
        currentCount := len(deals)

        if currentCount > previousCount {
            // New deals closed
            newDeals := currentCount - previousCount

            // Get latest deal
            if len(deals) > 0 {
                latest := deals[len(deals)-1]

                fmt.Printf("[%s] New deal closed!\n",
                    time.Now().Format("15:04:05"))
                fmt.Printf("   #%d %s: $%.2f\n",
                    latest.Ticket, latest.Symbol, latest.Profit)
            }
        }

        previousCount = currentCount
    }
}

// Usage: Monitor every 10 seconds
go MonitorTodaysDeals(sugar, 10*time.Second)

8) Daily performance gradeΒΆ

deals, _ := sugar.GetDealsToday()

if len(deals) == 0 {
    fmt.Println("No trades today - grade: N/A")
    return
}

totalProfit := 0.0
winCount := 0

for _, deal := range deals {
    totalProfit += deal.Profit
    if deal.Profit > 0 {
        winCount++
    }
}

winRate := float64(winCount) / float64(len(deals)) * 100

fmt.Println("╔═══════════════════════════════════════╗")
fmt.Println("β•‘      TODAY'S PERFORMANCE GRADE        β•‘")
fmt.Println("β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•")

fmt.Printf("Trades:    %d\n", len(deals))
fmt.Printf("Win rate:  %.1f%%\n", winRate)
fmt.Printf("P/L:       $%.2f\n\n", totalProfit)

// Grade based on win rate and profitability
grade := ""
if totalProfit > 0 && winRate >= 70 {
    grade = "🌟 A+ (Excellent)"
} else if totalProfit > 0 && winRate >= 60 {
    grade = "⭐ A (Very Good)"
} else if totalProfit > 0 && winRate >= 50 {
    grade = "βœ… B (Good)"
} else if totalProfit >= 0 {
    grade = "🟑 C (Fair)"
} else if totalProfit > -100 {
    grade = "⚠️  D (Poor)"
} else {
    grade = "❌ F (Fail)"
}

fmt.Printf("Grade:     %s\n", grade)

9) Export today's deals to CSVΒΆ

deals, _ := sugar.GetDealsToday()

if len(deals) == 0 {
    fmt.Println("No deals to export")
    return
}

filename := fmt.Sprintf("deals_%s.csv",
    time.Now().Format("2006-01-02"))

file, _ := os.Create(filename)
defer file.Close()

writer := csv.NewWriter(file)
defer writer.Flush()

// Header
writer.Write([]string{
    "Ticket", "Symbol", "Volume", "Profit",
    "Open Time", "Close Time", "Duration"})

// Data
for _, deal := range deals {
    duration := deal.TimeClose.Sub(deal.TimeOpen)

    writer.Write([]string{
        fmt.Sprintf("%d", deal.Ticket),
        deal.Symbol,
        fmt.Sprintf("%.2f", deal.Volume),
        fmt.Sprintf("%.2f", deal.Profit),
        deal.TimeOpen.Format("15:04:05"),
        deal.TimeClose.Format("15:04:05"),
        duration.String(),
    })
}

fmt.Printf("βœ… Exported %d deals to %s\n", len(deals), filename)

10) Advanced daily statistics managerΒΆ

type DailyDealStats struct {
    TotalDeals    int
    WinningDeals  int
    LosingDeals   int
    TotalProfit   float64
    LargestWin    float64
    LargestLoss   float64
    AvgProfit     float64
    WinRate       float64
}

func GetDailyDealStats(sugar *mt5.MT5Sugar) (*DailyDealStats, error) {
    deals, err := sugar.GetDealsToday()
    if err != nil {
        return nil, err
    }

    stats := &DailyDealStats{
        TotalDeals: len(deals),
    }

    if len(deals) == 0 {
        return stats, nil
    }

    stats.LargestWin = 0
    stats.LargestLoss = 0

    for _, deal := range deals {
        stats.TotalProfit += deal.Profit

        if deal.Profit > 0 {
            stats.WinningDeals++
            if deal.Profit > stats.LargestWin {
                stats.LargestWin = deal.Profit
            }
        } else if deal.Profit < 0 {
            stats.LosingDeals++
            if deal.Profit < stats.LargestLoss {
                stats.LargestLoss = deal.Profit
            }
        }
    }

    stats.AvgProfit = stats.TotalProfit / float64(len(deals))
    stats.WinRate = float64(stats.WinningDeals) / float64(len(deals)) * 100

    return stats, nil
}

func (s *DailyDealStats) Print() {
    fmt.Println("╔═══════════════════════════════════════╗")
    fmt.Println("β•‘      DAILY DEAL STATISTICS            β•‘")
    fmt.Println("β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•")

    if s.TotalDeals == 0 {
        fmt.Println("No deals today")
        return
    }

    fmt.Printf("Total Deals:     %d\n", s.TotalDeals)
    fmt.Printf("Winning:         %d (%.1f%%)\n",
        s.WinningDeals, s.WinRate)
    fmt.Printf("Losing:          %d (%.1f%%)\n",
        s.LosingDeals, 100-s.WinRate)
    fmt.Printf("\n")
    fmt.Printf("Total Profit:    $%.2f\n", s.TotalProfit)
    fmt.Printf("Average P/L:     $%.2f\n", s.AvgProfit)
    fmt.Printf("Largest Win:     $%.2f\n", s.LargestWin)
    fmt.Printf("Largest Loss:    $%.2f\n", s.LargestLoss)
}

// Usage:
stats, _ := GetDailyDealStats(sugar)
stats.Print()

🍬 Other time periods:

  • GetDealsYesterday() - Yesterday's deals
  • GetDealsThisWeek() - This week's deals
  • GetDealsThisMonth() - This month's deals
  • GetDealsDateRange() - Custom date range

🍬 Profit calculations:

  • GetProfitToday() - Just today's profit total

⚠️ Common Pitfalls¢

1) Assuming deals existΒΆ

// ❌ WRONG - might panic if no deals
deals, _ := sugar.GetDealsToday()
firstDeal := deals[0] // Panic if empty!

// βœ… CORRECT - check length first
deals, _ := sugar.GetDealsToday()
if len(deals) > 0 {
    firstDeal := deals[0]
}

2) Not considering timezoneΒΆ

// ❌ WRONG - "today" depends on server timezone
// MT5 server might be in different timezone
deals, _ := sugar.GetDealsToday()

// βœ… CORRECT - aware of timezone difference
// Today = 00:00 server time to now server time
deals, _ := sugar.GetDealsToday()
fmt.Println("Deals from server's 'today' (00:00 to now)")

3) Treating as real-time feedΒΆ

// ❌ WRONG - this is closed positions only!
deals, _ := sugar.GetDealsToday()
// This doesn't include currently OPEN positions

// βœ… CORRECT - for open positions use different method
openPositions, _ := sugar.GetOpenPositions() // Current positions
closedDeals, _ := sugar.GetDealsToday()      // Closed today

πŸ’Ž Pro TipsΒΆ

  1. Empty slice OK - Returns empty slice if no deals (not an error)

  2. Closed only - Only includes closed positions, not currently open

  3. Server time - "Today" is based on MT5 server time (00:00 server time)

  4. Performance - Uses 5-second timeout, suitable for frequent calls

  5. Auto-range - Automatically calculates today's range (00:00 to now)


πŸ“Š Deal StructureΒΆ

Each deal (*pb.PositionHistoryInfo) contains:

Ticket       - Position ticket number
Symbol       - Trading symbol (e.g., "EURUSD")
Volume       - Trade volume in lots
Profit       - Realized profit/loss
Commission   - Trading commission
Swap         - Swap charges
TimeOpen     - Position open time
TimeClose    - Position close time
PriceOpen    - Entry price
PriceClose   - Exit price
Type         - Position type (BUY/SELL)


See also: GetDealsYesterday.md, GetDealsThisWeek.md, GetProfitToday.md, GetDealsDateRange.md