import { getAccount, getDeals, type Deal } from "@/lib/mt5";
import { formatCurrency, formatDate } from "@/lib/format";
import EquityChart from "@/components/EquityChart";
import TradesRefresher from "@/components/TradesRefresher";
export const dynamic = "force-dynamic";
const MAGIC = 19730;
export default async function TradesPage() {
let deals: Deal[] = [];
let account = null;
let error = false;
try {
const now = new Date().toISOString().slice(0, 19);
[account, deals] = await Promise.all([
getAccount(),
getDeals("2025-01-01T00:00:00", now),
]);
} 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)} |