import type { Metadata } from "next";
import { getAccount, getAllDeals, type Deal } from "@/lib/mt5";
import { formatCurrency, formatDate } from "@/lib/format";
import EquityChart from "@/components/EquityChart";
import TradesRefresher from "@/components/TradesRefresher";
export const metadata: Metadata = {
title: "Trade History",
description: "Live closed trades and equity curve for ARES โ M5 Momentum FVG scalper on XAUUSDm.",
};
export const dynamic = "force-dynamic";
const MAGIC = 19730;
export default async function TradesPage() {
let deals: Deal[] = [];
let account = null;
let error = false;
try {
[account, deals] = await Promise.all([
getAccount(),
getAllDeals("2026-06-10T00:00:00"),
]);
} catch { error = true; }
const aresDeals = deals.filter(d => d.magic === MAGIC && d.type !== 2);
const closed = aresDeals.filter(d => d.entry === 1);
const wins = closed.filter(d => d.profit > 0);
const losses = closed.filter(d => d.profit < 0);
const netPnl = closed.reduce((s, d) => s + d.profit + d.swap + d.commission, 0);
const grossW = wins.reduce((s, d) => s + d.profit, 0);
const grossL = Math.abs(losses.reduce((s, d) => s + d.profit, 0));
const pf = grossL > 0 ? grossW / grossL : 0;
const wr = closed.length > 0 ? (wins.length / closed.length) * 100 : 0;
const currency = account?.currency ?? "USD";
return (
<>
Live Forward Test
All closed trades from ARES ยท magic {MAGIC}
Trade History
{label}
{value}
Equity Curve
Closed Trades
| {h} | ))}|||||
|---|---|---|---|---|---|
| {formatDate(d.time)} | {d.symbol || "โ"} | {d.type === 0 ? "BUY" : "SELL"} | {d.volume} | {d.price.toFixed(2)} | = 0 ? "text-bull" : "text-bear"}`}> {formatCurrency(d.profit, currency)} |