feat: add stock detail page with chart, position, and orders

- Add /api/alpaca/orders endpoint for order history
- Add TradingView chart component for candlestick visualization
- Add /analyze/:ticker route with position and orders display
- Make ticker cells in analyze page clickable for navigation
This commit is contained in:
2026-05-14 11:00:35 +02:00
parent 043c3d5afe
commit 2e22fd5635
14 changed files with 541 additions and 4 deletions
+35
View File
@@ -0,0 +1,35 @@
import { useEffect, useRef } from "react";
import * as LightweightCharts from "lightweight-charts";
interface TradingViewChartProps {
ticker: string;
data?: Array<{ time: string; open: number; high: number; low: number; close: number }>;
}
export default function TradingViewChart({ ticker, data }: TradingViewChartProps) {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!containerRef.current) return;
const chart = LightweightCharts.createChart(containerRef.current, {
width: containerRef.current.clientWidth,
height: 400,
});
const candlestickSeries = chart.addSeries(LightweightCharts.CandlestickSeries);
if (data && data.length > 0) {
candlestickSeries.setData(data);
}
return () => chart.remove();
}, [data]);
return (
<div className="bg-white rounded-xl shadow-lg p-4">
<h3 className="text-lg font-bold mb-3">{ticker} Price Chart</h3>
<div ref={containerRef} />
</div>
);
}
@@ -0,0 +1,36 @@
/// <reference types="vitest" />
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { render, screen } from "@testing-library/react";
import TradingViewChart from "../TradingViewChart";
// Mock lightweight-charts
vi.mock("lightweight-charts", () => ({
createChart: vi.fn(() => ({
addSeries: vi.fn(() => ({
setData: vi.fn(),
})),
remove: vi.fn(),
})),
CandlestickSeries: {},
}));
describe("TradingViewChart", () => {
it("renders the ticker symbol as heading", () => {
render(<TradingViewChart ticker="AAPL" />);
expect(screen.getByText("AAPL Price Chart")).toBeInTheDocument();
});
it("renders without data prop", () => {
render(<TradingViewChart ticker="MSFT" />);
expect(screen.getByText("MSFT Price Chart")).toBeInTheDocument();
});
it("renders with data prop", () => {
const data = [
{ time: "2024-01-01", open: 100, high: 110, low: 95, close: 105 },
{ time: "2024-01-02", open: 105, high: 115, low: 100, close: 110 },
];
render(<TradingViewChart ticker="GOOGL" data={data} />);
expect(screen.getByText("GOOGL Price Chart")).toBeInTheDocument();
});
});