trading-app/src/app/(app)/bac-a-sable/page.tsx
David 234efda586 Fix trade proposals, speed, Trade Republic setup and stock UI
- Buy by EUR amount (fractional shares, like Trade Republic): 200 EUR can
  now reach every large cap; risk engine sizes in whole euros
- No-AI screener (pullback in uptrend) feeds training cards and AI candidates
- Auto-update on app open via after(); "find ideas now" button (3/day)
- New Actions tab: stock list, stock page with chart, news, AI opinion,
  sandbox buy by amount or shares
- "Mon compte" tab: declare deposits, cash, holdings and PEA plan
  (no broker credentials, no PEA invented by default)
- Yahoo data cached and deduplicated, pages stream per section
- Tests: fractional sizing, screener, no-AI idea flow

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:05:20 +01:00

65 lines
2.5 KiB
TypeScript

import { Suspense } from "react";
import Link from "next/link";
import { connection } from "next/server";
import { ClosedList, PendingOrders, PositionList } from "@/components/positions";
import { ResetSandbox } from "@/components/reset-sandbox";
import { Card, CardSkeleton, Delta, Page, primaryBtn, Stat } from "@/components/ui";
import { eur, pct, signedEur } from "@/lib/format";
import { getClosedPositions, getPortfolioState } from "@/lib/portfolio";
import { isTradeRepublicOpen } from "@/lib/time";
async function SandboxContent() {
await connection();
const [state, closed] = await Promise.all([getPortfolioState("sandbox"), getClosedPositions("sandbox")]);
const perf = (state.equity / state.initialCash - 1) * 100;
const realized = closed.reduce((s, p) => s + (p.pnlEur ?? 0), 0);
const wins = closed.filter((p) => (p.pnlEur ?? 0) > 0).length;
return (
<>
<Card title="Ma cagnotte virtuelle">
<div className="flex items-end justify-between">
<p className="num text-3xl font-semibold">{eur(state.equity)}</p>
<Delta value={perf}>{pct(perf)}</Delta>
</div>
<div className="mt-3 grid grid-cols-3 gap-2 text-sm">
<Stat label="liquidités">{eur(state.cash, 0)}</Stat>
<Stat label="gains encaissés">{signedEur(realized)}</Stat>
<Stat label="trades gagnants">{closed.length ? `${wins}/${closed.length}` : "—"}</Stat>
</div>
<Link href="/actions" className={`${primaryBtn} mt-4 w-full`}>
+ Acheter une action
</Link>
{!isTradeRepublicOpen() && (
<p className="mt-2 text-xs text-muted">Trade Republic est fermé (7h30-23h en semaine) : tes ordres s&apos;exécuteront à la réouverture, comme en vrai.</p>
)}
</Card>
{state.pendingOrders.length > 0 && (
<Card title="Ordres en attente">
<PendingOrders orders={state.pendingOrders} cancellable />
</Card>
)}
<Card title="Mes positions">
<PositionList positions={state.positions} sellable />
</Card>
<Card title="Historique">
<ClosedList positions={closed} />
</Card>
<ResetSandbox />
</>
);
}
export default function SandboxPage() {
return (
<Page title="Bac à sable" subtitle="Argent fictif, cours réels, frais Trade Republic (1 € par ordre). Entraîne-toi sans risque.">
<Suspense fallback={<CardSkeleton title="Ma cagnotte virtuelle" height="h-40" />}>
<SandboxContent />
</Suspense>
</Page>
);
}