diff --git a/README.md b/README.md index f79ccf1..f61f51e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,19 @@ App web (installable sur iPhone) qui t'aide à investir 100 €/mois : > Outil d'aide à la décision, pas un conseil en investissement. La majorité des traders particuliers perdent de l'argent ; l'app est conçue pour le mesurer honnêtement. +**Les onglets** : +- **Accueil** : ce qu'il y a à faire (fiches du rendez-vous), bouton « Chercher des idées maintenant », patrimoine, classement. +- **Actions** : toutes les actions suivies avec leur cours ; une fiche par action (graphique, actus, avis de l'IA, achat dans le bac à sable par montant en € ou en nombre d'actions). +- **Bac à sable** : ta cagnotte virtuelle de 200 €. +- **IA** : la cagnotte et les analyses de l'IA. +- **Mon compte** : ton compte Trade Republic. Trade Republic n'a pas d'API : tu déclares tes versements, tes liquidités, les actions que tu détiens et ton plan PEA, l'app tient les comptes. Aucun identifiant n'est jamais demandé. + +**Achats par montant** : comme Trade Republic, l'app achète des fractions d'actions (« Montant : 150 € »). Même avec 200 €, toutes les grandes actions sont accessibles. + +**Sans clé Anthropic**, l'app fonctionne quand même : un filtre simple (repli dans une tendance haussière) repère des idées à tester dans le bac à sable. Avec la clé, ces idées servent aussi de candidates à l'IA. + +**Mise à jour automatique** : à chaque ouverture de l'app (au plus toutes les 20 minutes), ordres, stops, actus et idées se mettent à jour en arrière-plan. La tâche GitHub Actions reste utile pour le rendez-vous du soir et les notifications quand l'app est fermée. + --- ## Lancer l'app sur ton Mac diff --git a/drizzle/0001_friendly_bloodscream.sql b/drizzle/0001_friendly_bloodscream.sql new file mode 100644 index 0000000..56a292c --- /dev/null +++ b/drizzle/0001_friendly_bloodscream.sql @@ -0,0 +1,2 @@ +ALTER TABLE "orders" ALTER COLUMN "shares" SET DATA TYPE double precision;--> statement-breakpoint +ALTER TABLE "positions" ALTER COLUMN "shares" SET DATA TYPE double precision; \ No newline at end of file diff --git a/drizzle/meta/0001_snapshot.json b/drizzle/meta/0001_snapshot.json new file mode 100644 index 0000000..d3e8cf9 --- /dev/null +++ b/drizzle/meta/0001_snapshot.json @@ -0,0 +1,881 @@ +{ + "id": "44ea687c-f514-404a-be73-0f8f65cca593", + "prevId": "4dbfbae0-5e55-4b56-8cc8-1bce887ea407", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.actions": { + "name": "actions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rendezvous_id": { + "name": "rendezvous_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "training": { + "name": "training", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ai_usage": { + "name": "ai_usage", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "at": { + "name": "at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "input_tokens": { + "name": "input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "output_tokens": { + "name": "output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "cost_usd": { + "name": "cost_usd", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cash_flows": { + "name": "cash_flows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "portfolio_id": { + "name": "portfolio_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.equity_snapshots": { + "name": "equity_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "portfolio_id": { + "name": "portfolio_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "equity": { + "name": "equity", + "type": "double precision", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "equity_portfolio_date_idx": { + "name": "equity_portfolio_date_idx", + "columns": [ + { + "expression": "portfolio_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.kv": { + "name": "kv", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.news": { + "name": "news", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "publisher": { + "name": "publisher", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "triage": { + "name": "triage", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "triaged_at": { + "name": "triaged_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "alerted_at": { + "name": "alerted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.orders": { + "name": "orders", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "portfolio_id": { + "name": "portfolio_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "side": { + "name": "side", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "limit_price": { + "name": "limit_price", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "shares": { + "name": "shares", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "stop_price": { + "name": "stop_price", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "target_price": { + "name": "target_price", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "max_exit_date": { + "name": "max_exit_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "position_id": { + "name": "position_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "signal_id": { + "name": "signal_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "valid_until": { + "name": "valid_until", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "filled_at": { + "name": "filled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "fill_price": { + "name": "fill_price", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.portfolios": { + "name": "portfolios", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "initial_cash": { + "name": "initial_cash", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "cash": { + "name": "cash", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "high_water_mark": { + "name": "high_water_mark", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.positions": { + "name": "positions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "portfolio_id": { + "name": "portfolio_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "shares": { + "name": "shares", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "entry_price": { + "name": "entry_price", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "entry_fx": { + "name": "entry_fx", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "opened_at": { + "name": "opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "stop_price": { + "name": "stop_price", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "target_price": { + "name": "target_price", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "max_exit_date": { + "name": "max_exit_date", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "exit_price": { + "name": "exit_price", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "exit_fx": { + "name": "exit_fx", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "exit_reason": { + "name": "exit_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fees_eur": { + "name": "fees_eur", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "pnl_eur": { + "name": "pnl_eur", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "signal_id": { + "name": "signal_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.push_subscriptions": { + "name": "push_subscriptions", + "schema": "", + "columns": { + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "keys": { + "name": "keys", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rendezvous": { + "name": "rendezvous", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "notified_at": { + "name": "notified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "rendezvous_date_idx": { + "name": "rendezvous_date_idx", + "columns": [ + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.signals": { + "name": "signals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "decision": { + "name": "decision", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "thesis": { + "name": "thesis", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "risks": { + "name": "risks", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expected_move_pct": { + "name": "expected_move_pct", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "stop_pct": { + "name": "stop_pct", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "target_pct": { + "name": "target_pct", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "horizon_days": { + "name": "horizon_days", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "price_at_signal": { + "name": "price_at_signal", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "news_ids": { + "name": "news_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "risk_verdict": { + "name": "risk_verdict", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 7ff96e6..42a2a22 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1791720025887, "tag": "0000_init", "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1794851302883, + "tag": "0001_friendly_bloodscream", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/(app)/actions/[symbol]/page.tsx b/src/app/(app)/actions/[symbol]/page.tsx new file mode 100644 index 0000000..b3aec9a --- /dev/null +++ b/src/app/(app)/actions/[symbol]/page.tsx @@ -0,0 +1,146 @@ +import { Suspense } from "react"; +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { connection } from "next/server"; +import { and, desc, eq } from "drizzle-orm"; +import { PositionList } from "@/components/positions"; +import { StockChart } from "@/components/stock-chart"; +import { TradePanel } from "@/components/trade-panel"; +import { Badge, Card, CardSkeleton, Empty, Page } from "@/components/ui"; +import { aiEnabled, getAiSpend } from "@/lib/ai"; +import { getDb, schema } from "@/lib/db"; +import { pct, price, timeAgo } from "@/lib/format"; +import { getBars, getFxToEur, getNews, getNextEarningsDate, getQuote, isSupportedCurrency } from "@/lib/market"; +import { getPortfolioState } from "@/lib/portfolio"; +import { getSettings } from "@/lib/settings"; +import { addDays, formatDateFr, parisDate } from "@/lib/time"; +import { findStock } from "@/lib/universe"; + +type Props = PageProps<"/actions/[symbol]">; + +function numParam(v: string | string[] | undefined): number | undefined { + const n = Number(Array.isArray(v) ? v[0] : v); + return Number.isFinite(n) && n > 0 ? n : undefined; +} + +async function StockContent({ params, searchParams }: Props) { + await connection(); + const symbol = decodeURIComponent((await params).symbol); + const sp = await searchParams; + const quote = await getQuote(symbol); + if (!quote) notFound(); + + const db = await getDb(); + const [bars, fx, earnings, sandbox, spend, settings, signals, dbNews] = await Promise.all([ + getBars(symbol, addDays(parisDate(), -95)).catch(() => []), + getFxToEur(quote.currency), + getNextEarningsDate(symbol), + getPortfolioState("sandbox"), + getAiSpend(), + getSettings(), + db.select().from(schema.signals).where(eq(schema.signals.symbol, symbol)).orderBy(desc(schema.signals.createdAt)).limit(1), + db.select().from(schema.news).where(and(eq(schema.news.symbol, symbol))).orderBy(desc(schema.news.publishedAt)).limit(8), + ]); + const news = dbNews.length ? dbNews : (await getNews(symbol).catch(() => [])).map((n) => ({ ...n, triage: null })); + const held = sandbox.positions.filter((p) => p.symbol === symbol); + const signal = signals[0]; + const first = bars[0]?.close; + const change3m = first ? (quote.price / first - 1) * 100 : null; + const supported = isSupportedCurrency(quote.currency) && fx !== null; + const stock = findStock(symbol); + + return ( + + ‹ Actions + + } + > + +
+

{price(quote.price, quote.currency)}

+
+ {quote.changePct !== null &&

= 0 ? "text-accent" : "text-danger"}`}>{pct(quote.changePct, 2)} auj.

} + {change3m !== null &&

= 0 ? "text-accent" : "text-danger"}`}>{pct(change3m)} sur 3 mois

} +
+
+ {quote.currency === "USD" && fx &&

≈ {(quote.price * fx).toFixed(2)} € chez Trade Republic

} +
+ +
+ {earnings &&

📅 Prochains résultats : {formatDateFr(earnings)}

} +
+ + {held.length > 0 && ( + + + + )} + + {signal && ( + +

+ {signal.decision === "buy" ? "Achat" : "On passe"}{" "} + confiance {signal.confidence} % +

+

{signal.thesis}

+

⚠️ {signal.risks}

+
+ )} + + {supported ? ( + + ) : ( + + Cette action est cotée en {quote.currency} : seules les actions en euros ou en dollars sont gérées. + + )} + + + {!news.length && Pas d'actu récente.} +
    + {news.map((n) => ( +
  • + + {n.title} + + {n.triage?.reason &&

    {n.triage.reason}

    } +

    + {n.publisher} · {timeAgo(n.publishedAt)} + {n.triage && ` · ${n.triage.direction === "positive" ? "▲" : n.triage.direction === "negative" ? "▼" : "•"} ${n.triage.relevance}/10`} +

    +
  • + ))} +
+
+
+ ); +} + +export default function StockPage(props: Props) { + return ( + + + + + } + > + + + ); +} diff --git a/src/app/(app)/actions/page.tsx b/src/app/(app)/actions/page.tsx new file mode 100644 index 0000000..a80f300 --- /dev/null +++ b/src/app/(app)/actions/page.tsx @@ -0,0 +1,75 @@ +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 ( + filtre sans IA}> + {!items.length && Les idées se calculent à l'ouverture de l'app : reviens dans une minute.} + + + ); +} + +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 ; +} + +export default function ActionsPage() { + return ( + + 📰 Actus + + } + > + }> + + + }> + + + + ); +} diff --git a/src/app/(app)/bac-a-sable/page.tsx b/src/app/(app)/bac-a-sable/page.tsx index c9cdffc..9b971f8 100644 --- a/src/app/(app)/bac-a-sable/page.tsx +++ b/src/app/(app)/bac-a-sable/page.tsx @@ -1,58 +1,64 @@ import { Suspense } from "react"; +import Link from "next/link"; import { connection } from "next/server"; -import { PageSkeleton } from "@/components/page-skeleton"; -import { SandboxTrader } from "@/components/sandbox-trader"; -import { PositionList, ClosedList, PendingOrders } from "@/components/positions"; -import { Card, Page } from "@/components/ui"; -import { eur, pct } from "@/lib/format"; -import { getClosedPositions, getPortfolioState } from "@/lib/portfolio"; -import { getAiSpend } from "@/lib/ai"; -import { getSettings } from "@/lib/settings"; +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 SandboxPageContent() { +async function SandboxContent() { await connection(); - const [state, closed, spend, settings] = await Promise.all([ - getPortfolioState("sandbox"), - getClosedPositions("sandbox"), - getAiSpend(), - getSettings(), - ]); + 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 ( - + <>

{eur(state.equity)}

-

= 0 ? "text-accent" : "text-danger"}`}>{pct(perf)}

+ {pct(perf)}
-

Liquidités : {eur(state.cash)}

+
+ {eur(state.cash, 0)} + {signedEur(realized)} + {closed.length ? `${wins}/${closed.length}` : "—"} +
+ + + Acheter une action + + {!isTradeRepublicOpen() && ( +

Trade Republic est fermé (7h30-23h en semaine) : tes ordres s'exécuteront à la réouverture, comme en vrai.

+ )}
- - - - - {state.pendingOrders.length > 0 && ( )} + + + + + -
+ ); } export default function SandboxPage() { return ( - }> - - + + }> + + + ); } diff --git a/src/app/(app)/layout.tsx b/src/app/(app)/layout.tsx index e156f3f..1d7f817 100644 --- a/src/app/(app)/layout.tsx +++ b/src/app/(app)/layout.tsx @@ -1,10 +1,19 @@ -import { Nav } from "@/components/nav"; +import { Suspense } from "react"; +import { AutoTick } from "@/components/auto-tick"; +import { Nav, NavBar } from "@/components/nav"; + +export const maxDuration = 300; export default function AppLayout({ children }: LayoutProps<"/">) { return ( <> {children} -