From 17eb2ca745f68544b20476a6edd84ba5356f8a59 Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Thu, 12 Feb 2026 11:52:43 +0100 Subject: [PATCH] fix: sort candle data before displaying in chart - Add sorting by timestamp in ascending order before setting chart data - Fixes 'data must be asc ordered by time' error from lightweight-charts - Ensures chart displays correctly even if API returns unsorted data --- src/components/CandleChart.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/CandleChart.tsx b/src/components/CandleChart.tsx index 22c70c0..8f12c8e 100644 --- a/src/components/CandleChart.tsx +++ b/src/components/CandleChart.tsx @@ -136,13 +136,15 @@ const CandleChart = forwardRef( useEffect(() => { if (!seriesRef.current || candles.length === 0) return; - const chartData: CandlestickData[] = candles.map((candle) => ({ - time: candle.time as Time, - open: candle.open, - high: candle.high, - low: candle.low, - close: candle.close, - })); + const chartData: CandlestickData[] = candles + .map((candle) => ({ + time: candle.time as Time, + open: candle.open, + high: candle.high, + low: candle.low, + close: candle.close, + })) + .sort((a, b) => (a.time as number) - (b.time as number)); seriesRef.current.setData(chartData); }, [candles]);