From 6cd8959c2dfce76564801ed8b5bdf254602d1e02 Mon Sep 17 00:00:00 2001 From: romysaputrasihananda Date: Thu, 11 Jun 2026 16:26:18 +0700 Subject: [PATCH] fix(web/trades): fetch deals per-day to bypass MT5 bridge per-request limit Co-Authored-By: Claude Sonnet 4.6 --- web/app/trades/page.tsx | 5 ++--- web/lib/mt5.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/web/app/trades/page.tsx b/web/app/trades/page.tsx index 88a99fe..8b161b3 100644 --- a/web/app/trades/page.tsx +++ b/web/app/trades/page.tsx @@ -1,4 +1,4 @@ -import { getAccount, getDeals, type Deal } from "@/lib/mt5"; +import { getAccount, getAllDeals, type Deal } from "@/lib/mt5"; import { formatCurrency, formatDate } from "@/lib/format"; import EquityChart from "@/components/EquityChart"; import TradesRefresher from "@/components/TradesRefresher"; @@ -12,10 +12,9 @@ export default async function TradesPage() { let error = false; try { - const now = new Date().toISOString().slice(0, 19); [account, deals] = await Promise.all([ getAccount(), - getDeals("2026-06-01T00:00:00", now), + getAllDeals("2026-06-10T00:00:00"), ]); } catch { error = true; } diff --git a/web/lib/mt5.ts b/web/lib/mt5.ts index 465f2d3..8bc2377 100644 --- a/web/lib/mt5.ts +++ b/web/lib/mt5.ts @@ -104,3 +104,35 @@ export async function getDeals(dateFrom: string, dateTo: string, symbol?: string const w = await apiFetch>(path); return w.data; } + +// Fetch all deals from startDate to now by querying one day at a time, +// working around the MT5 bridge per-request deal limit. +export async function getAllDeals(startDate: string): Promise { + const start = new Date(startDate); + const now = new Date(); + const days: Array<[string, string]> = []; + + const cur = new Date(start); + while (cur <= now) { + const next = new Date(cur); + next.setUTCDate(next.getUTCDate() + 1); + days.push([ + cur.toISOString().slice(0, 19), + next.toISOString().slice(0, 19), + ]); + cur.setUTCDate(cur.getUTCDate() + 1); + } + + const chunks = await Promise.all(days.map(([f, t]) => getDeals(f, t))); + const seen = new Set(); + const result: Deal[] = []; + for (const chunk of chunks) { + for (const deal of chunk) { + if (!seen.has(deal.ticket)) { + seen.add(deal.ticket); + result.push(deal); + } + } + } + return result; +}