Files
AITrader/app/components/TradingViewChart.tsx
T
henry 15e49cb0f9
Run Tests / test (push) Failing after 8s
feat(tests): update Alpaca API tests to include range parameters and improve stock database cleanup
- Modified Alpaca Historical Bars tests to include range parameters in API requests.
- Updated test descriptions for clarity.
- Added cleanup step to delete test ticker after verification in stock database tests.
- Adjusted Vitest configuration to exclude test files from coverage.
2026-05-14 16:46:28 +02:00

58 lines
1.4 KiB
TypeScript

import { useEffect, useRef } from "react";
import * as LightweightCharts from "lightweight-charts";
type ChartTime = string | number;
interface ChartDataPoint {
time: ChartTime;
open: number;
high: number;
low: number;
close: number;
}
interface TradingViewChartProps {
ticker: string;
data?: ChartDataPoint[];
}
export default function TradingViewChart({ ticker, data }: TradingViewChartProps) {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!containerRef.current) {
return;
}
const chart = LightweightCharts.createChart(containerRef.current, {
height: 400,
autoSize: true,
});
const candlestickSeries = chart.addSeries(LightweightCharts.CandlestickSeries, {
upColor: "#26a69a",
downColor: "#ef5350",
borderUpColor: "#26a69a",
borderDownColor: "#ef5350",
wickUpColor: "#26a69a",
wickDownColor: "#ef5350",
});
if (data && data.length > 0) {
try {
candlestickSeries.setData(data as any);
} catch (err) {
console.error(`TradingViewChart: error setting data for ${ticker}`, err);
}
}
return () => chart.remove();
}, [data, ticker]);
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} className="w-full" />
</div>
);
}