trading-app/src/app/(app)/actions/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

76 lines
2.7 KiB
TypeScript

import { Suspense } from "react";
import Link from "next/link";
import { connection } from "next/server";
import { StockBrowser, type StockRow } from "@/components/stock-browser";
import { Card, CardSkeleton, Empty, Page } from "@/components/ui";
import { pct } from "@/lib/format";
import { getIdeas } from "@/lib/ideas";
import { getQuotes } from "@/lib/market";
import { newsCounts } from "@/lib/news";
import { getOpenSymbols } from "@/lib/portfolio";
import { UNIVERSE } from "@/lib/universe";
async function Ideas() {
await connection();
const ideas = await getIdeas();
const items = ideas?.items.slice(0, 4) ?? [];
return (
<Card title="Idées du moment" action={<span className="text-xs text-muted">filtre sans IA</span>}>
{!items.length && <Empty>Les idées se calculent à l&apos;ouverture de l&apos;app : reviens dans une minute.</Empty>}
<ul className="flex flex-col gap-2">
{items.map((i) => (
<li key={i.symbol}>
<Link href={`/actions/${encodeURIComponent(i.symbol)}`} className="block rounded-xl bg-surface-2 p-3">
<span className="flex items-center justify-between gap-2">
<span className="font-semibold">{i.name}</span>
<span className="num text-sm text-danger">{pct(i.pullbackPct)} sur 5 j</span>
</span>
<span className="mt-1 block text-xs leading-relaxed text-muted">{i.reason}</span>
</Link>
</li>
))}
</ul>
</Card>
);
}
async function Market() {
await connection();
const [quotes, newsCount, held] = await Promise.all([getQuotes(UNIVERSE.map((s) => s.symbol)), newsCounts(48), getOpenSymbols(["sandbox", "real"])]);
const rows: StockRow[] = UNIVERSE.map((s) => {
const q = quotes.get(s.symbol);
return {
symbol: s.symbol,
name: s.name,
market: s.market,
price: q?.price ?? null,
currency: q?.currency ?? (s.market === "US" ? "USD" : "EUR"),
changePct: q?.changePct ?? null,
news: newsCount.get(s.symbol) ?? 0,
held: held.includes(s.symbol),
};
});
return <StockBrowser rows={rows} />;
}
export default function ActionsPage() {
return (
<Page
title="Actions"
subtitle="Les grandes actions US et Europe suivies par l'app. Touche une action pour la voir et l'acheter dans ton bac à sable."
action={
<Link href="/actus" className="text-sm font-medium text-accent">
📰 Actus
</Link>
}
>
<Suspense fallback={<CardSkeleton title="Idées du moment" />}>
<Ideas />
</Suspense>
<Suspense fallback={<CardSkeleton height="h-96" />}>
<Market />
</Suspense>
</Page>
);
}