From d1a84325ae14bc5eb4ba265297585e218fd98b04 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Thu, 14 May 2026 11:23:33 +0200 Subject: [PATCH] fix: pass bars data to TradingView chart correctly - Include bars in loader response - Convert timestamp to YYYY-MM-DD format for TradingView - Fix error response to always include bars array --- app/routes/analyze.ticker.tsx | 8 ++++---- app/routes/api/alpaca/quote.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/routes/analyze.ticker.tsx b/app/routes/analyze.ticker.tsx index 1b87874..4055d3a 100644 --- a/app/routes/analyze.ticker.tsx +++ b/app/routes/analyze.ticker.tsx @@ -33,20 +33,20 @@ export async function loader({ params, request }: { params: { ticker: string }; const barsData = barsRes.ok ? await barsRes.json() : null; const bars = barsData?.bars || []; - return Response.json({ ticker, position, orders }); + return Response.json({ ticker, position, orders, bars }); } export default function StockDetail() { const { ticker, position, orders, bars } = useLoaderData() as LoaderData; - // Convert Alpaca bars to TradingView format + // Convert Alpaca bars to TradingView format (YYYY-MM-DD for time) const chartData = bars?.map((bar: any) => ({ - time: bar.t, + time: bar.t ? new Date(bar.t).toISOString().split('T')[0] : "", open: bar.o, high: bar.h, low: bar.l, close: bar.c, - })) || []; + })).filter((bar: any) => bar.time) || []; return (
diff --git a/app/routes/api/alpaca/quote.ts b/app/routes/api/alpaca/quote.ts index 529e217..b758a16 100644 --- a/app/routes/api/alpaca/quote.ts +++ b/app/routes/api/alpaca/quote.ts @@ -44,6 +44,6 @@ export async function loader({ params }: { params: { ticker: string } }) { }); } catch (error) { console.error("Alpaca data error:", error); - return Response.json({ error: "Failed to fetch data" }, { status: 500 }); + return Response.json({ ticker, price: 0, bars: [] }, { status: 500 }); } } \ No newline at end of file