trading-app/src/components/positions.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

102 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import Link from "next/link";
import { useTransition } from "react";
import { cancelSandboxOrder, sandboxSell } from "@/app/actions";
import { eur, EXIT_REASONS, pct, price, shares, signedEur } from "@/lib/format";
import type { Order, Position, PositionView } from "@/lib/portfolio";
import { Delta, Empty, secondaryBtn } from "./ui";
export function PositionList({ positions, sellable = false }: { positions: PositionView[]; sellable?: boolean }) {
const [pending, start] = useTransition();
if (!positions.length) return <Empty>Aucune position ouverte.</Empty>;
return (
<ul className="flex flex-col gap-2">
{positions.map((p) => (
<li key={p.id} className="rounded-xl bg-surface-2 p-3">
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<Link href={`/actions/${encodeURIComponent(p.symbol)}`} className="font-semibold">
{p.name}
</Link>
<p className="num text-xs text-muted">
{shares(p.shares)} × {price(p.entryPrice, p.currency)} → {p.price !== null ? price(p.price, p.currency) : "?"}
</p>
</div>
<div className="text-right">
<p className="num font-semibold">{eur(p.valueEur)}</p>
<Delta value={p.pnlOpenEur}>
{signedEur(p.pnlOpenEur)} ({pct(p.pnlOpenPct)})
</Delta>
</div>
</div>
{(p.stopPrice || p.targetPrice || p.maxExitDate) && (
<p className="num mt-2 text-xs text-muted">
{p.stopPrice ? `Stop ${price(p.stopPrice, p.currency)}` : ""}
{p.targetPrice ? ` · Objectif ${price(p.targetPrice, p.currency)}` : ""}
{p.maxExitDate ? ` · Sortie au plus tard le ${p.maxExitDate}` : ""}
</p>
)}
{sellable && (
<button
className={`${secondaryBtn} mt-3 h-9 w-full`}
disabled={pending}
onClick={() =>
start(async () => {
const r = await sandboxSell(p.id);
if (!r.ok) alert(r.message);
})
}
>
Vendre
</button>
)}
</li>
))}
</ul>
);
}
export function PendingOrders({ orders, cancellable = false }: { orders: Order[]; cancellable?: boolean }) {
const [pending, start] = useTransition();
return (
<ul className="flex flex-col gap-2 text-sm">
{orders.map((o) => (
<li key={o.id} className="flex items-center justify-between gap-3 rounded-xl bg-surface-2 p-3">
<span>
{o.side === "buy" ? "Achat" : "Vente"} {shares(o.shares)} {o.name}
<span className="num block text-xs text-muted">
{o.type === "limit" && o.limitPrice ? `limite ${price(o.limitPrice, o.currency)}` : "au marché"}
{o.validUntil ? ` · valable jusqu'au ${o.validUntil}` : ""}
</span>
</span>
{cancellable && (
<button className="text-sm font-medium text-danger" disabled={pending} onClick={() => start(() => cancelSandboxOrder(o.id))}>
Annuler
</button>
)}
</li>
))}
</ul>
);
}
export function ClosedList({ positions }: { positions: Position[] }) {
if (!positions.length) return <Empty>Pas encore de trade terminé.</Empty>;
return (
<ul className="flex flex-col divide-y divide-line text-sm">
{positions.map((p) => (
<li key={p.id} className="flex items-center justify-between gap-3 py-2.5">
<span>
<span className="font-medium">{p.name}</span>
<span className="block text-xs text-muted">
{p.closedAt?.toLocaleDateString("fr-FR")} · {EXIT_REASONS[p.exitReason ?? ""] ?? p.exitReason}
</span>
</span>
<Delta value={p.pnlEur ?? 0}>{signedEur(p.pnlEur ?? 0)}</Delta>
</li>
))}
</ul>
);
}